mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 16:07:35 +00:00
HackStudio: Add an 'Auto Save before Build or Run' option
This commit is contained in:
parent
0e9bdfa822
commit
4c915a9e67
2 changed files with 39 additions and 10 deletions
|
@ -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));
|
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&) {
|
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)
|
if (m_auto_save_before_build_or_run) {
|
||||||
return;
|
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);
|
reveal_action_tab(*m_terminal_wrapper);
|
||||||
build();
|
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));
|
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&) {
|
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)
|
if (m_auto_save_before_build_or_run) {
|
||||||
return;
|
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);
|
reveal_action_tab(*m_terminal_wrapper);
|
||||||
run();
|
run();
|
||||||
|
@ -1473,6 +1483,14 @@ ErrorOr<void> HackStudioWidget::create_edit_menu(GUI::Window& window)
|
||||||
vim_emulation_setting_action->set_checked(false);
|
vim_emulation_setting_action->set_checked(false);
|
||||||
edit_menu->add_action(vim_emulation_setting_action);
|
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_separator();
|
||||||
edit_menu->add_action(*m_open_project_configuration_action);
|
edit_menu->add_action(*m_open_project_configuration_action);
|
||||||
return {};
|
return {};
|
||||||
|
@ -1679,17 +1697,25 @@ HackStudioWidget::ContinueDecision HackStudioWidget::warn_unsaved_changes(Deprec
|
||||||
return ContinueDecision::No;
|
return ContinueDecision::No;
|
||||||
|
|
||||||
if (result == GUI::MessageBox::ExecResult::Yes) {
|
if (result == GUI::MessageBox::ExecResult::Yes) {
|
||||||
for (auto& editor_wrapper : m_all_editor_wrappers) {
|
if (!save_file_changes())
|
||||||
if (editor_wrapper->editor().document().is_modified()) {
|
return ContinueDecision::No;
|
||||||
if (!editor_wrapper->save())
|
|
||||||
return ContinueDecision::No;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ContinueDecision::Yes;
|
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
|
bool HackStudioWidget::any_document_is_dirty() const
|
||||||
{
|
{
|
||||||
return any_of(m_all_editor_wrappers, [](auto& editor_wrapper) {
|
return any_of(m_all_editor_wrappers, [](auto& editor_wrapper) {
|
||||||
|
|
|
@ -168,6 +168,7 @@ private:
|
||||||
void update_toolbar_actions();
|
void update_toolbar_actions();
|
||||||
void on_cursor_change();
|
void on_cursor_change();
|
||||||
void file_renamed(DeprecatedString const& old_name, DeprecatedString const& new_name);
|
void file_renamed(DeprecatedString const& old_name, DeprecatedString const& new_name);
|
||||||
|
bool save_file_changes();
|
||||||
|
|
||||||
struct ProjectLocation {
|
struct ProjectLocation {
|
||||||
DeprecatedString filename;
|
DeprecatedString filename;
|
||||||
|
@ -195,6 +196,8 @@ private:
|
||||||
size_t m_locations_history_end_index { 0 };
|
size_t m_locations_history_end_index { 0 };
|
||||||
bool m_locations_history_disabled { false };
|
bool m_locations_history_disabled { false };
|
||||||
|
|
||||||
|
bool m_auto_save_before_build_or_run { false };
|
||||||
|
|
||||||
RefPtr<GUI::TreeView> m_project_tree_view;
|
RefPtr<GUI::TreeView> m_project_tree_view;
|
||||||
RefPtr<GUI::ListView> m_open_files_view;
|
RefPtr<GUI::ListView> m_open_files_view;
|
||||||
RefPtr<GUI::VerticalSplitter> m_right_hand_splitter;
|
RefPtr<GUI::VerticalSplitter> m_right_hand_splitter;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue