Procházet zdrojové kódy

Merge pull request #59164 from timothyqiu/filter-property-3.x

Rémi Verschelde před 3 roky
rodič
revize
cdbc819b85
2 změnil soubory, kde provedl 35 přidání a 14 odebrání
  1. 20 13
      editor/editor_inspector.cpp
  2. 15 1
      editor/editor_sectioned_inspector.cpp

+ 20 - 13
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_ofi(EditorPropertyNameProcessor::get_singleton()->process_name(sections[i]))) {
+			return true;
+		}
+	}
+	return false;
+}
+
 Size2 EditorProperty::get_minimum_size() const {
 	Size2 ms;
 	Ref<Font> 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;
 			}
 		}

+ 15 - 1
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<String> 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;
 		}