Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Make some improvements to the right-click menu for checkable inspector sections

Michael Alexsander8f1c28069343
diff --git a/editor/inspector/editor_inspector.cpp b/editor/inspector/editor_inspector.cpp
index 279d306bda4..76437259a8b 100644
--- a/editor/inspector/editor_inspector.cpp
+++ b/editor/inspector/editor_inspector.cpp
@@ -2633,7 +2633,7 @@ void EditorInspectorSection::gui_input(const Ref<InputEvent> &p_event) {
fold();
}
}
- } else if ((!checkable || checked) && mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) {
+ } else if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) {
accept_event();
_update_popup();
menu->set_position(get_screen_position() + get_local_mouse_position());
@@ -2747,6 +2747,10 @@ void EditorInspectorSection::set_checked(bool p_checked) {
queue_redraw();
}
+void EditorInspectorSection::set_doc_path(const String &p_doc_path) {
+ doc_path = p_doc_path;
+}
+
bool EditorInspectorSection::has_revertable_properties() const {
return !revertable_properties.is_empty();
}
@@ -2789,20 +2793,62 @@ void EditorInspectorSection::update_property() {
}
void EditorInspectorSection::_update_popup() {
- if (!menu) {
+ if (menu) {
+ menu->clear();
+ } else {
menu = memnew(PopupMenu);
add_child(menu);
menu->connect(SceneStringName(id_pressed), callable_mp(this, &EditorInspectorSection::menu_option));
+ }
- menu->add_icon_item(theme_cache.icon_copy, TTRC("Copy Section Values"), MENU_COPY_VALUE);
- menu->add_icon_item(theme_cache.icon_paste, TTRC("Paste Section Values"), MENU_PASTE_VALUE);
+ if (checkable) {
+ menu->add_icon_item(theme_cache.icon_copy, TTRC("Copy Value"), MENU_COPY_VALUE);
+ menu->add_icon_item(theme_cache.icon_paste, TTRC("Paste Value"), MENU_PASTE_VALUE);
+ menu->set_item_disabled(-1, EditorInspector::get_property_clipboard_type() != EditorInspector::PropertyClipboard::Type::PROPERTY);
+ menu->add_icon_item(theme_cache.icon_copy_path, TTRC("Copy Property Path"), MENU_COPY_PROPERTY_PATH);
+ menu->set_item_disabled(-1, related_enable_property.is_empty());
+ menu->add_separator();
+ }
+
+ menu->add_icon_item(theme_cache.icon_copy, TTRC("Copy Section Values"), MENU_COPY_SECTION);
+ menu->add_icon_item(theme_cache.icon_paste, TTRC("Paste Section Values"), MENU_PASTE_SECTION);
+ menu->set_item_disabled(-1, EditorInspector::get_property_clipboard_type() != EditorInspector::PropertyClipboard::Type::SECTION);
+
+ if (can_revert) {
+ menu->add_separator();
+ menu->add_icon_item(theme_cache.icon_gui_revert, TTRC("Revert Value"), MENU_REVERT_VALUE);
+ }
+ if (!doc_path.is_empty() && ScriptEditor::get_singleton() && EditorNode::get_singleton()) {
+ menu->add_separator();
+ menu->add_icon_item(theme_cache.help_icon, TTRC("Open Documentation"), MENU_OPEN_DOCUMENTATION);
}
- menu->set_item_disabled(MENU_PASTE_VALUE, EditorInspector::get_property_clipboard_type() != EditorInspector::PropertyClipboard::Type::SECTION);
}
-void EditorInspectorSection::menu_option(int p_option) const {
+void EditorInspectorSection::menu_option(int p_option) {
switch (p_option) {
case MENU_COPY_VALUE: {
+ EditorInspector::set_property_clipboard(EditorInspector::PropertyClipboard::Type::PROPERTY, object->get(related_enable_property));
+ } break;
+
+ case MENU_PASTE_VALUE: {
+ if (EditorInspector::get_property_clipboard_type() != EditorInspector::PropertyClipboard::Type::PROPERTY) {
+ return;
+ }
+
+ checked = EditorInspector::get_property_clipboard_value();
+ emit_signal(SNAME("section_toggled_by_user"), related_enable_property, checked);
+ if (checked) {
+ unfold();
+ } else if (!checkbox_only) {
+ vbox->hide();
+ }
+ } break;
+
+ case MENU_COPY_PROPERTY_PATH: {
+ DisplayServer::get_singleton()->clipboard_set(related_enable_property);
+ } break;
+
+ case MENU_COPY_SECTION: {
Dictionary clipboard;
for (const EditorProperty *property : section_properties) {
clipboard[property->get_edited_property()] = property->get_edited_property_value();
@@ -2810,7 +2856,7 @@ void EditorInspectorSection::menu_option(int p_option) const {
EditorInspector::set_property_clipboard(EditorInspector::PropertyClipboard::Type::SECTION, clipboard);
} break;
- case MENU_PASTE_VALUE: {
+ case MENU_PASTE_SECTION: {
if (EditorInspector::get_property_clipboard_type() != EditorInspector::PropertyClipboard::Type::SECTION) {
break;
}
@@ -2830,6 +2876,24 @@ void EditorInspectorSection::menu_option(int p_option) const {
}
ur->commit_action();
} break;
+
+ case MENU_REVERT_VALUE: {
+ bool is_valid_revert = false;
+ Variant revert_value = EditorPropertyRevert::get_property_revert_value(object, related_enable_property, &is_valid_revert);
+ ERR_FAIL_COND(!is_valid_revert);
+ checked = revert_value;
+ emit_signal(SNAME("section_toggled_by_user"), related_enable_property, revert_value);
+ if (checked) {
+ unfold();
+ } else if (!checkbox_only) {
+ vbox->hide();
+ }
+ } break;
+
+ case MENU_OPEN_DOCUMENTATION: {
+ ScriptEditor::get_singleton()->goto_help(doc_path);
+ EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
+ } break;
}
}
@@ -3887,6 +3951,8 @@ void EditorInspector::initialize_section_theme(EditorInspectorSection::ThemeCach
p_cache.icon_gui_animation_key = p_control->get_editor_theme_icon(SNAME("Key"));
p_cache.icon_copy = p_control->get_editor_theme_icon(SNAME("ActionCopy"));
p_cache.icon_paste = p_control->get_editor_theme_icon(SNAME("ActionPaste"));
+ p_cache.icon_copy_path = p_control->get_editor_theme_icon(SNAME("CopyNodePath"));
+ p_cache.help_icon = p_control->get_editor_theme_icon(SNAME("Help"));
p_cache.indent_box = p_control->get_theme_stylebox(SNAME("indent_box"), SNAME("EditorInspectorSection"));
p_cache.icon_hover = p_control->get_theme_stylebox(SceneStringName(hover), SceneStringName(FlatButton));
@@ -4848,6 +4914,7 @@ void EditorInspector::update_tree() {
}
if (use_doc_hints) {
+ last_created_section->set_doc_path(doc_path);
last_created_section->set_tooltip_text(doc_tooltip_text);
}
continue;
@@ -5053,9 +5120,11 @@ void EditorInspector::update_tree() {
Variant value_checked = object->get(corresponding_section->related_enable_property, &valid);
if (valid) {
section->section = corresponding_section->section;
+ section->label = corresponding_section->label;
section->set_checkable(corresponding_section->related_enable_property, corresponding_section->checkbox_only, value_checked.operator bool());
section->set_keying(keying);
if (use_doc_hints) {
+ section->set_doc_path(corresponding_section->doc_path);
section->set_tooltip_text(corresponding_section->get_tooltip_text());
}
@@ -5092,9 +5161,11 @@ void EditorInspector::update_tree() {
Variant value_checked = object->get(corresponding_section->related_enable_property, &valid);
if (valid) {
section->section = corresponding_section->section;
+ section->label = corresponding_section->label;
section->set_checkable(corresponding_section->related_enable_property, corresponding_section->checkbox_only, value_checked.operator bool());
section->set_keying(keying);
if (use_doc_hints) {
+ section->set_doc_path(corresponding_section->doc_path);
section->set_tooltip_text(corresponding_section->get_tooltip_text());
}
diff --git a/editor/inspector/editor_inspector.h b/editor/inspector/editor_inspector.h
index 9355d094319..88138fe39b7 100644
--- a/editor/inspector/editor_inspector.h
+++ b/editor/inspector/editor_inspector.h
@@ -454,6 +454,11 @@ class EditorInspectorSection : public Container {
enum MenuItems {
MENU_COPY_VALUE,
MENU_PASTE_VALUE,
+ MENU_COPY_PROPERTY_PATH,
+ MENU_COPY_SECTION,
+ MENU_PASTE_SECTION,
+ MENU_REVERT_VALUE,
+ MENU_OPEN_DOCUMENTATION,
};
String label;
@@ -481,6 +486,8 @@ class EditorInspectorSection : public Container {
bool checkbox_only = false;
+ String doc_path;
+
PopupMenu *menu = nullptr;
HashSet<StringName> revertable_properties;
@@ -527,6 +534,8 @@ class EditorInspectorSection : public Container {
Ref<Texture2D> icon_gui_animation_key;
Ref<Texture2D> icon_copy;
Ref<Texture2D> icon_paste;
+ Ref<Texture2D> icon_copy_path;
+ Ref<Texture2D> help_icon;
Ref<StyleBoxFlat> indent_box;
Ref<StyleBoxFlat> icon_hover;
@@ -558,6 +567,7 @@ public:
void set_checkable(const String &p_related_check_property, bool p_checkbox_only, bool p_checked);
inline bool is_checkable() const { return checkable; }
void set_checked(bool p_checked);
+ void set_doc_path(const String &p_doc_path);
void set_keying(bool p_keying);
bool has_revertable_properties() const;
@@ -566,7 +576,7 @@ public:
void update_property();
void _update_popup();
- void menu_option(int p_option) const;
+ void menu_option(int p_option);
void register_property(EditorProperty *p_property) { section_properties.push_back(p_property); }