[Bf-blender-cvs] [43b08d05786] blender-v2.93-release: RNA: add STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID flag

Campbell Barton noreply at git.blender.org
Fri Apr 16 07:10:14 CEST 2021


Commit: 43b08d05786f83797d04e5d0f777ae9b888807f9
Author: Campbell Barton
Date:   Fri Apr 16 15:04:37 2021 +1000
Branches: blender-v2.93-release
https://developer.blender.org/rB43b08d05786f83797d04e5d0f777ae9b888807f9

RNA: add STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID flag

This flag is needed so PointerRNA structs that aren't
part of the current context can access enum values
without inspecting the context.

This is needed for keymap access, so the keymap UI and keymap
export doesn't depend on the current context.

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

M	source/blender/makesrna/RNA_types.h
M	source/blender/makesrna/intern/rna_access.c

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

diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h
index 78192f937e6..6cd3678017e 100644
--- a/source/blender/makesrna/RNA_types.h
+++ b/source/blender/makesrna/RNA_types.h
@@ -636,6 +636,12 @@ typedef enum StructFlag {
   STRUCT_PUBLIC_NAMESPACE = (1 << 9),
   /** All subtypes are added too. */
   STRUCT_PUBLIC_NAMESPACE_INHERIT = (1 << 10),
+  /**
+   * When the #PointerRNA.owner_id is NULL, this signifies the property should be accessed
+   * without any context (the key-map UI and import/export for example).
+   * So accessing the property should not read from the current context to derive values/limits.
+   */
+  STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID = (1 << 11),
 } StructFlag;
 
 typedef int (*StructValidateFunc)(struct PointerRNA *ptr, void *data, int *have_function);
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index f94dc38ddfe..9b57096ec19 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -1623,35 +1623,35 @@ void RNA_property_enum_items_ex(bContext *C,
 
   *r_free = false;
 
-  if (!use_static && eprop->item_fn && (C != NULL || (prop->flag & PROP_ENUM_NO_CONTEXT))) {
-    const EnumPropertyItem *item;
+  if (!use_static && (eprop->item_fn != NULL)) {
+    const bool no_context = (prop->flag & PROP_ENUM_NO_CONTEXT) ||
+                            ((ptr->type->flag & STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID) &&
+                             (ptr->owner_id == NULL));
+    if (C != NULL || no_context) {
+      const EnumPropertyItem *item;
 
-    if (prop->flag & PROP_ENUM_NO_CONTEXT) {
-      item = eprop->item_fn(NULL, ptr, prop, r_free);
-    }
-    else {
-      item = eprop->item_fn(C, ptr, prop, r_free);
-    }
+      item = eprop->item_fn(no_context ? NULL : C, ptr, prop, r_free);
 
-    /* any callbacks returning NULL should be fixed */
-    BLI_assert(item != NULL);
+      /* any callbacks returning NULL should be fixed */
+      BLI_assert(item != NULL);
 
-    if (r_totitem) {
-      int tot;
-      for (tot = 0; item[tot].identifier; tot++) {
-        /* pass */
+      if (r_totitem) {
+        int tot;
+        for (tot = 0; item[tot].identifier; tot++) {
+          /* pass */
+        }
+        *r_totitem = tot;
       }
-      *r_totitem = tot;
-    }
 
-    *r_item = item;
-  }
-  else {
-    *r_item = eprop->item;
-    if (r_totitem) {
-      *r_totitem = eprop->totitem;
+      *r_item = item;
+      return;
     }
   }
+
+  *r_item = eprop->item;
+  if (r_totitem) {
+    *r_totitem = eprop->totitem;
+  }
 }
 
 void RNA_property_enum_items(bContext *C,
@@ -1753,42 +1753,42 @@ void RNA_property_enum_items_gettexted_all(bContext *C,
     *r_totitem = eprop->totitem;
   }
 
-  if (eprop->item_fn && (C != NULL || (prop->flag & PROP_ENUM_NO_CONTEXT))) {
-    const EnumPropertyItem *item;
-    int i;
-    bool free = false;
+  if (eprop->item_fn != NULL) {
+    const bool no_context = (prop->flag & PROP_ENUM_NO_CONTEXT) ||
+                            ((ptr->type->flag & STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID) &&
+                             (ptr->owner_id == NULL));
+    if (C != NULL || no_context) {
+      const EnumPropertyItem *item;
+      int i;
+      bool free = false;
 
-    if (prop->flag & PROP_ENUM_NO_CONTEXT) {
-      item = eprop->item_fn(NULL, ptr, prop, &free);
-    }
-    else {
-      item = eprop->item_fn(C, ptr, prop, &free);
-    }
+      item = eprop->item_fn(no_context ? NULL : NULL, ptr, prop, &free);
 
-    /* any callbacks returning NULL should be fixed */
-    BLI_assert(item != NULL);
+      /* any callbacks returning NULL should be fixed */
+      BLI_assert(item != NULL);
 
-    for (i = 0; i < eprop->totitem; i++) {
-      bool exists = false;
-      int i_fixed;
+      for (i = 0; i < eprop->totitem; i++) {
+        bool exists = false;
+        int i_fixed;
 
-      /* Items that do not exist on list are returned,
-       * but have their names/identifiers NULL'ed out. */
-      for (i_fixed = 0; item[i_fixed].identifier; i_fixed++) {
-        if (STREQ(item[i_fixed].identifier, item_array[i].identifier)) {
-          exists = true;
-          break;
+        /* Items that do not exist on list are returned,
+         * but have their names/identifiers NULL'ed out. */
+        for (i_fixed = 0; item[i_fixed].identifier; i_fixed++) {
+          if (STREQ(item[i_fixed].identifier, item_array[i].identifier)) {
+            exists = true;
+            break;
+          }
         }
-      }
 
-      if (!exists) {
-        item_array[i].name = NULL;
-        item_array[i].identifier = "";
+        if (!exists) {
+          item_array[i].name = NULL;
+          item_array[i].identifier = "";
+        }
       }
-    }
 
-    if (free) {
-      MEM_freeN((void *)item);
+      if (free) {
+        MEM_freeN((void *)item);
+      }
     }
   }



More information about the Bf-blender-cvs mailing list