summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaoyu Qiu <timothyqiu32@gmail.com>2022-03-18 01:16:25 +0800
committerHaoyu Qiu <timothyqiu32@gmail.com>2022-03-18 01:16:25 +0800
commit7bdca99d51ec5a28a67ceeb2e509826191aa6326 (patch)
tree22e9955c40c35fedde79ad098e6af8a047fbab2f
parent5d806b435bdfb6669435f1a28589f847be5ff807 (diff)
Improve inspector filtering
-rw-r--r--editor/editor_inspector.cpp26
-rw-r--r--editor/editor_sectioned_inspector.cpp16
-rw-r--r--editor/project_settings_editor.cpp1
3 files changed, 36 insertions, 7 deletions
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index 9efd942a51..9601eaf5f5 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<String> sections = p_property_path.split("/");
+ for (int i = 0; i < sections.size(); i++) {
+ if (p_filter.is_subsequence_ofn(EditorPropertyNameProcessor::get_singleton()->process_name(sections[i]))) {
+ return true;
+ }
+ }
+ return false;
+}
+
Size2 EditorProperty::get_minimum_size() const {
Size2 ms;
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Tree"));
@@ -2657,15 +2671,14 @@ void EditorInspector::update_tree() {
}
// Get the property label's string.
- String property_label_string = (path.contains("/")) ? path.substr(path.rfind("/") + 1) : path;
+ String name_override = (path.contains("/")) ? path.substr(path.rfind("/") + 1) : path;
+ String property_label_string = name_override;
if (capitalize_paths) {
// Capitalize paths.
int dot = property_label_string.find(".");
if (dot != -1) {
- String ov = property_label_string.substr(dot);
- property_label_string = property_label_string.substr(0, dot);
- property_label_string = EditorPropertyNameProcessor::get_singleton()->process_name(property_label_string);
- property_label_string += ov;
+ name_override = name_override.substr(0, dot);
+ property_label_string = EditorPropertyNameProcessor::get_singleton()->process_name(name_override) + property_label_string.substr(dot);
} else {
property_label_string = EditorPropertyNameProcessor::get_singleton()->process_name(property_label_string);
}
@@ -2681,7 +2694,8 @@ void EditorInspector::update_tree() {
// Ignore properties that do not fit the filter.
if (use_filter && !filter.is_empty()) {
- if (!filter.is_subsequence_ofn(path) && !filter.is_subsequence_ofn(property_label_string) && !property_prefix.to_lower().contains(filter.to_lower())) {
+ const String property_path = property_prefix + (path.is_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 a44cf20771..627fa0eb35 100644
--- a/editor/editor_sectioned_inspector.cpp
+++ b/editor/editor_sectioned_inspector.cpp
@@ -33,6 +33,20 @@
#include "editor/editor_property_name_processor.h"
#include "editor/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<String> sections = p_property_path.split("/");
+ for (int i = 0; i < sections.size(); i++) {
+ if (p_filter.is_subsequence_ofn(EditorPropertyNameProcessor::get_singleton()->process_name(sections[i]))) {
+ return true;
+ }
+ }
+ return false;
+}
+
class SectionedInspectorFilter : public Object {
GDCLASS(SectionedInspectorFilter, Object);
@@ -232,7 +246,7 @@ void SectionedInspector::update_category_list() {
continue;
}
- if (!filter.is_empty() && pi.name.findn(filter) == -1 && pi.name.replace("/", " ").capitalize().findn(filter) == -1) {
+ if (!filter.is_empty() && !_property_path_matches(pi.name, filter)) {
continue;
}
diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp
index c4019bc22d..98f8aefea0 100644
--- a/editor/project_settings_editor.cpp
+++ b/editor/project_settings_editor.cpp
@@ -617,6 +617,7 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) {
general_settings_inspector->get_inspector()->set_undo_redo(EditorNode::get_singleton()->get_undo_redo());
general_settings_inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
general_settings_inspector->register_search_box(search_box);
+ general_settings_inspector->get_inspector()->set_use_filter(true);
general_settings_inspector->get_inspector()->connect("property_selected", callable_mp(this, &ProjectSettingsEditor::_setting_selected));
general_settings_inspector->get_inspector()->connect("property_edited", callable_mp(this, &ProjectSettingsEditor::_setting_edited));
general_settings_inspector->get_inspector()->connect("restart_requested", callable_mp(this, &ProjectSettingsEditor::_editor_restart_request));