From 4ef0433be114ef713cca956bfb9887e47a813d58 Mon Sep 17 00:00:00 2001 From: Yuval Date: Wed, 29 Jun 2022 18:20:31 +0300 Subject: [PATCH] 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). --- .../DevTools/HackStudio/HackStudioWidget.cpp | 17 ++++++++++++++++- Userland/DevTools/HackStudio/HackStudioWidget.h | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp index ce54329954..4f87e45914 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp +++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp @@ -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 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 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 HackStudioWidget::create_show_in_file_manager_action( return show_in_file_manager_action; } +NonnullRefPtr 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 HackStudioWidget::create_delete_action() { auto delete_action = GUI::CommonActions::make_delete_action([this](const GUI::Action&) { diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.h b/Userland/DevTools/HackStudio/HackStudioWidget.h index a8bed831c6..406dd7553a 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.h +++ b/Userland/DevTools/HackStudio/HackStudioWidget.h @@ -112,6 +112,7 @@ private: NonnullRefPtr create_save_action(); NonnullRefPtr create_save_as_action(); NonnullRefPtr create_show_in_file_manager_action(); + NonnullRefPtr create_copy_relative_path_action(); NonnullRefPtr create_add_editor_tab_widget_action(); NonnullRefPtr create_add_editor_action(); NonnullRefPtr create_add_terminal_action(); @@ -219,6 +220,7 @@ private: RefPtr m_open_selected_action; RefPtr m_open_selected_in_new_tab_action; RefPtr m_show_in_file_manager_action; + RefPtr m_copy_relative_path_action; RefPtr m_delete_action; RefPtr m_tree_view_rename_action; RefPtr m_new_project_action;