1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 19:07:34 +00:00

HackStudio: Remove release_values_but_fixme_should_propogate_errorss

There were a total of 20 fixmes that were removed. This required me to
create a `initialize_all()` function for the HackStudioWidget class
that could actually propagate the errors forward to the Serenity::Main
function for the HackStudio application.

All the fixmes dealt with loading icons for the various actions
possible.
This should not be a failure that keeps HackStudio from running, but
currently, if the icons cannot be loaded HackStudio fails to open.
This commit is contained in:
ominusliticus 2022-12-17 20:48:17 -05:00 committed by Ali Mohammad Pur
parent da4067a75f
commit ae16cfff0f
3 changed files with 177 additions and 137 deletions

View file

@ -96,7 +96,8 @@ ErrorOr<NonnullRefPtr<HackStudioWidget>> HackStudioWidget::create(DeprecatedStri
auto& left_hand_splitter = outer_splitter.add<GUI::VerticalSplitter>(); auto& left_hand_splitter = outer_splitter.add<GUI::VerticalSplitter>();
left_hand_splitter.layout()->set_spacing(6); left_hand_splitter.layout()->set_spacing(6);
left_hand_splitter.set_preferred_width(150); left_hand_splitter.set_preferred_width(150);
widget->m_project_tree_view_context_menu = widget->create_project_tree_view_context_menu();
widget->m_project_tree_view_context_menu = TRY(widget->create_project_tree_view_context_menu());
widget->m_right_hand_splitter = outer_splitter.add<GUI::VerticalSplitter>(); widget->m_right_hand_splitter = outer_splitter.add<GUI::VerticalSplitter>();
widget->m_right_hand_stack = widget->m_right_hand_splitter->add<GUI::StackWidget>(); widget->m_right_hand_stack = widget->m_right_hand_splitter->add<GUI::StackWidget>();
@ -121,16 +122,16 @@ ErrorOr<NonnullRefPtr<HackStudioWidget>> HackStudioWidget::create(DeprecatedStri
widget->m_switch_to_previous_editor = widget->create_switch_to_previous_editor_action(); widget->m_switch_to_previous_editor = widget->create_switch_to_previous_editor_action();
widget->m_remove_current_editor_tab_widget_action = widget->create_remove_current_editor_tab_widget_action(); widget->m_remove_current_editor_tab_widget_action = widget->create_remove_current_editor_tab_widget_action();
widget->m_remove_current_editor_action = widget->create_remove_current_editor_action(); widget->m_remove_current_editor_action = TRY(widget->create_remove_current_editor_action());
widget->m_open_action = widget->create_open_action(); widget->m_open_action = TRY(widget->create_open_action());
widget->m_save_action = widget->create_save_action(); widget->m_save_action = widget->create_save_action();
widget->m_save_as_action = widget->create_save_as_action(); widget->m_save_as_action = widget->create_save_as_action();
widget->m_new_project_action = widget->create_new_project_action(); widget->m_new_project_action = TRY(widget->create_new_project_action());
widget->m_add_editor_tab_widget_action = widget->create_add_editor_tab_widget_action(); widget->m_add_editor_tab_widget_action = widget->create_add_editor_tab_widget_action();
widget->m_add_editor_action = widget->create_add_editor_action(); widget->m_add_editor_action = TRY(widget->create_add_editor_action());
widget->m_add_terminal_action = widget->create_add_terminal_action(); widget->m_add_terminal_action = TRY(widget->create_add_terminal_action());
widget->m_remove_current_terminal_action = widget->create_remove_current_terminal_action(); widget->m_remove_current_terminal_action = TRY(widget->create_remove_current_terminal_action());
widget->m_locator = widget->add<Locator>(); widget->m_locator = widget->add<Locator>();
@ -138,12 +139,11 @@ ErrorOr<NonnullRefPtr<HackStudioWidget>> HackStudioWidget::create(DeprecatedStri
widget->m_stop_action->set_enabled(false); widget->m_stop_action->set_enabled(false);
}; };
widget->m_open_project_configuration_action = widget->create_open_project_configuration_action(); widget->m_open_project_configuration_action = TRY(widget->create_open_project_configuration_action());
widget->m_build_action = TRY(widget->create_build_action());
widget->m_build_action = widget->create_build_action(); widget->m_run_action = TRY(widget->create_run_action());
widget->m_run_action = widget->create_run_action(); widget->m_stop_action = TRY(widget->create_stop_action());
widget->m_stop_action = widget->create_stop_action(); widget->m_debug_action = TRY(widget->create_debug_action());
widget->m_debug_action = widget->create_debug_action();
widget->initialize_debugger(); widget->initialize_debugger();
@ -465,33 +465,31 @@ void HackStudioWidget::set_edit_mode(EditMode mode)
m_right_hand_stack->active_widget()->update(); m_right_hand_stack->active_widget()->update();
} }
NonnullRefPtr<GUI::Menu> HackStudioWidget::create_project_tree_view_context_menu() ErrorOr<NonnullRefPtr<GUI::Menu>> HackStudioWidget::create_project_tree_view_context_menu()
{ {
m_new_file_actions.append(create_new_file_action("&C++ Source File", "/res/icons/16x16/filetype-cplusplus.png", "cpp")); TRY(m_new_file_actions.try_append(TRY(create_new_file_action("&C++ Source File", "/res/icons/16x16/filetype-cplusplus.png", "cpp"))));
m_new_file_actions.append(create_new_file_action("C++ &Header File", "/res/icons/16x16/filetype-header.png", "h")); TRY(m_new_file_actions.try_append(TRY(create_new_file_action("C++ &Header File", "/res/icons/16x16/filetype-header.png", "h"))));
m_new_file_actions.append(create_new_file_action("&GML File", "/res/icons/16x16/filetype-gml.png", "gml")); TRY(m_new_file_actions.try_append(TRY(create_new_file_action("&GML File", "/res/icons/16x16/filetype-gml.png", "gml"))));
m_new_file_actions.append(create_new_file_action("P&ython Source File", "/res/icons/16x16/filetype-python.png", "py")); TRY(m_new_file_actions.try_append(TRY(create_new_file_action("P&ython Source File", "/res/icons/16x16/filetype-python.png", "py"))));
m_new_file_actions.append(create_new_file_action("Ja&va Source File", "/res/icons/16x16/filetype-java.png", "java")); TRY(m_new_file_actions.try_append(TRY(create_new_file_action("Ja&va Source File", "/res/icons/16x16/filetype-java.png", "java"))));
m_new_file_actions.append(create_new_file_action("C Source File", "/res/icons/16x16/filetype-c.png", "c")); TRY(m_new_file_actions.try_append(TRY(create_new_file_action("C Source File", "/res/icons/16x16/filetype-c.png", "c"))));
TRY(m_new_file_actions.try_append(TRY(create_new_file_action("&JavaScript Source File", "/res/icons/16x16/filetype-javascript.png", "js"))));
TRY(m_new_file_actions.try_append(TRY(create_new_file_action("HT&ML File", "/res/icons/16x16/filetype-html.png", "html"))));
TRY(m_new_file_actions.try_append(TRY(create_new_file_action("C&SS File", "/res/icons/16x16/filetype-css.png", "css"))));
TRY(m_new_file_actions.try_append(TRY(create_new_file_action("&PHP File", "/res/icons/16x16/filetype-php.png", "php"))));
TRY(m_new_file_actions.try_append(TRY(create_new_file_action("&Wasm File", "/res/icons/16x16/filetype-wasm.png", "wasm"))));
TRY(m_new_file_actions.try_append(TRY(create_new_file_action("&INI File", "/res/icons/16x16/filetype-ini.png", "ini"))));
TRY(m_new_file_actions.try_append(TRY(create_new_file_action("JS&ON File", "/res/icons/16x16/filetype-json.png", "json"))));
TRY(m_new_file_actions.try_append(TRY(create_new_file_action("Mark&down File", "/res/icons/16x16/filetype-markdown.png", "md"))));
m_new_file_actions.append(create_new_file_action("&JavaScript Source File", "/res/icons/16x16/filetype-javascript.png", "js")); m_new_plain_file_action = TRY(create_new_file_action("Plain &File", "/res/icons/16x16/new.png", ""));
m_new_file_actions.append(create_new_file_action("HT&ML File", "/res/icons/16x16/filetype-html.png", "html"));
m_new_file_actions.append(create_new_file_action("C&SS File", "/res/icons/16x16/filetype-css.png", "css"));
m_new_file_actions.append(create_new_file_action("&PHP File", "/res/icons/16x16/filetype-php.png", "php"));
m_new_file_actions.append(create_new_file_action("&Wasm File", "/res/icons/16x16/filetype-wasm.png", "wasm"));
m_new_file_actions.append(create_new_file_action("&INI File", "/res/icons/16x16/filetype-ini.png", "ini")); m_open_selected_action = TRY(create_open_selected_action());
m_new_file_actions.append(create_new_file_action("JS&ON File", "/res/icons/16x16/filetype-json.png", "json"));
m_new_file_actions.append(create_new_file_action("Mark&down File", "/res/icons/16x16/filetype-markdown.png", "md"));
m_new_plain_file_action = create_new_file_action("Plain &File", "/res/icons/16x16/new.png", "");
m_open_selected_action = create_open_selected_action();
m_show_in_file_manager_action = create_show_in_file_manager_action(); m_show_in_file_manager_action = create_show_in_file_manager_action();
m_copy_relative_path_action = create_copy_relative_path_action(); m_copy_relative_path_action = create_copy_relative_path_action();
m_copy_full_path_action = create_copy_full_path_action(); m_copy_full_path_action = create_copy_full_path_action();
m_new_directory_action = create_new_directory_action(); m_new_directory_action = TRY(create_new_directory_action());
m_delete_action = create_delete_action(); m_delete_action = create_delete_action();
m_tree_view_rename_action = GUI::CommonActions::make_rename_action([this](GUI::Action const&) { m_tree_view_rename_action = GUI::CommonActions::make_rename_action([this](GUI::Action const&) {
m_project_tree_view->begin_editing(m_project_tree_view->cursor_index()); m_project_tree_view->begin_editing(m_project_tree_view->cursor_index());
@ -502,7 +500,8 @@ NonnullRefPtr<GUI::Menu> HackStudioWidget::create_project_tree_view_context_menu
for (auto& new_file_action : m_new_file_actions) { for (auto& new_file_action : m_new_file_actions) {
new_file_submenu.add_action(new_file_action); new_file_submenu.add_action(new_file_action);
} }
new_file_submenu.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new.png"sv).release_value_but_fixme_should_propagate_errors()); auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new.png"sv));
new_file_submenu.set_icon(icon);
new_file_submenu.add_action(*m_new_plain_file_action); new_file_submenu.add_action(*m_new_plain_file_action);
new_file_submenu.add_separator(); new_file_submenu.add_separator();
new_file_submenu.add_action(*m_new_directory_action); new_file_submenu.add_action(*m_new_directory_action);
@ -518,9 +517,10 @@ NonnullRefPtr<GUI::Menu> HackStudioWidget::create_project_tree_view_context_menu
return project_tree_view_context_menu; return project_tree_view_context_menu;
} }
NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_file_action(DeprecatedString const& label, DeprecatedString const& icon, DeprecatedString const& extension) ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_new_file_action(DeprecatedString const& label, DeprecatedString const& icon, DeprecatedString const& extension)
{ {
return GUI::Action::create(label, Gfx::Bitmap::try_load_from_file(icon).release_value_but_fixme_should_propagate_errors(), [this, extension](const GUI::Action&) { auto icon_no_shadow = TRY(Gfx::Bitmap::try_load_from_file(icon));
return GUI::Action::create(label, icon_no_shadow, [this, extension](const GUI::Action&) {
DeprecatedString filename; DeprecatedString filename;
if (GUI::InputBox::show(window(), filename, "Enter name of new file:"sv, "Add new file to project"sv) != GUI::InputBox::ExecResult::OK) if (GUI::InputBox::show(window(), filename, "Enter name of new file:"sv, "Add new file to project"sv) != GUI::InputBox::ExecResult::OK)
return; return;
@ -559,9 +559,10 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_file_action(DeprecatedSt
}); });
} }
NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_directory_action() ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_new_directory_action()
{ {
return GUI::Action::create("&Directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/mkdir.png"sv).release_value_but_fixme_should_propagate_errors(), [this](const GUI::Action&) { auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/mkdir.png"sv));
return GUI::Action::create("&Directory...", { Mod_Ctrl | Mod_Shift, Key_N }, icon, [this](const GUI::Action&) {
DeprecatedString directory_name; DeprecatedString directory_name;
if (GUI::InputBox::show(window(), directory_name, "Enter name of new directory:"sv, "Add new folder to project"sv) != GUI::InputBox::ExecResult::OK) if (GUI::InputBox::show(window(), directory_name, "Enter name of new directory:"sv, "Add new folder to project"sv) != GUI::InputBox::ExecResult::OK)
return; return;
@ -590,14 +591,15 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_directory_action()
}); });
} }
NonnullRefPtr<GUI::Action> HackStudioWidget::create_open_selected_action() ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_open_selected_action()
{ {
auto open_selected_action = GUI::Action::create("&Open", [this](const GUI::Action&) { auto open_selected_action = GUI::Action::create("&Open", [this](const GUI::Action&) {
auto files = selected_file_paths(); auto files = selected_file_paths();
for (auto& file : files) for (auto& file : files)
open_file(file); open_file(file);
}); });
open_selected_action->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png"sv).release_value_but_fixme_should_propagate_errors()); auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png"sv));
open_selected_action->set_icon(icon);
open_selected_action->set_enabled(true); open_selected_action->set_enabled(true);
return open_selected_action; return open_selected_action;
} }
@ -701,9 +703,12 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_delete_action()
return delete_action; return delete_action;
} }
NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_project_action() ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_new_project_action()
{ {
return GUI::Action::create("&Project...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/hackstudio-project.png"sv).release_value_but_fixme_should_propagate_errors(), [this](const GUI::Action&) { auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/hackstudio-project.png"sv));
return GUI::Action::create(
"&Project...", icon,
[this](const GUI::Action&) {
if (warn_unsaved_changes("There are unsaved changes. Would you like to save before creating a new project?") == ContinueDecision::No) if (warn_unsaved_changes("There are unsaved changes. Would you like to save before creating a new project?") == ContinueDecision::No)
return; return;
// If the user wishes to save the changes, this occurs in warn_unsaved_changes. If they do not, // If the user wishes to save the changes, this occurs in warn_unsaved_changes. If they do not,
@ -849,9 +854,10 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_switch_to_previous_editor_ac
}); });
} }
NonnullRefPtr<GUI::Action> HackStudioWidget::create_remove_current_editor_action() ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_remove_current_editor_action()
{ {
return GUI::Action::create("&Remove Current Editor", { Mod_Alt | Mod_Shift, Key_E }, Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/remove-editor.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) { auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/remove-editor.png"sv));
return GUI::Action::create("&Remove Current Editor", { Mod_Alt | Mod_Shift, Key_E }, icon, [this](auto&) {
if (m_all_editor_wrappers.size() <= 1) if (m_all_editor_wrappers.size() <= 1)
return; return;
auto tab_widget = m_current_editor_tab_widget; auto tab_widget = m_current_editor_tab_widget;
@ -862,9 +868,10 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_remove_current_editor_action
}); });
} }
NonnullRefPtr<GUI::Action> HackStudioWidget::create_open_action() ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_open_action()
{ {
return GUI::Action::create("&Open Project...", { Mod_Ctrl | Mod_Shift, Key_O }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) { auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png"sv));
return GUI::Action::create("&Open Project...", { Mod_Ctrl | Mod_Shift, Key_O }, icon, [this](auto&) {
auto open_path = GUI::FilePicker::get_open_filepath(window(), "Open project", m_project->root_path(), true); auto open_path = GUI::FilePicker::get_open_filepath(window(), "Open project", m_project->root_path(), true);
if (!open_path.has_value()) if (!open_path.has_value())
return; return;
@ -928,9 +935,10 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_save_as_action()
}); });
} }
NonnullRefPtr<GUI::Action> HackStudioWidget::create_remove_current_terminal_action() ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_remove_current_terminal_action()
{ {
return GUI::Action::create("Remove &Current Terminal", { Mod_Alt | Mod_Shift, Key_T }, Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/remove-terminal.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) { auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/remove-terminal.png"sv));
return GUI::Action::create("Remove &Current Terminal", { Mod_Alt | Mod_Shift, Key_T }, icon, [this](auto&) {
auto widget = m_action_tab_widget->active_widget(); auto widget = m_action_tab_widget->active_widget();
if (!widget) if (!widget)
return; return;
@ -953,20 +961,22 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_add_editor_tab_widget_action
}); });
} }
NonnullRefPtr<GUI::Action> HackStudioWidget::create_add_editor_action() ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_add_editor_action()
{ {
auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/add-editor.png"sv));
return GUI::Action::create("Add New &Editor", { Mod_Ctrl | Mod_Alt, Key_E }, return GUI::Action::create("Add New &Editor", { Mod_Ctrl | Mod_Alt, Key_E },
Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/add-editor.png"sv).release_value_but_fixme_should_propagate_errors(), icon,
[this](auto&) { [this](auto&) {
add_new_editor(*m_current_editor_tab_widget); add_new_editor(*m_current_editor_tab_widget);
update_actions(); update_actions();
}); });
} }
NonnullRefPtr<GUI::Action> HackStudioWidget::create_add_terminal_action() ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_add_terminal_action()
{ {
auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/add-terminal.png"sv));
return GUI::Action::create("Add New &Terminal", { Mod_Ctrl | Mod_Alt, Key_T }, return GUI::Action::create("Add New &Terminal", { Mod_Ctrl | Mod_Alt, Key_T },
Gfx::Bitmap::try_load_from_file("/res/icons/hackstudio/add-terminal.png"sv).release_value_but_fixme_should_propagate_errors(), icon,
[this](auto&) { [this](auto&) {
auto& terminal_wrapper = m_action_tab_widget->add_tab<TerminalWrapper>("Terminal"); auto& terminal_wrapper = m_action_tab_widget->add_tab<TerminalWrapper>("Terminal");
terminal_wrapper.on_command_exit = [&]() { terminal_wrapper.on_command_exit = [&]() {
@ -987,9 +997,10 @@ void HackStudioWidget::reveal_action_tab(GUI::Widget& widget)
m_action_tab_widget->set_active_widget(&widget); m_action_tab_widget->set_active_widget(&widget);
} }
NonnullRefPtr<GUI::Action> HackStudioWidget::create_debug_action() ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_debug_action()
{ {
return GUI::Action::create("&Debug", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-run.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) { auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/debug-run.png"sv));
return GUI::Action::create("&Debug", icon, [this](auto&) {
if (!Core::File::exists(get_project_executable_path())) { if (!Core::File::exists(get_project_executable_path())) {
GUI::MessageBox::show(window(), DeprecatedString::formatted("Could not find file: {}. (did you build the project?)", get_project_executable_path()), "Error"sv, GUI::MessageBox::Type::Error); GUI::MessageBox::show(window(), DeprecatedString::formatted("Could not find file: {}. (did you build the project?)", get_project_executable_path()), "Error"sv, GUI::MessageBox::Type::Error);
return; return;
@ -1282,9 +1293,10 @@ void HackStudioWidget::create_toolbar(GUI::Widget& parent)
toolbar.add_action(*m_debug_action); toolbar.add_action(*m_debug_action);
} }
NonnullRefPtr<GUI::Action> HackStudioWidget::create_build_action() ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_build_action()
{ {
return GUI::Action::create("&Build", { Mod_Ctrl, Key_B }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/build.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) { auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/build.png"sv));
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 (warn_unsaved_changes("There are unsaved changes, do you want to save before building?") == ContinueDecision::No)
return; return;
@ -1293,9 +1305,10 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_build_action()
}); });
} }
NonnullRefPtr<GUI::Action> HackStudioWidget::create_run_action() ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_run_action()
{ {
return GUI::Action::create("&Run", { Mod_Ctrl, Key_R }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/program-run.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) { auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/program-run.png"sv));
return GUI::Action::create("&Run", { Mod_Ctrl, Key_R }, icon, [this](auto&) {
reveal_action_tab(*m_terminal_wrapper); reveal_action_tab(*m_terminal_wrapper);
run(); run();
}); });
@ -1387,7 +1400,7 @@ void HackStudioWidget::update_recent_projects_submenu()
} }
} }
void HackStudioWidget::create_file_menu(GUI::Window& window) ErrorOr<void> HackStudioWidget::create_file_menu(GUI::Window& window)
{ {
auto& file_menu = window.add_menu("&File"); auto& file_menu = window.add_menu("&File");
@ -1397,14 +1410,21 @@ void HackStudioWidget::create_file_menu(GUI::Window& window)
for (auto& new_file_action : m_new_file_actions) { for (auto& new_file_action : m_new_file_actions) {
new_submenu.add_action(new_file_action); new_submenu.add_action(new_file_action);
} }
new_submenu.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new.png"sv).release_value_but_fixme_should_propagate_errors());
{
auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new.png"sv));
new_submenu.set_icon(icon);
}
new_submenu.add_action(*m_new_plain_file_action); new_submenu.add_action(*m_new_plain_file_action);
new_submenu.add_separator(); new_submenu.add_separator();
new_submenu.add_action(*m_new_directory_action); new_submenu.add_action(*m_new_directory_action);
file_menu.add_action(*m_open_action); file_menu.add_action(*m_open_action);
m_recent_projects_submenu = &file_menu.add_submenu("Open &Recent"); m_recent_projects_submenu = &file_menu.add_submenu("Open &Recent");
m_recent_projects_submenu->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open-recent.png"sv).release_value_but_fixme_should_propagate_errors()); {
auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open-recent.png"sv));
m_recent_projects_submenu->set_icon(icon);
}
update_recent_projects_submenu(); update_recent_projects_submenu();
file_menu.add_action(*m_save_action); file_menu.add_action(*m_save_action);
file_menu.add_action(*m_save_as_action); file_menu.add_action(*m_save_as_action);
@ -1412,12 +1432,14 @@ void HackStudioWidget::create_file_menu(GUI::Window& window)
file_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) { file_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the()->quit(); GUI::Application::the()->quit();
})); }));
return {};
} }
void HackStudioWidget::create_edit_menu(GUI::Window& window) ErrorOr<void> HackStudioWidget::create_edit_menu(GUI::Window& window)
{ {
auto& edit_menu = window.add_menu("&Edit"); auto& edit_menu = window.add_menu("&Edit");
edit_menu.add_action(GUI::Action::create("&Find in Files...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/find.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) { auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/find.png"sv));
edit_menu.add_action(GUI::Action::create("&Find in Files...", { Mod_Ctrl | Mod_Shift, Key_F }, icon, [this](auto&) {
reveal_action_tab(*m_find_in_files_widget); reveal_action_tab(*m_find_in_files_widget);
m_find_in_files_widget->focus_textbox_and_select_all(); m_find_in_files_widget->focus_textbox_and_select_all();
})); }));
@ -1438,6 +1460,7 @@ void HackStudioWidget::create_edit_menu(GUI::Window& window)
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 {};
} }
void HackStudioWidget::create_build_menu(GUI::Window& window) void HackStudioWidget::create_build_menu(GUI::Window& window)
@ -1451,7 +1474,7 @@ void HackStudioWidget::create_build_menu(GUI::Window& window)
build_menu.add_action(*m_debug_action); build_menu.add_action(*m_debug_action);
} }
void HackStudioWidget::create_view_menu(GUI::Window& window) ErrorOr<void> HackStudioWidget::create_view_menu(GUI::Window& window)
{ {
auto hide_action_tabs_action = GUI::Action::create("&Hide Action Tabs", { Mod_Ctrl | Mod_Shift, Key_X }, [this](auto&) { auto hide_action_tabs_action = GUI::Action::create("&Hide Action Tabs", { Mod_Ctrl | Mod_Shift, Key_X }, [this](auto&) {
hide_action_tabs(); hide_action_tabs();
@ -1469,7 +1492,7 @@ void HackStudioWidget::create_view_menu(GUI::Window& window)
view_menu.add_action(hide_action_tabs_action); view_menu.add_action(hide_action_tabs_action);
view_menu.add_action(open_locator_action); view_menu.add_action(open_locator_action);
view_menu.add_action(show_dotfiles_action); view_menu.add_action(show_dotfiles_action);
m_toggle_semantic_highlighting_action = create_toggle_syntax_highlighting_mode_action(); m_toggle_semantic_highlighting_action = TRY(create_toggle_syntax_highlighting_mode_action());
view_menu.add_action(*m_toggle_semantic_highlighting_action); view_menu.add_action(*m_toggle_semantic_highlighting_action);
view_menu.add_separator(); view_menu.add_separator();
@ -1498,7 +1521,8 @@ void HackStudioWidget::create_view_menu(GUI::Window& window)
m_no_wrapping_action->set_checked(true); m_no_wrapping_action->set_checked(true);
m_editor_font_action = GUI::Action::create("Editor &Font...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-font-editor.png"sv).release_value_but_fixme_should_propagate_errors(), auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-font-editor.png"sv));
m_editor_font_action = GUI::Action::create("Editor &Font...", icon,
[&](auto&) { [&](auto&) {
auto picker = GUI::FontPicker::construct(&window, m_editor_font, false); auto picker = GUI::FontPicker::construct(&window, m_editor_font, false);
if (picker->exec() == GUI::Dialog::ExecResult::OK) { if (picker->exec() == GUI::Dialog::ExecResult::OK) {
@ -1516,7 +1540,7 @@ void HackStudioWidget::create_view_menu(GUI::Window& window)
view_menu.add_separator(); view_menu.add_separator();
create_location_history_actions(); TRY(create_location_history_actions());
view_menu.add_action(*m_locations_history_back_action); view_menu.add_action(*m_locations_history_back_action);
view_menu.add_action(*m_locations_history_forward_action); view_menu.add_action(*m_locations_history_forward_action);
@ -1525,6 +1549,7 @@ void HackStudioWidget::create_view_menu(GUI::Window& window)
view_menu.add_action(GUI::CommonActions::make_fullscreen_action([&](auto&) { view_menu.add_action(GUI::CommonActions::make_fullscreen_action([&](auto&) {
window.set_fullscreen(!window.is_fullscreen()); window.set_fullscreen(!window.is_fullscreen());
})); }));
return {};
} }
void HackStudioWidget::create_help_menu(GUI::Window& window) void HackStudioWidget::create_help_menu(GUI::Window& window)
@ -1534,9 +1559,10 @@ void HackStudioWidget::create_help_menu(GUI::Window& window)
help_menu.add_action(GUI::CommonActions::make_about_action("Hack Studio", GUI::Icon::default_icon("app-hack-studio"sv), &window)); help_menu.add_action(GUI::CommonActions::make_about_action("Hack Studio", GUI::Icon::default_icon("app-hack-studio"sv), &window));
} }
NonnullRefPtr<GUI::Action> HackStudioWidget::create_stop_action() ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_stop_action()
{ {
auto action = GUI::Action::create("&Stop", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/program-stop.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) { auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/program-stop.png"sv));
auto action = GUI::Action::create("&Stop", icon, [this](auto&) {
if (!Debugger::the().session()) { if (!Debugger::the().session()) {
if (auto result = m_terminal_wrapper->kill_running_command(); result.is_error()) if (auto result = m_terminal_wrapper->kill_running_command(); result.is_error())
warnln("{}", result.error()); warnln("{}", result.error());
@ -1550,13 +1576,14 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_stop_action()
return action; return action;
} }
void HackStudioWidget::initialize_menubar(GUI::Window& window) ErrorOr<void> HackStudioWidget::initialize_menubar(GUI::Window& window)
{ {
create_file_menu(window); TRY(create_file_menu(window));
create_edit_menu(window); TRY(create_edit_menu(window));
create_build_menu(window); create_build_menu(window);
create_view_menu(window); TRY(create_view_menu(window));
create_help_menu(window); create_help_menu(window);
return {};
} }
void HackStudioWidget::update_statusbar() void HackStudioWidget::update_statusbar()
@ -1701,9 +1728,11 @@ void HackStudioWidget::on_cursor_change()
update_history_actions(); update_history_actions();
} }
void HackStudioWidget::create_location_history_actions() ErrorOr<void> HackStudioWidget::create_location_history_actions()
{ {
m_locations_history_back_action = GUI::Action::create("Go Back", { Mod_Alt | Mod_Shift, Key_Left }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-back.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) { {
auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-back.png"sv));
m_locations_history_back_action = GUI::Action::create("Go Back", { Mod_Alt | Mod_Shift, Key_Left }, icon, [this](auto&) {
if (m_locations_history_end_index <= 1) if (m_locations_history_end_index <= 1)
return; return;
@ -1716,8 +1745,11 @@ void HackStudioWidget::create_location_history_actions()
update_history_actions(); update_history_actions();
}); });
}
m_locations_history_forward_action = GUI::Action::create("Go Forward", { Mod_Alt | Mod_Shift, Key_Right }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) { {
auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png"sv));
m_locations_history_forward_action = GUI::Action::create("Go Forward", { Mod_Alt | Mod_Shift, Key_Right }, icon, [this](auto&) {
if (m_locations_history_end_index == m_locations_history.size()) if (m_locations_history_end_index == m_locations_history.size())
return; return;
@ -1730,12 +1762,15 @@ void HackStudioWidget::create_location_history_actions()
update_history_actions(); update_history_actions();
}); });
}
m_locations_history_forward_action->set_enabled(false); m_locations_history_forward_action->set_enabled(false);
return {};
} }
NonnullRefPtr<GUI::Action> HackStudioWidget::create_open_project_configuration_action() ErrorOr<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"sv).release_value(), [&](auto&) { auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/settings.png"sv));
return GUI::Action::create("Project Configuration", icon, [&](auto&) {
auto parent_directory = LexicalPath::dirname(Project::config_file_path); 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); auto absolute_config_file_path = LexicalPath::absolute_path(m_project->root_path(), Project::config_file_path);
@ -1836,9 +1871,10 @@ void HackStudioWidget::for_each_open_file(Function<void(ProjectFile const&)> fun
} }
} }
NonnullRefPtr<GUI::Action> HackStudioWidget::create_toggle_syntax_highlighting_mode_action() ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_toggle_syntax_highlighting_mode_action()
{ {
auto action = GUI::Action::create_checkable("&Semantic Highlighting", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-cplusplus.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto& action) { auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-cplusplus.png"sv));
auto action = GUI::Action::create_checkable("&Semantic Highlighting", icon, [this](auto& action) {
for (auto& editor_wrapper : m_all_editor_wrappers) for (auto& editor_wrapper : m_all_editor_wrappers)
editor_wrapper.editor().set_semantic_syntax_highlighting(action.is_checked()); editor_wrapper.editor().set_semantic_syntax_highlighting(action.is_checked());
}); });

View file

@ -56,7 +56,7 @@ public:
GUI::TabWidget const& current_editor_tab_widget() const; GUI::TabWidget const& current_editor_tab_widget() const;
DeprecatedString const& active_file() const { return m_current_editor_wrapper->filename(); } DeprecatedString const& active_file() const { return m_current_editor_wrapper->filename(); }
void initialize_menubar(GUI::Window&); ErrorOr<void> initialize_menubar(GUI::Window&);
Locator& locator() Locator& locator()
{ {
@ -100,35 +100,35 @@ private:
void set_edit_mode(EditMode); void set_edit_mode(EditMode);
NonnullRefPtr<GUI::Menu> create_project_tree_view_context_menu(); ErrorOr<NonnullRefPtr<GUI::Menu>> create_project_tree_view_context_menu();
NonnullRefPtr<GUI::Action> create_new_file_action(DeprecatedString const& label, DeprecatedString const& icon, DeprecatedString const& extension); ErrorOr<NonnullRefPtr<GUI::Action>> create_new_file_action(DeprecatedString const& label, DeprecatedString const& icon, DeprecatedString const& extension);
NonnullRefPtr<GUI::Action> create_new_directory_action(); ErrorOr<NonnullRefPtr<GUI::Action>> create_new_directory_action();
NonnullRefPtr<GUI::Action> create_open_selected_action(); ErrorOr<NonnullRefPtr<GUI::Action>> create_open_selected_action();
NonnullRefPtr<GUI::Action> create_open_selected_in_new_tab_action(); NonnullRefPtr<GUI::Action> create_open_selected_in_new_tab_action();
NonnullRefPtr<GUI::Action> create_delete_action(); NonnullRefPtr<GUI::Action> create_delete_action();
NonnullRefPtr<GUI::Action> create_new_project_action(); ErrorOr<NonnullRefPtr<GUI::Action>> create_new_project_action();
NonnullRefPtr<GUI::Action> create_switch_to_next_editor_tab_widget_action(); NonnullRefPtr<GUI::Action> create_switch_to_next_editor_tab_widget_action();
NonnullRefPtr<GUI::Action> create_switch_to_next_editor_action(); NonnullRefPtr<GUI::Action> create_switch_to_next_editor_action();
NonnullRefPtr<GUI::Action> create_switch_to_previous_editor_action(); NonnullRefPtr<GUI::Action> create_switch_to_previous_editor_action();
NonnullRefPtr<GUI::Action> create_remove_current_editor_tab_widget_action(); NonnullRefPtr<GUI::Action> create_remove_current_editor_tab_widget_action();
NonnullRefPtr<GUI::Action> create_remove_current_editor_action(); ErrorOr<NonnullRefPtr<GUI::Action>> create_remove_current_editor_action();
NonnullRefPtr<GUI::Action> create_open_action(); ErrorOr<NonnullRefPtr<GUI::Action>> create_open_action();
NonnullRefPtr<GUI::Action> create_save_action(); NonnullRefPtr<GUI::Action> create_save_action();
NonnullRefPtr<GUI::Action> create_save_as_action(); NonnullRefPtr<GUI::Action> create_save_as_action();
NonnullRefPtr<GUI::Action> create_show_in_file_manager_action(); NonnullRefPtr<GUI::Action> create_show_in_file_manager_action();
NonnullRefPtr<GUI::Action> create_copy_relative_path_action(); NonnullRefPtr<GUI::Action> create_copy_relative_path_action();
NonnullRefPtr<GUI::Action> create_copy_full_path_action(); NonnullRefPtr<GUI::Action> create_copy_full_path_action();
NonnullRefPtr<GUI::Action> create_add_editor_tab_widget_action(); NonnullRefPtr<GUI::Action> create_add_editor_tab_widget_action();
NonnullRefPtr<GUI::Action> create_add_editor_action(); ErrorOr<NonnullRefPtr<GUI::Action>> create_add_editor_action();
NonnullRefPtr<GUI::Action> create_add_terminal_action(); ErrorOr<NonnullRefPtr<GUI::Action>> create_add_terminal_action();
NonnullRefPtr<GUI::Action> create_remove_current_terminal_action(); ErrorOr<NonnullRefPtr<GUI::Action>> create_remove_current_terminal_action();
NonnullRefPtr<GUI::Action> create_debug_action(); ErrorOr<NonnullRefPtr<GUI::Action>> create_debug_action();
NonnullRefPtr<GUI::Action> create_build_action(); ErrorOr<NonnullRefPtr<GUI::Action>> create_build_action();
NonnullRefPtr<GUI::Action> create_run_action(); ErrorOr<NonnullRefPtr<GUI::Action>> create_run_action();
NonnullRefPtr<GUI::Action> create_stop_action(); ErrorOr<NonnullRefPtr<GUI::Action>> create_stop_action();
NonnullRefPtr<GUI::Action> create_toggle_syntax_highlighting_mode_action(); ErrorOr<NonnullRefPtr<GUI::Action>> create_toggle_syntax_highlighting_mode_action();
NonnullRefPtr<GUI::Action> create_open_project_configuration_action(); ErrorOr<NonnullRefPtr<GUI::Action>> create_open_project_configuration_action();
void create_location_history_actions(); ErrorOr<void> create_location_history_actions();
void add_new_editor_tab_widget(GUI::Widget& parent); void add_new_editor_tab_widget(GUI::Widget& parent);
void add_new_editor(GUI::TabWidget& parent); void add_new_editor(GUI::TabWidget& parent);
@ -147,11 +147,11 @@ private:
void create_open_files_view(GUI::Widget& parent); void create_open_files_view(GUI::Widget& parent);
void create_toolbar(GUI::Widget& parent); void create_toolbar(GUI::Widget& parent);
ErrorOr<void> create_action_tab(GUI::Widget& parent); ErrorOr<void> create_action_tab(GUI::Widget& parent);
void create_file_menu(GUI::Window&); ErrorOr<void> create_file_menu(GUI::Window&);
void update_recent_projects_submenu(); void update_recent_projects_submenu();
void create_edit_menu(GUI::Window&); ErrorOr<void> create_edit_menu(GUI::Window&);
void create_build_menu(GUI::Window&); void create_build_menu(GUI::Window&);
void create_view_menu(GUI::Window&); ErrorOr<void> create_view_menu(GUI::Window&);
void create_help_menu(GUI::Window&); void create_help_menu(GUI::Window&);
void create_project_tab(GUI::Widget& parent); void create_project_tab(GUI::Widget& parent);
void configure_project_tree_view(); void configure_project_tree_view();

View file

@ -15,6 +15,7 @@
#include <LibCore/System.h> #include <LibCore/System.h>
#include <LibGUI/Application.h> #include <LibGUI/Application.h>
#include <LibGUI/Menubar.h> #include <LibGUI/Menubar.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Notification.h> #include <LibGUI/Notification.h>
#include <LibGUI/Window.h> #include <LibGUI/Window.h>
#include <LibMain/Main.h> #include <LibMain/Main.h>
@ -30,7 +31,7 @@ using namespace HackStudio;
static WeakPtr<HackStudioWidget> s_hack_studio_widget; static WeakPtr<HackStudioWidget> s_hack_studio_widget;
static bool make_is_available(); static bool make_is_available();
static void notify_make_not_available(); static ErrorOr<void> notify_make_not_available();
static void update_path_environment_variable(); static void update_path_environment_variable();
static Optional<DeprecatedString> last_opened_project_path(); static Optional<DeprecatedString> last_opened_project_path();
@ -43,12 +44,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto window = GUI::Window::construct(); auto window = GUI::Window::construct();
window->resize(840, 600); window->resize(840, 600);
window->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-hack-studio.png"sv).release_value_but_fixme_should_propagate_errors()); auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-hack-studio.png"sv));
window->set_icon(icon);
update_path_environment_variable(); update_path_environment_variable();
if (!make_is_available()) { if (!make_is_available()) {
notify_make_not_available(); TRY(notify_make_not_available());
} }
char const* path_argument = nullptr; char const* path_argument = nullptr;
@ -74,7 +76,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->set_title(DeprecatedString::formatted("{} - Hack Studio", hack_studio_widget->project().name())); window->set_title(DeprecatedString::formatted("{} - Hack Studio", hack_studio_widget->project().name()));
hack_studio_widget->initialize_menubar(*window); TRY(hack_studio_widget->initialize_menubar(*window));
window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision { window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision {
hack_studio_widget->locator().close(); hack_studio_widget->locator().close();
@ -110,13 +112,15 @@ static bool make_is_available()
return WEXITSTATUS(wstatus) == 0; return WEXITSTATUS(wstatus) == 0;
} }
static void notify_make_not_available() static ErrorOr<void> notify_make_not_available()
{ {
auto notification = GUI::Notification::construct(); auto notification = GUI::Notification::construct();
notification->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/32x32/app-hack-studio.png"sv).release_value_but_fixme_should_propagate_errors()); auto icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/32x32/app-hack-studio.png"sv));
notification->set_icon(icon);
notification->set_title("'make' Not Available"); notification->set_title("'make' Not Available");
notification->set_text("You probably want to install the binutils, gcc, and make ports from the root of the Serenity repository"); notification->set_text("You probably want to install the binutils, gcc, and make ports from the root of the Serenity repository");
notification->show(); notification->show();
return {};
} }
static void update_path_environment_variable() static void update_path_environment_variable()