mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-08 04:50:08 +03:00
HackStudio: Add an 'Auto Save before Build or Run' option
This commit is contained in:
parent
0e9bdfa822
commit
4c915a9e67
Notes:
sideshowbarker
2024-07-17 06:51:10 +09:00
Author: https://github.com/0GreenClover0 Commit: https://github.com/SerenityOS/serenity/commit/4c915a9e67 Pull-request: https://github.com/SerenityOS/serenity/pull/21729 Reviewed-by: https://github.com/AtkinsSJ ✅
@ -1311,8 +1311,13 @@ ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_build_action()
|
||||
{
|
||||
auto icon = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/build.png"sv));
|
||||
return GUI::Action::create("&Build", { Mod_Ctrl, Key_B }, icon, [this](auto&) {
|
||||
if (warn_unsaved_changes("There are unsaved changes, do you want to save before building?") == ContinueDecision::No)
|
||||
return;
|
||||
if (m_auto_save_before_build_or_run) {
|
||||
if (!save_file_changes())
|
||||
return;
|
||||
} else {
|
||||
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();
|
||||
@ -1323,8 +1328,13 @@ ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_run_action()
|
||||
{
|
||||
auto icon = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/program-run.png"sv));
|
||||
return GUI::Action::create("&Run", { Mod_Ctrl, Key_R }, icon, [this](auto&) {
|
||||
if (warn_unsaved_changes("There are unsaved changes, do you want to save before running?") == ContinueDecision::No)
|
||||
return;
|
||||
if (m_auto_save_before_build_or_run) {
|
||||
if (!save_file_changes())
|
||||
return;
|
||||
} else {
|
||||
if (warn_unsaved_changes("There are unsaved changes, do you want to save before running?") == ContinueDecision::No)
|
||||
return;
|
||||
}
|
||||
|
||||
reveal_action_tab(*m_terminal_wrapper);
|
||||
run();
|
||||
@ -1473,6 +1483,14 @@ ErrorOr<void> HackStudioWidget::create_edit_menu(GUI::Window& window)
|
||||
vim_emulation_setting_action->set_checked(false);
|
||||
edit_menu->add_action(vim_emulation_setting_action);
|
||||
|
||||
auto auto_save_before_build_or_run_action = GUI::Action::create_checkable("&Auto Save before Build or Run", [this](auto& action) {
|
||||
m_auto_save_before_build_or_run = action.is_checked();
|
||||
Config::write_bool("HackStudio"sv, "Global"sv, "AutoSaveBeforeBuildOrRun"sv, m_auto_save_before_build_or_run);
|
||||
});
|
||||
m_auto_save_before_build_or_run = Config::read_bool("HackStudio"sv, "Global"sv, "AutoSaveBeforeBuildOrRun"sv, false);
|
||||
auto_save_before_build_or_run_action->set_checked(m_auto_save_before_build_or_run);
|
||||
edit_menu->add_action(auto_save_before_build_or_run_action);
|
||||
|
||||
edit_menu->add_separator();
|
||||
edit_menu->add_action(*m_open_project_configuration_action);
|
||||
return {};
|
||||
@ -1679,17 +1697,25 @@ HackStudioWidget::ContinueDecision HackStudioWidget::warn_unsaved_changes(Deprec
|
||||
return ContinueDecision::No;
|
||||
|
||||
if (result == GUI::MessageBox::ExecResult::Yes) {
|
||||
for (auto& editor_wrapper : m_all_editor_wrappers) {
|
||||
if (editor_wrapper->editor().document().is_modified()) {
|
||||
if (!editor_wrapper->save())
|
||||
return ContinueDecision::No;
|
||||
}
|
||||
}
|
||||
if (!save_file_changes())
|
||||
return ContinueDecision::No;
|
||||
}
|
||||
|
||||
return ContinueDecision::Yes;
|
||||
}
|
||||
|
||||
bool HackStudioWidget::save_file_changes()
|
||||
{
|
||||
for (auto& editor_wrapper : m_all_editor_wrappers) {
|
||||
if (editor_wrapper->editor().document().is_modified()) {
|
||||
if (!editor_wrapper->save())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HackStudioWidget::any_document_is_dirty() const
|
||||
{
|
||||
return any_of(m_all_editor_wrappers, [](auto& editor_wrapper) {
|
||||
|
@ -168,6 +168,7 @@ private:
|
||||
void update_toolbar_actions();
|
||||
void on_cursor_change();
|
||||
void file_renamed(DeprecatedString const& old_name, DeprecatedString const& new_name);
|
||||
bool save_file_changes();
|
||||
|
||||
struct ProjectLocation {
|
||||
DeprecatedString filename;
|
||||
@ -195,6 +196,8 @@ private:
|
||||
size_t m_locations_history_end_index { 0 };
|
||||
bool m_locations_history_disabled { false };
|
||||
|
||||
bool m_auto_save_before_build_or_run { false };
|
||||
|
||||
RefPtr<GUI::TreeView> m_project_tree_view;
|
||||
RefPtr<GUI::ListView> m_open_files_view;
|
||||
RefPtr<GUI::VerticalSplitter> m_right_hand_splitter;
|
||||
|
Loading…
Reference in New Issue
Block a user