Skip to content

Commit a7ba867

Browse files
mrkctawesomekling
authored andcommitted
HackStudio: Add a "Project Configuration" button in the Edit menu
1 parent 9096da1 commit a7ba867

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Userland/DevTools/HackStudio/HackStudioWidget.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ HackStudioWidget::HackStudioWidget(String path_to_project)
137137
m_stop_action->set_enabled(false);
138138
};
139139

140+
m_open_project_configuration_action = create_open_project_configuration_action();
141+
140142
m_build_action = create_build_action();
141143
m_run_action = create_run_action();
142144
m_stop_action = create_stop_action();
@@ -1366,6 +1368,9 @@ void HackStudioWidget::create_edit_menu(GUI::Window& window)
13661368
});
13671369
vim_emulation_setting_action->set_checked(false);
13681370
edit_menu.add_action(vim_emulation_setting_action);
1371+
1372+
edit_menu.add_separator();
1373+
edit_menu.add_action(*m_open_project_configuration_action);
13691374
}
13701375

13711376
void HackStudioWidget::create_build_menu(GUI::Window& window)
@@ -1648,6 +1653,33 @@ void HackStudioWidget::create_location_history_actions()
16481653
m_locations_history_forward_action->set_enabled(false);
16491654
}
16501655

1656+
NonnullRefPtr<GUI::Action> HackStudioWidget::create_open_project_configuration_action()
1657+
{
1658+
return GUI::Action::create("Project Configuration", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/settings.png").release_value(), [&](auto&) {
1659+
auto parent_directory = LexicalPath::dirname(Project::config_file_path);
1660+
auto absolute_config_file_path = LexicalPath::absolute_path(m_project->root_path(), Project::config_file_path);
1661+
1662+
if (!Core::File::exists(absolute_config_file_path)) {
1663+
if (Core::File::exists(parent_directory) && !Core::File::is_directory(parent_directory)) {
1664+
GUI::MessageBox::show_error(window(), String::formatted("Cannot create the '{}' directory because there is already a file with that name", parent_directory));
1665+
return;
1666+
}
1667+
1668+
mkdir(LexicalPath::absolute_path(m_project->root_path(), parent_directory).characters(), 0755);
1669+
1670+
auto file = Core::File::open(absolute_config_file_path, Core::OpenMode::WriteOnly);
1671+
file.value()->write(
1672+
"{\n"
1673+
" \"build_command\": \"your build command here\",\n"
1674+
" \"run_command\": \"your run command here\"\n"
1675+
"}\n");
1676+
file.value()->close();
1677+
}
1678+
1679+
open_file(Project::config_file_path);
1680+
});
1681+
}
1682+
16511683
HackStudioWidget::ProjectLocation HackStudioWidget::current_project_location() const
16521684
{
16531685
return ProjectLocation { current_editor_wrapper().filename(), current_editor().cursor().line(), current_editor().cursor().column() };

Userland/DevTools/HackStudio/HackStudioWidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class HackStudioWidget : public GUI::Widget {
120120
NonnullRefPtr<GUI::Action> create_run_action();
121121
NonnullRefPtr<GUI::Action> create_stop_action();
122122
NonnullRefPtr<GUI::Action> create_toggle_syntax_highlighting_mode_action();
123+
NonnullRefPtr<GUI::Action> create_open_project_configuration_action();
123124
void create_location_history_actions();
124125

125126
void add_new_editor_tab_widget(GUI::Widget& parent);
@@ -238,6 +239,7 @@ class HackStudioWidget : public GUI::Widget {
238239
RefPtr<GUI::Action> m_locations_history_back_action;
239240
RefPtr<GUI::Action> m_locations_history_forward_action;
240241
RefPtr<GUI::Action> m_toggle_semantic_highlighting_action;
242+
RefPtr<GUI::Action> m_open_project_configuration_action;
241243

242244
RefPtr<Gfx::Font> read_editor_font_from_config();
243245
void change_editor_font(RefPtr<Gfx::Font>);

0 commit comments

Comments
 (0)