From d644b9b640e905555e7e59fcc85eeb0b786141b6 Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Fri, 26 Jan 2024 20:42:20 +0100 Subject: [PATCH] Better hide internal properties from users --- editor/editor_help.cpp | 10 +++++++++- editor/editor_inspector.cpp | 18 +++++++++++++++--- editor/editor_inspector.h | 2 ++ modules/gdscript/gdscript_editor.cpp | 12 +++++++++--- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index f0f7f877111..5557c409047 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -2862,9 +2862,17 @@ void EditorHelpTooltip::parse_tooltip(const String &p_text) { const String &property_name = slices[2]; const String &property_args = slices[3]; + String formatted_text; + + // Exclude internal properties, they are not documented. + if (type == "internal_property") { + formatted_text = "[i]" + TTR("This property can only be set in the Inspector.") + "[/i]"; + set_text(formatted_text); + return; + } + String title; String description; - String formatted_text; if (type == "class") { title = class_name; diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index a3530fc9abd..bfadc48b33d 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -436,6 +436,10 @@ void EditorProperty::set_doc_path(const String &p_doc_path) { doc_path = p_doc_path; } +void EditorProperty::set_internal(bool p_internal) { + internal = p_internal; +} + void EditorProperty::update_property() { GDVIRTUAL_CALL(_update_property); } @@ -748,10 +752,10 @@ void EditorProperty::shortcut_input(const Ref &p_event) { if (ED_IS_SHORTCUT("property_editor/copy_value", p_event)) { menu_option(MENU_COPY_VALUE); accept_event(); - } else if (ED_IS_SHORTCUT("property_editor/paste_value", p_event) && !is_read_only()) { + } else if (!is_read_only() && ED_IS_SHORTCUT("property_editor/paste_value", p_event)) { menu_option(MENU_PASTE_VALUE); accept_event(); - } else if (ED_IS_SHORTCUT("property_editor/copy_property_path", p_event)) { + } else if (!internal && ED_IS_SHORTCUT("property_editor/copy_property_path", p_event)) { menu_option(MENU_COPY_PROPERTY_PATH); accept_event(); } @@ -1036,6 +1040,8 @@ void EditorProperty::_update_popup() { menu->add_icon_shortcut(get_editor_theme_icon(SNAME("ActionPaste")), ED_GET_SHORTCUT("property_editor/paste_value"), MENU_PASTE_VALUE); menu->add_icon_shortcut(get_editor_theme_icon(SNAME("CopyNodePath")), ED_GET_SHORTCUT("property_editor/copy_property_path"), MENU_COPY_PROPERTY_PATH); menu->set_item_disabled(MENU_PASTE_VALUE, is_read_only()); + menu->set_item_disabled(MENU_COPY_PROPERTY_PATH, internal); + if (!pin_hidden) { menu->add_separator(); if (can_pin) { @@ -3329,7 +3335,11 @@ void EditorInspector::update_tree() { if (use_doc_hints) { // `|` separator used in `EditorHelpTooltip` for formatting. if (theme_item_name.is_empty()) { - ep->set_tooltip_text("property|" + classname + "|" + property_prefix + p.name + "|"); + if (p.usage & PROPERTY_USAGE_INTERNAL) { + ep->set_tooltip_text("internal_property|" + classname + "|" + property_prefix + p.name + "|"); + } else { + ep->set_tooltip_text("property|" + classname + "|" + property_prefix + p.name + "|"); + } } else { ep->set_tooltip_text("theme_item|" + classname + "|" + theme_item_name + "|"); } @@ -3337,6 +3347,8 @@ void EditorInspector::update_tree() { } ep->set_doc_path(doc_path); + ep->set_internal(p.usage & PROPERTY_USAGE_INTERNAL); + ep->update_property(); ep->_update_pin_flags(); ep->update_editor_property_status(); diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index e36606c0805..2dcad88840f 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -74,6 +74,7 @@ private: StringName property; String property_path; String doc_path; + bool internal = false; bool has_doc_tooltip = false; int property_usage; @@ -156,6 +157,7 @@ public: EditorInspector *get_parent_inspector() const; void set_doc_path(const String &p_doc_path); + void set_internal(bool p_internal); virtual void update_property(); void update_editor_property_status(); diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index d921a73b9a5..44e104da05f 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -1135,7 +1135,7 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base List members; scr->get_script_property_list(&members); for (const PropertyInfo &E : members) { - if (E.usage & (PROPERTY_USAGE_CATEGORY | PROPERTY_USAGE_GROUP | PROPERTY_USAGE_SUBGROUP)) { + if (E.usage & (PROPERTY_USAGE_CATEGORY | PROPERTY_USAGE_GROUP | PROPERTY_USAGE_SUBGROUP | PROPERTY_USAGE_INTERNAL)) { continue; } if (E.name.contains("/")) { @@ -1210,7 +1210,7 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base List pinfo; ClassDB::get_property_list(type, &pinfo); for (const PropertyInfo &E : pinfo) { - if (E.usage & (PROPERTY_USAGE_CATEGORY | PROPERTY_USAGE_GROUP | PROPERTY_USAGE_SUBGROUP)) { + if (E.usage & (PROPERTY_USAGE_CATEGORY | PROPERTY_USAGE_GROUP | PROPERTY_USAGE_SUBGROUP | PROPERTY_USAGE_INTERNAL)) { continue; } if (E.name.contains("/")) { @@ -1273,7 +1273,7 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base } for (const PropertyInfo &E : members) { - if (E.usage & (PROPERTY_USAGE_CATEGORY | PROPERTY_USAGE_GROUP | PROPERTY_USAGE_SUBGROUP)) { + if (E.usage & (PROPERTY_USAGE_CATEGORY | PROPERTY_USAGE_GROUP | PROPERTY_USAGE_SUBGROUP | PROPERTY_USAGE_INTERNAL)) { continue; } if (!String(E.name).contains("/")) { @@ -3514,6 +3514,12 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co } if (ClassDB::has_property(class_name, p_symbol, true)) { + PropertyInfo prop_info; + ClassDB::get_property_info(class_name, p_symbol, &prop_info, true); + if (prop_info.usage & PROPERTY_USAGE_INTERNAL) { + return ERR_CANT_RESOLVE; + } + r_result.type = ScriptLanguage::LOOKUP_RESULT_CLASS_PROPERTY; r_result.class_name = base_type.native_type; r_result.class_member = p_symbol;