HackStudio: Add "Open in New Tab" context menu entry

This action creates a new editor tab and opens the selected file in the
newly created tab.
This commit is contained in:
hhsdev 2022-05-26 04:56:08 +06:30 committed by Sam Atkins
parent 68bc742d9e
commit 3f230a638d
Notes: sideshowbarker 2024-07-17 10:09:00 +09:00
2 changed files with 18 additions and 0 deletions

View File

@ -471,6 +471,7 @@ NonnullRefPtr<GUI::Menu> HackStudioWidget::create_project_tree_view_context_menu
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_open_selected_in_new_tab_action = create_open_selected_in_new_tab_action();
m_show_in_file_manager_action = create_show_in_file_manager_action();
m_new_directory_action = create_new_directory_action();
@ -490,6 +491,7 @@ NonnullRefPtr<GUI::Menu> HackStudioWidget::create_project_tree_view_context_menu
new_file_submenu.add_action(*m_new_directory_action);
project_tree_view_context_menu->add_action(*m_open_selected_action);
project_tree_view_context_menu->add_action(*m_open_selected_in_new_tab_action);
project_tree_view_context_menu->add_action(*m_show_in_file_manager_action);
// TODO: Cut, copy, duplicate with new name...
project_tree_view_context_menu->add_separator();
@ -582,6 +584,20 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_open_selected_action()
return open_selected_action;
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_open_selected_in_new_tab_action()
{
auto open_selected_in_new_tab_action = GUI::Action::create("Open in New &Tab", [this](const GUI::Action&) {
auto files = selected_file_paths();
for (auto& file : files) {
add_new_editor(*m_current_editor_tab_widget);
open_file(file);
}
});
open_selected_in_new_tab_action->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png").release_value_but_fixme_should_propagate_errors());
open_selected_in_new_tab_action->set_enabled(true);
return open_selected_in_new_tab_action;
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_show_in_file_manager_action()
{
auto show_in_file_manager_action = GUI::Action::create("Show in File &Manager", [this](const GUI::Action&) {

View File

@ -100,6 +100,7 @@ private:
NonnullRefPtr<GUI::Action> create_new_file_action(String const& label, String const& icon, String const& extension);
NonnullRefPtr<GUI::Action> create_new_directory_action();
NonnullRefPtr<GUI::Action> create_open_selected_action();
NonnullRefPtr<GUI::Action> create_open_selected_in_new_tab_action();
NonnullRefPtr<GUI::Action> create_delete_action();
NonnullRefPtr<GUI::Action> create_new_project_action();
NonnullRefPtr<GUI::Action> create_switch_to_next_editor_tab_widget_action();
@ -216,6 +217,7 @@ private:
RefPtr<GUI::Action> m_new_directory_action;
RefPtr<GUI::Action> m_open_selected_action;
RefPtr<GUI::Action> m_open_selected_in_new_tab_action;
RefPtr<GUI::Action> m_show_in_file_manager_action;
RefPtr<GUI::Action> m_delete_action;
RefPtr<GUI::Action> m_tree_view_rename_action;