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 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 create_run_action(); NonnullRefPtr create_stop_action(); NonnullRefPtr create_toggle_syntax_highlighting_mode_action(); + NonnullRefPtr 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 m_locations_history_back_action; RefPtr m_locations_history_forward_action; RefPtr m_toggle_semantic_highlighting_action; + RefPtr m_open_project_configuration_action; RefPtr read_editor_font_from_config(); void change_editor_font(RefPtr);