[Bf-blender-cvs] [169ac2805e4] property-search-ui: Property Search: Add search filter active tabs property

Hans Goudey noreply at git.blender.org
Thu Jul 9 14:49:50 CEST 2020


Commit: 169ac2805e47b3e1dfcfdd58fe1cfb20cf43fbaf
Author: Hans Goudey
Date:   Thu Jul 9 08:45:54 2020 -0400
Branches: property-search-ui
https://developer.blender.org/rB169ac2805e47b3e1dfcfdd58fe1cfb20cf43fbaf

Property Search: Add search filter active tabs property

I also generalized the tab "adding" code in RNA to make it usable for filling
both the context enum and the active search filter tabs properties. The tab
layout code might need to be extended to add the idea of a custom
highlight property.

===================================================================

M	release/scripts/startup/bl_ui/space_properties.py
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_properties.py b/release/scripts/startup/bl_ui/space_properties.py
index 673f0fae7e0..311892cab15 100644
--- a/release/scripts/startup/bl_ui/space_properties.py
+++ b/release/scripts/startup/bl_ui/space_properties.py
@@ -52,7 +52,10 @@ class PROPERTIES_PT_navigation_bar(Panel):
 
         layout.scale_x = 1.4
         layout.scale_y = 1.4
-        layout.prop_tabs_enum(view, "context", icon_only=True)
+        if (view.filter_text):
+            layout.prop_tabs_enum(view, "context_search_filter_active", icon_only=True)
+        else:
+            layout.prop_tabs_enum(view, "context", icon_only=True)
 
 
 classes = (
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 30b2dd3463f..c265eedab2b 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -148,9 +148,10 @@ typedef struct SpaceProperties {
 
   /** Context tabs. */
   short mainb, mainbo, mainbuser;
+  int context_search_filter_active;
   /** Preview is signal to refresh. */
   short preview;
-  char _pad[5];
+  char _pad[1];
   char flag;
 
   /** Runtime. */
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 691be0bdcde..712c9884c2e 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -1769,94 +1769,122 @@ static void rna_SpaceProperties_context_set(PointerRNA *ptr, int value)
   sbuts->mainbuser = value;
 }
 
-static const EnumPropertyItem *rna_SpaceProperties_context_itemf(bContext *UNUSED(C),
-                                                                 PointerRNA *ptr,
-                                                                 PropertyRNA *UNUSED(prop),
-                                                                 bool *r_free)
+/**
+ * Fills an array with the context items for the properties editor. -1 signals a separator.
+ *
+ * \return The total number of items in the array returned.
+ */
+static int rna_SpaceProperties_context_tabs(SpaceProperties *sbuts, int *context_tabs_array)
 {
-  SpaceProperties *sbuts = (SpaceProperties *)(ptr->data);
-  EnumPropertyItem *item = NULL;
-  int totitem = 0;
-
+  int length = 0;
   if (sbuts->pathflag & (1 << BCONTEXT_TOOL)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_TOOL);
+    context_tabs_array[length] = BCONTEXT_TOOL;
+    length++;
   }
-
-  if (totitem) {
-    RNA_enum_item_add_separator(&item, &totitem);
+  if (length != 0) {
+    context_tabs_array[length] = -1;
+    length++;
   }
-
   if (sbuts->pathflag & (1 << BCONTEXT_RENDER)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_RENDER);
+    context_tabs_array[length] = BCONTEXT_RENDER;
+    length++;
   }
-
   if (sbuts->pathflag & (1 << BCONTEXT_OUTPUT)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_OUTPUT);
+    context_tabs_array[length] = BCONTEXT_OUTPUT;
+    length++;
   }
-
   if (sbuts->pathflag & (1 << BCONTEXT_VIEW_LAYER)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_VIEW_LAYER);
+    context_tabs_array[length] = BCONTEXT_VIEW_LAYER;
+    length++;
   }
-
   if (sbuts->pathflag & (1 << BCONTEXT_SCENE)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_SCENE);
+    context_tabs_array[length] = BCONTEXT_SCENE;
+    length++;
   }
-
   if (sbuts->pathflag & (1 << BCONTEXT_WORLD)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_WORLD);
+    context_tabs_array[length] = BCONTEXT_WORLD;
+    length++;
   }
-
-  if (totitem) {
-    RNA_enum_item_add_separator(&item, &totitem);
+  if (length != 0) {
+    context_tabs_array[length] = -1;
+    length++;
   }
-
   if (sbuts->pathflag & (1 << BCONTEXT_OBJECT)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_OBJECT);
+    context_tabs_array[length] = BCONTEXT_OBJECT;
+    length++;
   }
-
   if (sbuts->pathflag & (1 << BCONTEXT_MODIFIER)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_MODIFIER);
+    context_tabs_array[length] = BCONTEXT_MODIFIER;
+    length++;
   }
-
   if (sbuts->pathflag & (1 << BCONTEXT_SHADERFX)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_SHADERFX);
+    context_tabs_array[length] = BCONTEXT_SHADERFX;
+    length++;
   }
-
   if (sbuts->pathflag & (1 << BCONTEXT_PARTICLE)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_PARTICLE);
