summaryrefslogtreecommitdiff
path: root/Userland/DevTools/HackStudio
diff options
context:
space:
mode:
authorMarco Cutecchia <marco.cutecchia@outlook.it>2022-03-19 12:47:18 +0100
committerAndreas Kling <kling@serenityos.org>2022-04-15 00:15:04 +0200
commita7ba8677cd1647ff74885b26b6906dba476a0645 (patch)
treeb09d478747017f103b478e057da10bdda05d966e /Userland/DevTools/HackStudio
parent9096da19f115bfd7e3a187fcd0611e89e062a5db (diff)
downloadserenity-a7ba8677cd1647ff74885b26b6906dba476a0645.zip
HackStudio: Add a "Project Configuration" button in the Edit menu
Diffstat (limited to 'Userland/DevTools/HackStudio')
-rw-r--r--Userland/DevTools/HackStudio/HackStudioWidget.cpp32
-rw-r--r--Userland/DevTools/HackStudio/HackStudioWidget.h2
2 files changed, 34 insertions, 0 deletions
diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp
index fb7ebf72aa..1a140cc7dd 100644
--- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp
+++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp
@@ -137,6 +137,8 @@ HackStudioWidget::HackStudioWidget(String path_to_project)
m_stop_action->set_enabled(false);
};
+ m_open_project_configuration_action = create_open_project_configuration_action();
+
m_build_action = create_build_action();
m_run_action = create_run_action();
m_stop_action = create_stop_action();
@@ -1366,6 +1368,9 @@ void HackStudioWidget::create_edit_menu(GUI::Window& window)
});
vim_emulation_setting_action->set_checked(false);
edit_menu.add_action(vim_emulation_setting_action);
+
+ edit_menu.add_separator();
+ edit_menu.add_action(*m_open_project_configuration_action);
}
void HackStudioWidget::create_build_menu(GUI::Window& window)
@@ -1648,6 +1653,33 @@ void HackStudioWidget::create_location_history_actions()
m_locations_history_forward_action->set_enabled(false);
}
+NonnullRefPtr<GUI::Action> HackStudioWidget::create_open_project_configuration_action()
+{
+ return GUI::Action::create("Project Configuration", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/settings.png").release_value(), [&](auto&) {
+ auto parent_directory = LexicalPath::dirname(Project::config_file_path);
+ auto absolute_config_file_path = LexicalPath::absolute_path(m_project->root_path(), Project::config_file_path);
+
+ if (!Core::File::exists(absolute_config_file_path)) {
+ if (Core::File::exists(parent_directory) && !Core::File::is_directory(parent_directory)) {
+ GUI::MessageBox::show_error(window(), String::formatted("Cannot create the '{}' directory because there is already a file with that name", parent_directory));
+ return;
+ }
+
+ mkdir(LexicalPath::absolute_path(m_project->root_path(), parent_directory).characters(), 0755);
+
+ auto file = Core::File::open(absolute_config_file_path, Core::OpenMode::WriteOnly);
+ file.value()->write(
+ "{\n"
+ " \"build_command\": \"your build command here\",\n"
+ " \"run_command\": \"your run command here\"\n"
+ "}\n");
+ file.value()->close();
+ }
+
+ open_file(Project::config_file_path);
+ });
+}
+
HackStudioWidget::ProjectLocation HackStudioWidget::current_project_location() const
{
return ProjectLocation { current_editor_wrapper().filename(), current_editor().cursor().line(), current_editor().cursor().column() };
diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.h b/Userland/DevTools/HackStudio/HackStudioWidget.h
index dfbfe3e30e..face53b6e7 100644
--- a/Userland/DevTools/HackStudio/HackStudioWidget.h
+++ b/Userland/DevTools/HackStudio/HackStudioWidget.h
@@ -120,6 +120,7 @@ private:
NonnullRefPtr<GUI::Action> create_run_action();
NonnullRefPtr<GUI::Action> create_stop_action();
NonnullRefPtr<GUI::Action> create_toggle_syntax_highlighting_mode_action();
+ NonnullRefPtr<GUI::Action> create_open_project_configuration_action();
void create_location_history_actions();
void add_new_editor_tab_widget(GUI::Widget& parent);
@@ -238,6 +239,7 @@ private:
RefPtr<GUI::Action> m_locations_history_back_action;
RefPtr<GUI::Action> m_locations_history_forward_action;
RefPtr<GUI::Action> m_toggle_semantic_highlighting_action;
+ RefPtr<GUI::Action> m_open_project_configuration_action;
RefPtr<Gfx::Font> read_editor_font_from_config();
void change_editor_font(RefPtr<Gfx::Font>);