From 7e0d8146034f4766340b69d164ab70b1c62ae521 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Fri, 18 Mar 2022 01:15:31 +0800 Subject: [PATCH] Improve inspector filtering --- editor/editor_inspector.cpp | 33 ++++++++++++++++----------- editor/editor_sectioned_inspector.cpp | 16 ++++++++++++- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 21b20e67ece..10af09a00c7 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -43,6 +43,20 @@ #include "scene/property_utils.h" #include "scene/resources/packed_scene.h" +static bool _property_path_matches(const String &p_property_path, const String &p_filter) { + if (p_property_path.findn(p_filter) != -1) { + return true; + } + + const Vector sections = p_property_path.split("/"); + for (int i = 0; i < sections.size(); i++) { + if (p_filter.is_subsequence_ofi(EditorPropertyNameProcessor::get_singleton()->process_name(sections[i]))) { + return true; + } + } + return false; +} + Size2 EditorProperty::get_minimum_size() const { Size2 ms; Ref font = get_font("font", "Tree"); @@ -1547,15 +1561,13 @@ void EditorInspector::update_tree() { } String name = (basename.find("/") != -1) ? basename.right(basename.rfind("/") + 1) : basename; + String name_override = name; if (capitalize_paths) { int dot = name.find("."); if (dot != -1) { - String ov = name.right(dot); - name = name.substr(0, dot); - name = EditorPropertyNameProcessor::get_singleton()->process_name(name); - name += ov; - + name_override = name.substr(0, dot); + name = EditorPropertyNameProcessor::get_singleton()->process_name(name_override) + name.right(dot); } else { name = EditorPropertyNameProcessor::get_singleton()->process_name(name); } @@ -1563,14 +1575,9 @@ void EditorInspector::update_tree() { String path = basename.left(basename.rfind("/")); - if (use_filter && filter != "") { - String cat = path; - - if (capitalize_paths) { - cat = EditorPropertyNameProcessor::get_singleton()->process_name(cat); - } - - if (!filter.is_subsequence_ofi(cat) && !filter.is_subsequence_ofi(name) && property_prefix.to_lower().find(filter.to_lower()) == -1) { + if (use_filter && !filter.empty()) { + const String property_path = property_prefix + (path.empty() ? "" : path + "/") + name_override; + if (!_property_path_matches(property_path, filter)) { continue; } } diff --git a/editor/editor_sectioned_inspector.cpp b/editor/editor_sectioned_inspector.cpp index 7a211bc331e..b344c89878d 100644 --- a/editor/editor_sectioned_inspector.cpp +++ b/editor/editor_sectioned_inspector.cpp @@ -33,6 +33,20 @@ #include "editor_property_name_processor.h" #include "editor_scale.h" +static bool _property_path_matches(const String &p_property_path, const String &p_filter) { + if (p_property_path.findn(p_filter) != -1) { + return true; + } + + const Vector sections = p_property_path.split("/"); + for (int i = 0; i < sections.size(); i++) { + if (p_filter.is_subsequence_ofi(EditorPropertyNameProcessor::get_singleton()->process_name(sections[i]))) { + return true; + } + } + return false; +} + class SectionedInspectorFilter : public Object { GDCLASS(SectionedInspectorFilter, Object); @@ -242,7 +256,7 @@ void SectionedInspector::update_category_list() { continue; } - if (!filter.empty() && pi.name.findn(filter) == -1 && pi.name.replace("/", " ").capitalize().findn(filter) == -1) { + if (!filter.empty() && !_property_path_matches(pi.name, filter)) { continue; }