+    context_tabs_array[length] = BCONTEXT_PARTICLE;
+    length++;
   }
-
   if (sbuts->pathflag & (1 << BCONTEXT_PHYSICS)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_PHYSICS);
+    context_tabs_array[length] = BCONTEXT_PHYSICS;
+    length++;
   }
-
   if (sbuts->pathflag & (1 << BCONTEXT_CONSTRAINT)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_CONSTRAINT);
+    context_tabs_array[length] = BCONTEXT_CONSTRAINT;
+    length++;
   }
-
   if (sbuts->pathflag & (1 << BCONTEXT_DATA)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_DATA);
-    (item + totitem - 1)->icon = sbuts->dataicon;
+    context_tabs_array[length] = BCONTEXT_DATA;
+    length++;
   }
-
   if (sbuts->pathflag & (1 << BCONTEXT_BONE)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_BONE);
+    context_tabs_array[length] = BCONTEXT_BONE;
+    length++;
   }
-
   if (sbuts->pathflag & (1 << BCONTEXT_BONE_CONSTRAINT)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_BONE_CONSTRAINT);
+    context_tabs_array[length] = BCONTEXT_BONE_CONSTRAINT;
+    length++;
   }
-
   if (sbuts->pathflag & (1 << BCONTEXT_MATERIAL)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_MATERIAL);
+    context_tabs_array[length] = BCONTEXT_MATERIAL;
+    length++;
   }
-
-  if (totitem) {
-    RNA_enum_item_add_separator(&item, &totitem);
+  if (length != 0) {
+    context_tabs_array[length] = -1;
+    length++;
   }
-
   if (sbuts->pathflag & (1 << BCONTEXT_TEXTURE)) {
-    RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_TEXTURE);
+    context_tabs_array[length] = BCONTEXT_TEXTURE;
+    length++;
+  }
+
+  return length;
+}
+
+static const EnumPropertyItem *rna_SpaceProperties_context_itemf(bContext *UNUSED(C),
+                                                                 PointerRNA *ptr,
+                                                                 PropertyRNA *UNUSED(prop),
+                                                                 bool *r_free)
+{
+  SpaceProperties *sbuts = (SpaceProperties *)(ptr->data);
+  EnumPropertyItem *item = NULL;
+
+  int context_tabs_array[32];
+  int totitem = rna_SpaceProperties_context_tabs(sbuts, context_tabs_array);
+  int totitem_added = 0;
+  for (int i = 0; i < totitem; i++) {
+    if (context_tabs_array[i] == -1) {
+      RNA_enum_item_add_separator(&item, &totitem_added);
+    }
+    else {
+      RNA_enum_items_add_value(
+          &item, &totitem_added, buttons_context_items, context_tabs_array[i]);
+
+      /* Add the object data icon dynamically for the data tab. */
+      if (context_tabs_array[i] == BCONTEXT_DATA) {
+        (item + totitem_added - 1)->icon = sbuts->dataicon;
+      }
+    }
   }
 
   RNA_enum_item_end(&item, &totitem);
@@ -1865,6 +1893,27 @@ static const EnumPropertyItem *rna_SpaceProperties_context_itemf(bContext *UNUSE
   return item;
 }
 
+static const int rna_SpaceProperties_context_search_filter_active_get(PointerRNA *ptr)
+{
+  SpaceProperties *sbuts = (SpaceProperties *)(ptr->data);
+
+  int context_tabs_array[32];
+  int totitem = rna_SpaceProperties_context_tabs(sbuts, context_tabs_array);
+
+  int retval = 0;
+  for (int i = 0; i < totitem; i++) {
+    if (context_tabs_array[i] == -1) {
+      continue;
+    }
+    int tab_context = context_tabs_array[i];
+    if (sbuts->context_search_filter_active & (1 << tab_context)) {
+      retval |= (1 << i);
+    }
+  }
+
+  return retval;
+}
+
 static void rna_SpaceProperties_context_update(Main *UNUSED(bmain),
                                                Scene *UNUSED(scene),
                                                PointerRNA *ptr)
@@ -4514,6 +4563,17 @@ static void rna_def_space_properties(BlenderRNA *brna)
   RNA_def_property_update(
       prop, NC_SPACE | ND_SPACE_PROPERTIES, "rna_SpaceProperties_context_update");
 
+  prop = RNA_def_property(srna, "context_search_filter_active", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, buttons_context_items);
+  RNA_def_property_flag(prop, PROP_ENUM_FLAG);
+  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+  RNA_def_property_enum_funcs(prop,
+                              "rna_SpaceProperties_context_search_filter_active_get",
+                              NULL,
+                              "rna_SpaceProperties_context_itemf");
+  RNA_def_property_update(
+      prop, NC_SPACE | ND_SPACE_PROPERTIES, "rna_SpaceProperties_context_update");
+
   /* pinned data */
   prop = RNA_def_property(srna, "pin_id", PROP_POINTER, PROP_NONE);
   RNA_def_property_pointer_sdna(prop, NULL, "pinid");



More information about the Bf-blender-cvs mailing list