1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:28:11 +00:00

HackStudio: Add the "Copy Relative Path" TreeView context menu option

This commit adds support for the option described above.
The option can be seen after a right click on a TreeView item,
and it puts the item's relative path in the clipboard (relative
to the project's root directory).
This commit is contained in:
Yuval 2022-06-29 18:20:31 +03:00 committed by Sam Atkins
parent 6978b53ea0
commit 4ef0433be1
2 changed files with 18 additions and 1 deletions

View file

@ -17,7 +17,6 @@
#include "Git/DiffViewer.h"
#include "Git/GitWidget.h"
#include "HackStudio.h"
#include "HackStudioWidget.h"
#include "Locator.h"
#include "Project.h"
#include "ProjectDeclarations.h"
@ -473,6 +472,7 @@ NonnullRefPtr<GUI::Menu> HackStudioWidget::create_project_tree_view_context_menu
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_copy_relative_path_action = create_copy_relative_path_action();
m_new_directory_action = create_new_directory_action();
m_delete_action = create_delete_action();
@ -493,6 +493,7 @@ NonnullRefPtr<GUI::Menu> HackStudioWidget::create_project_tree_view_context_menu
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);
project_tree_view_context_menu->add_action(*m_copy_relative_path_action);
// TODO: Cut, copy, duplicate with new name...
project_tree_view_context_menu->add_separator();
project_tree_view_context_menu->add_action(*m_tree_view_rename_action);
@ -611,6 +612,20 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_show_in_file_manager_action(
return show_in_file_manager_action;
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_copy_relative_path_action()
{
auto copy_relative_path_action = GUI::Action::create("Copy &Relative Path", [this](const GUI::Action&) {
auto paths = selected_file_paths();
VERIFY(!paths.is_empty());
auto paths_string = String::join("\n", paths);
GUI::Clipboard::the().set_plain_text(paths_string);
});
copy_relative_path_action->set_enabled(true);
copy_relative_path_action->set_icon(GUI::Icon::default_icon("hard-disk").bitmap_for_size(16));
return copy_relative_path_action;
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_delete_action()
{
auto delete_action = GUI::CommonActions::make_delete_action([this](const GUI::Action&) {