Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow copying property path from inspector. #39404

Merged
merged 1 commit into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

////////////////////////////////////////////////
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
15 changes: 15 additions & 0 deletions editor/editor_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class EditorPropertyRevert {
class EditorProperty : public Container {
GDCLASS(EditorProperty, Container);

public:
enum MenuItems {
MENU_COPY_PROPERTY,
MENU_PASTE_PROPERTY,
MENU_COPY_PROPERTY_PATH,
};

private:
String label;
int text_size;
Expand Down Expand Up @@ -84,6 +91,7 @@ class EditorProperty : public Container {
bool use_folding;
bool draw_top_bg;

void _ensure_popup();
bool _is_property_different(const Variant &p_current, const Variant &p_orig);
bool _get_instantiated_node_original_property(const StringName &p_prop, Variant &value);
void _focusable_focused(int p_index);
Expand All @@ -97,6 +105,7 @@ class EditorProperty : public Container {
Vector<Control *> focusables;
Control *label_reference;
Control *bottom_editor;
PopupMenu *menu;

mutable String tooltip_text;

Expand All @@ -108,6 +117,7 @@ class EditorProperty : public Container {
static void _bind_methods();

virtual void gui_input(const Ref<InputEvent> &p_event) override;
virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override;

public:
void emit_changed(const StringName &p_property, const Variant &p_value, const StringName &p_field = StringName(), bool p_changing = false);
Expand Down Expand Up @@ -175,6 +185,8 @@ class EditorProperty : public Container {

bool can_revert_to_default() const { return can_revert; }

void menu_option(int p_option);

EditorProperty();
};

Expand Down Expand Up @@ -321,6 +333,7 @@ class EditorInspector : public ScrollContainer {

String property_prefix; //used for sectioned inspector
String object_class;
Variant property_clipboard;

bool restrict_to_basic = false;

Expand Down Expand Up @@ -412,6 +425,8 @@ class EditorInspector : public ScrollContainer {
void set_use_deletable_properties(bool p_enabled);

void set_restrict_to_basic_settings(bool p_restrict);
void set_property_clipboard(const Variant &p_value);
Variant get_property_clipboard() const;

EditorInspector();
};
Expand Down