mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 20:17:13 +02:00
HackStudio: Show dialog on build and exit if there are unsaved changes
If the user tries to exit HackStudio, or build the project, when there are unsaved changes in some of the editors, A Yes/No/Cancel dialog will be shown.
This commit is contained in:
Notes:
sideshowbarker
2024-07-18 18:46:05 +09:00
Author: https://github.com/itamar8910 Commit: https://github.com/SerenityOS/serenity/commit/329cb134d6f Pull-request: https://github.com/SerenityOS/serenity/pull/6779 Reviewed-by: https://github.com/IdanHo Reviewed-by: https://github.com/awesomekling
@@ -896,6 +896,9 @@ void HackStudioWidget::create_toolbar(GUI::Widget& parent)
|
||||
NonnullRefPtr<GUI::Action> HackStudioWidget::create_build_action()
|
||||
{
|
||||
return GUI::Action::create("&Build", { Mod_Ctrl, Key_B }, Gfx::Bitmap::load_from_file("/res/icons/16x16/build.png"), [this](auto&) {
|
||||
if (warn_unsaved_changes("There are unsaved changes, do you want to save before building?") == ContinueDecision::No)
|
||||
return;
|
||||
|
||||
reveal_action_tab(*m_terminal_wrapper);
|
||||
build(*m_terminal_wrapper);
|
||||
m_stop_action->set_enabled(true);
|
||||
@@ -1129,4 +1132,35 @@ HackStudioWidget::~HackStudioWidget()
|
||||
}
|
||||
}
|
||||
|
||||
HackStudioWidget::ContinueDecision HackStudioWidget::warn_unsaved_changes(const String& prompt)
|
||||
{
|
||||
if (!any_document_is_dirty())
|
||||
return ContinueDecision::Yes;
|
||||
|
||||
auto result = GUI::MessageBox::show(window(), prompt, "Unsaved changes", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel);
|
||||
|
||||
if (result == GUI::MessageBox::ExecCancel)
|
||||
return ContinueDecision::No;
|
||||
|
||||
if (result == GUI::MessageBox::ExecYes) {
|
||||
for (auto& editor_wrapper : m_all_editor_wrappers) {
|
||||
if (editor_wrapper.document_dirty()) {
|
||||
editor_wrapper.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ContinueDecision::Yes;
|
||||
}
|
||||
|
||||
bool HackStudioWidget::any_document_is_dirty() const
|
||||
{
|
||||
for (auto& editor_wrapper : m_all_editor_wrappers) {
|
||||
if (editor_wrapper.document_dirty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user