summaryrefslogtreecommitdiff
path: root/editor/editor_inspector.cpp
diff options
context:
space:
mode:
authorTomek <kobewi4e@gmail.com>2021-08-27 00:39:42 +0200
committerGitHub <noreply@github.com>2021-08-27 00:39:42 +0200
commitf6f5e0f934e18cdd07cbefbf440b9e0208ccd676 (patch)
treef2ebbb92413ff2cd15f2195cdc600f14d364f8db /editor/editor_inspector.cpp
parentadafc509f33f83928881903f9fcba0eb6540fa96 (diff)
parent0205fffbf3ebf03cf974802f07368a5d18326893 (diff)
Merge pull request #39404 from rcorre/proposal-106-copy-prop-path
Allow copying property path from inspector.
Diffstat (limited to 'editor/editor_inspector.cpp')
-rw-r--r--editor/editor_inspector.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index 97cb9b6f85..380b205bad 100644
--- a/editor/editor_inspector.cpp
+++ b/editor/editor_inspector.cpp
@@ -31,11 +31,13 @@
#include "editor_inspector.h"
#include "array_property_edit.h"
+#include "core/os/keyboard.h"
#include "dictionary_property_edit.h"
#include "editor/doc_tools.h"
#include "editor_feature_profile.h"
#include "editor_node.h"
#include "editor_scale.h"
+#include "editor_settings.h"
#include "multi_node_edit.h"
#include "scene/resources/packed_scene.h"
@@ -782,6 +784,30 @@ void EditorProperty::gui_input(const Ref<InputEvent> &p_event) {
update();
emit_signal(SNAME("property_checked"), property, checked);
}
+ } else if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_RIGHT) {
+ _ensure_popup();
+ menu->set_position(get_screen_position() + get_local_mouse_position());
+ menu->set_size(Vector2(1, 1));
+ menu->popup();
+ select();
+ return;
+ }
+}
+
+void EditorProperty::unhandled_key_input(const Ref<InputEvent> &p_event) {
+ if (!selected) {
+ return;
+ }
+
+ if (ED_IS_SHORTCUT("property_editor/copy_property", p_event)) {
+ menu_option(MENU_COPY_PROPERTY);
+ accept_event();
+ } else if (ED_IS_SHORTCUT("property_editor/paste_property", p_event) && !is_read_only()) {
+ menu_option(MENU_PASTE_PROPERTY);
+ accept_event();
+ } else if (ED_IS_SHORTCUT("property_editor/copy_property_path", p_event)) {
+ menu_option(MENU_COPY_PROPERTY_PATH);
+ accept_event();
}
}
@@ -895,6 +921,20 @@ String EditorProperty::get_tooltip_text() const {
return tooltip_text;
}
+void EditorProperty::menu_option(int p_option) {
+ switch (p_option) {
+ case MENU_COPY_PROPERTY: {
+ EditorNode::get_singleton()->get_inspector()->set_property_clipboard(object->get(property));
+ } break;
+ case MENU_PASTE_PROPERTY: {
+ emit_changed(property, EditorNode::get_singleton()->get_inspector()->get_property_clipboard());
+ } break;
+ case MENU_COPY_PROPERTY_PATH: {
+ DisplayServer::get_singleton()->clipboard_set(property);
+ } break;
+ }
+}
+
void EditorProperty::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_label", "text"), &EditorProperty::set_label);
ClassDB::bind_method(D_METHOD("get_label"), &EditorProperty::get_label);
@@ -971,6 +1011,21 @@ EditorProperty::EditorProperty() {
label_reference = nullptr;
bottom_editor = nullptr;
delete_hover = false;
+ menu = nullptr;
+ set_process_unhandled_key_input(true);
+}
+
+void EditorProperty::_ensure_popup() {
+ if (menu) {
+ return;
+ }
+ menu = memnew(PopupMenu);
+ menu->add_shortcut(ED_GET_SHORTCUT("property_editor/copy_property"), MENU_COPY_PROPERTY);
+ menu->add_shortcut(ED_GET_SHORTCUT("property_editor/paste_property"), MENU_PASTE_PROPERTY);
+ menu->add_shortcut(ED_GET_SHORTCUT("property_editor/copy_property_path"), MENU_COPY_PROPERTY_PATH);
+ menu->connect("id_pressed", callable_mp(this, &EditorProperty::menu_option));
+ menu->set_item_disabled(MENU_PASTE_PROPERTY, is_read_only());
+ add_child(menu);
}
////////////////////////////////////////////////
@@ -2615,6 +2670,14 @@ void EditorInspector::set_restrict_to_basic_settings(bool p_restrict) {
update_tree();
}
+void EditorInspector::set_property_clipboard(const Variant &p_value) {
+ property_clipboard = p_value;
+}
+
+Variant EditorInspector::get_property_clipboard() const {
+ return property_clipboard;
+}
+
void EditorInspector::_bind_methods() {
ClassDB::bind_method("_edit_request_change", &EditorInspector::_edit_request_change);
@@ -2657,6 +2720,7 @@ EditorInspector::EditorInspector() {
property_focusable = -1;
sub_inspector = false;
deletable_properties = false;
+ property_clipboard = Variant();
get_v_scrollbar()->connect("value_changed", callable_mp(this, &EditorInspector::_vscroll_changed));
update_scroll_request = -1;
@@ -2666,4 +2730,8 @@ EditorInspector::EditorInspector() {
//used when class is created by the docgen to dump default values of everything bindable, editorsettings may not be created
refresh_countdown = 0.33;
}
+
+ ED_SHORTCUT("property_editor/copy_property", TTR("Copy Property"), KEY_MASK_CMD | KEY_C);
+ ED_SHORTCUT("property_editor/paste_property", TTR("Paste Property"), KEY_MASK_CMD | KEY_V);
+ ED_SHORTCUT("property_editor/copy_property_path", TTR("Copy Property Path"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_C);
}