瀏覽代碼

Inspector: Add context menu to copy property name/value

I added a context menu for the property tree view to copy the name/value
of a property.
DragonAlex98 4 年之前
父節點
當前提交
fd43ee09e1
共有 1 個文件被更改,包括 20 次插入0 次删除
  1. 20 0
      Userland/DevTools/Inspector/main.cpp

+ 20 - 0
Userland/DevTools/Inspector/main.cpp

@@ -33,6 +33,7 @@
 #include <LibDesktop/Launcher.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/BoxLayout.h>
+#include <LibGUI/Clipboard.h>
 #include <LibGUI/Menu.h>
 #include <LibGUI/Menubar.h>
 #include <LibGUI/MessageBox.h>
@@ -174,6 +175,25 @@ int main(int argc, char** argv)
         remote_process.set_inspected_object(remote_object->address);
     };
 
+    auto properties_tree_view_context_menu = GUI::Menu::construct("Properties Tree View");
+
+    auto copy_bitmap = Gfx::Bitmap::load_from_file("/res/icons/16x16/edit-copy.png");
+    auto copy_property_name_action = GUI::Action::create("Copy Property Name", copy_bitmap, [&](auto&) {
+        GUI::Clipboard::the().set_plain_text(properties_tree_view.selection().first().data().to_string());
+    });
+    auto copy_property_value_action = GUI::Action::create("Copy Property Value", copy_bitmap, [&](auto&) {
+        GUI::Clipboard::the().set_plain_text(properties_tree_view.selection().first().sibling_at_column(1).data().to_string());
+    });
+
+    properties_tree_view_context_menu->add_action(copy_property_name_action);
+    properties_tree_view_context_menu->add_action(copy_property_value_action);
+
+    properties_tree_view.on_context_menu_request = [&](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) {
+        if (index.is_valid()) {
+            properties_tree_view_context_menu->popup(event.screen_position());
+        }
+    };
+
     window->set_menubar(move(menubar));
     window->show();
     remote_process.update();