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 to copy/paste properties in the inspector #39398

Closed
wants to merge 1 commit into from
Closed
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
33 changes: 33 additions & 0 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "editor_inspector.h"

#include "array_property_edit.h"
#include "core/os/keyboard.h"
#include "dictionary_property_edit.h"
#include "editor_feature_profile.h"
#include "editor_node.h"
Expand Down Expand Up @@ -749,6 +750,12 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) {
update();
emit_signal("property_checked", property, checked);
}
} else if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) {
menu->set_position(get_global_transform().xform(get_local_mouse_position()));
menu->set_size(Vector2(1, 1));
menu->popup();
select();
return;
}
}

Expand Down Expand Up @@ -840,6 +847,17 @@ String EditorProperty::get_tooltip_text() const {
return tooltip_text;
}

void EditorProperty::menu_option(int p_option) {
switch (p_option) {
case MENU_COPY: {
EditorNode::get_singleton()->get_inspector()->set_property_clipboard(object->get(property));
} break;
case MENU_PASTE: {
emit_changed(property, EditorNode::get_singleton()->get_inspector()->get_property_clipboard());
} 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 @@ -918,6 +936,12 @@ EditorProperty::EditorProperty() {
selected_focusable = -1;
label_reference = nullptr;
bottom_editor = nullptr;

menu = memnew(PopupMenu);
menu->add_item(TTR("Copy"), MENU_COPY, KEY_MASK_CMD | KEY_C);
menu->add_item(TTR("Paste"), MENU_PASTE, KEY_MASK_CMD | KEY_V);
menu->connect("id_pressed", callable_mp(this, &EditorProperty::menu_option));
add_child(menu);
}

////////////////////////////////////////////////
Expand Down Expand Up @@ -2370,6 +2394,14 @@ void EditorInspector::_feature_profile_changed() {
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 @@ -2415,6 +2447,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 Down
13 changes: 13 additions & 0 deletions editor/editor_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class EditorPropertyRevert {
class EditorProperty : public Container {
GDCLASS(EditorProperty, Container);

public:
enum MenuItems {
MENU_COPY,
MENU_PASTE
};

private:
String label;
int text_size;
Expand Down Expand Up @@ -95,6 +101,7 @@ class EditorProperty : public Container {
Vector<Control *> focusables;
Control *label_reference;
Control *bottom_editor;
PopupMenu *menu;

mutable String tooltip_text;

Expand Down Expand Up @@ -168,6 +175,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 @@ -305,6 +314,7 @@ class EditorInspector : public ScrollContainer {

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

void _edit_set(const String &p_name, const Variant &p_value, bool p_refresh_all, const String &p_changed_field);

Expand Down Expand Up @@ -392,6 +402,9 @@ class EditorInspector : public ScrollContainer {

void set_use_deletable_properties(bool p_enabled);

void set_property_clipboard(const Variant &p_value);
Variant get_property_clipboard() const;

EditorInspector();
};

Expand Down