浏览代码

HackStudio: Add the "Copy Full 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 full path in the clipboard.
Yuval 3 年之前
父节点
当前提交
bd74db157a
共有 2 个文件被更改,包括 21 次插入0 次删除
  1. 19 0
      Userland/DevTools/HackStudio/HackStudioWidget.cpp
  2. 2 0
      Userland/DevTools/HackStudio/HackStudioWidget.h

+ 19 - 0
Userland/DevTools/HackStudio/HackStudioWidget.cpp

@@ -473,6 +473,7 @@ NonnullRefPtr<GUI::Menu> HackStudioWidget::create_project_tree_view_context_menu
     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_copy_full_path_action = create_copy_full_path_action();
 
     m_new_directory_action = create_new_directory_action();
     m_delete_action = create_delete_action();
@@ -494,6 +495,7 @@ NonnullRefPtr<GUI::Menu> HackStudioWidget::create_project_tree_view_context_menu
     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);
+    project_tree_view_context_menu->add_action(*m_copy_full_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);
@@ -626,6 +628,23 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_copy_relative_path_action()
     return copy_relative_path_action;
 }
 
+NonnullRefPtr<GUI::Action> HackStudioWidget::create_copy_full_path_action()
+{
+    auto copy_full_path_action = GUI::Action::create("Copy &Full Path", [this](const GUI::Action&) {
+        auto paths = selected_file_paths();
+        VERIFY(!paths.is_empty());
+        Vector<String> full_paths;
+        for (auto& path : paths)
+            full_paths.append(get_absolute_path(path));
+        auto paths_string = String::join("\n", full_paths);
+        GUI::Clipboard::the().set_plain_text(paths_string);
+    });
+    copy_full_path_action->set_enabled(true);
+    copy_full_path_action->set_icon(GUI::Icon::default_icon("hard-disk").bitmap_for_size(16));
+
+    return copy_full_path_action;
+}
+
 NonnullRefPtr<GUI::Action> HackStudioWidget::create_delete_action()
 {
     auto delete_action = GUI::CommonActions::make_delete_action([this](const GUI::Action&) {

+ 2 - 0
Userland/DevTools/HackStudio/HackStudioWidget.h

@@ -113,6 +113,7 @@ private:
     NonnullRefPtr<GUI::Action> create_save_as_action();
     NonnullRefPtr<GUI::Action> create_show_in_file_manager_action();
     NonnullRefPtr<GUI::Action> create_copy_relative_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_action();
     NonnullRefPtr<GUI::Action> create_add_terminal_action();
@@ -221,6 +222,7 @@ private:
     RefPtr<GUI::Action> m_open_selected_in_new_tab_action;
     RefPtr<GUI::Action> m_show_in_file_manager_action;
     RefPtr<GUI::Action> m_copy_relative_path_action;
+    RefPtr<GUI::Action> m_copy_full_path_action;
     RefPtr<GUI::Action> m_delete_action;
     RefPtr<GUI::Action> m_tree_view_rename_action;
     RefPtr<GUI::Action> m_new_project_action;