summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarol Kosek <krkk@krkk.ct8.pl>2021-08-12 17:07:39 +0200
committerAndreas Kling <kling@serenityos.org>2021-08-12 18:54:57 +0200
commit8516b9532ee6aba42261e6aca9d5ebda8ec82e69 (patch)
treeef3e64bc3aea85c067c6005d20c56f99a0929dec
parent8a4bb581a2353936dad90c8027bbd08579535dcf (diff)
downloadserenity-8516b9532ee6aba42261e6aca9d5ebda8ec82e69.zip
HackStudio: Add 'Save as...' action
Not adding it to the toolbar, because it has the same icon as a typical 'Save' action.
-rw-r--r--Userland/DevTools/HackStudio/HackStudioWidget.cpp25
-rw-r--r--Userland/DevTools/HackStudio/HackStudioWidget.h2
2 files changed, 27 insertions, 0 deletions
diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp
index 2a9abc29b1..ea9ac31f99 100644
--- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp
+++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp
@@ -116,6 +116,7 @@ HackStudioWidget::HackStudioWidget(const String& path_to_project)
m_remove_current_editor_action = create_remove_current_editor_action();
m_open_action = create_open_action();
m_save_action = create_save_action();
+ m_save_as_action = create_save_as_action();
m_new_project_action = create_new_project_action();
create_action_tab(*m_right_hand_splitter);
@@ -609,6 +610,29 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_save_action()
});
}
+NonnullRefPtr<GUI::Action> HackStudioWidget::create_save_as_action()
+{
+ return GUI::CommonActions::make_save_as_action([&](auto&) {
+ auto const old_filename = current_editor_wrapper().filename();
+ LexicalPath const old_path(old_filename);
+
+ Optional<String> save_path = GUI::FilePicker::get_save_filepath(window(),
+ old_filename.is_null() ? "Untitled" : old_path.title(),
+ old_filename.is_null() ? "txt" : old_path.extension(),
+ Core::File::absolute_path(old_path.dirname()));
+ if (!save_path.has_value()) {
+ return;
+ }
+
+ current_editor_wrapper().set_filename(save_path.value());
+ current_editor_wrapper().save();
+
+ auto new_project_file = m_project->get_file(save_path.value());
+ m_open_files.set(save_path.value(), *new_project_file);
+ m_open_files_vector.append(save_path.value());
+ });
+}
+
NonnullRefPtr<GUI::Action> HackStudioWidget::create_remove_current_terminal_action()
{
return GUI::Action::create("Remove &Current Terminal", { Mod_Alt | Mod_Shift, Key_T }, [this](auto&) {
@@ -956,6 +980,7 @@ void HackStudioWidget::create_file_menu(GUI::Window& window)
file_menu.add_action(*m_new_project_action);
file_menu.add_action(*m_open_action);
file_menu.add_action(*m_save_action);
+ file_menu.add_action(*m_save_as_action);
file_menu.add_separator();
file_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the()->quit();
diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.h b/Userland/DevTools/HackStudio/HackStudioWidget.h
index 92f07ea7df..6e00dc5634 100644
--- a/Userland/DevTools/HackStudio/HackStudioWidget.h
+++ b/Userland/DevTools/HackStudio/HackStudioWidget.h
@@ -82,6 +82,7 @@ private:
NonnullRefPtr<GUI::Action> create_remove_current_editor_action();
NonnullRefPtr<GUI::Action> create_open_action();
NonnullRefPtr<GUI::Action> create_save_action();
+ NonnullRefPtr<GUI::Action> create_save_as_action();
NonnullRefPtr<GUI::Action> create_show_in_file_manager_action();
NonnullRefPtr<GUI::Action> create_add_editor_action();
NonnullRefPtr<GUI::Action> create_add_terminal_action();
@@ -164,6 +165,7 @@ private:
RefPtr<GUI::Action> m_remove_current_editor_action;
RefPtr<GUI::Action> m_open_action;
RefPtr<GUI::Action> m_save_action;
+ RefPtr<GUI::Action> m_save_as_action;
RefPtr<GUI::Action> m_add_editor_action;
RefPtr<GUI::Action> m_add_terminal_action;
RefPtr<GUI::Action> m_remove_current_terminal_action;