Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2022-05-23 22:01:11 +0300
committerJulian Eisel <julian@blender.org>2022-05-23 22:08:01 +0300
commitb2e5fc72c8c60ca03d2c82b44a0c8ca21ecae194 (patch)
tree3a15f31c1b68526ffa79dc53403c1f27f7508d56 /source/blender/windowmanager
parent9039fbaa9ce171d40a75cc7fb56b2e3f004334bb (diff)
parent8f79fa9c6780dd5526dccce039c49bc7f69f47df (diff)
Merge branch 'blender-v3.2-release'
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_api.h30
-rw-r--r--source/blender/windowmanager/intern/wm_operator_props.c67
2 files changed, 97 insertions, 0 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 59d40ce840f..a29559e904e 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -770,6 +770,36 @@ void WM_operator_properties_filesel(struct wmOperatorType *ot,
eFileSel_Flag flag,
short display,
short sort);
+
+/**
+ * Tries to pass \a id to an operator via either a "session_uuid" or a "name" property defined in
+ * the properties of \a ptr. The former is preferred, since it works properly with linking and
+ * library overrides (which may both result in multiple IDs with the same name and type).
+ *
+ * Also see #WM_operator_properties_id_lookup() and
+ * #WM_operator_properties_id_lookup_from_name_or_session_uuid()
+ */
+void WM_operator_properties_id_lookup_set_from_id(PointerRNA *ptr, const ID *id);
+/**
+ * Tries to find an ID in \a bmain. There needs to be either a "name" string or "session_uuid" int
+ * property defined and set. The former has priority. See #WM_operator_properties_id_lookup() for a
+ * helper to add the properties.
+ */
+struct ID *WM_operator_properties_id_lookup_from_name_or_session_uuid(struct Main *bmain,
+ const struct wmOperator *op,
+ enum ID_Type type);
+/**
+ * Adds "name" and "session_uuid" properties so the caller can tell the operator which ID to act
+ * on. See #WM_operator_properties_id_lookup_from_name_or_session_uuid(). Both properties will be
+ * hidden in the UI and not be saved over consecutive operator calls.
+ *
+ * \note New operators should probably use "session_uuid" only (set \a add_name_prop to #false),
+ * since this works properly with linked data and/or library overrides (in both cases, multiple IDs
+ * with the same name and type may be present). The "name" property is only kept to not break
+ * compatibility with old scripts using some previously existing operators.
+ */
+void WM_operator_properties_id_lookup(wmOperatorType *ot, const bool add_name_prop);
+
/**
* Disable using cursor position,
* use when view operators are initialized from buttons.
diff --git a/source/blender/windowmanager/intern/wm_operator_props.c b/source/blender/windowmanager/intern/wm_operator_props.c
index 6e44246f3ef..55544e9906d 100644
--- a/source/blender/windowmanager/intern/wm_operator_props.c
+++ b/source/blender/windowmanager/intern/wm_operator_props.c
@@ -8,8 +8,12 @@
* (`WM_operator_properties_*` functions).
*/
+#include "DNA_ID_enums.h"
#include "DNA_space_types.h"
+#include "BKE_lib_id.h"
+#include "BKE_main.h"
+
#include "BLI_math_base.h"
#include "BLI_rect.h"
@@ -222,6 +226,69 @@ void WM_operator_properties_filesel(wmOperatorType *ot,
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
+void WM_operator_properties_id_lookup_set_from_id(PointerRNA *ptr, const ID *id)
+{
+ PropertyRNA *prop_session_uuid = RNA_struct_find_property(ptr, "session_uuid");
+ PropertyRNA *prop_name = RNA_struct_find_property(ptr, "name");
+
+ if (prop_session_uuid) {
+ RNA_int_set(ptr, "session_uuid", (int)id->session_uuid);
+ }
+ else if (prop_name) {
+ RNA_string_set(ptr, "name", id->name + 2);
+ }
+ else {
+ BLI_assert_unreachable();
+ }
+}
+
+ID *WM_operator_properties_id_lookup_from_name_or_session_uuid(Main *bmain,
+ const wmOperator *op,
+ const ID_Type type)
+{
+ PropertyRNA *prop_name = RNA_struct_find_property(op->ptr, "name");
+ PropertyRNA *prop_session_uuid = RNA_struct_find_property(op->ptr, "session_uuid");
+
+ if (prop_name && RNA_property_is_set(op->ptr, prop_name)) {
+ char name[MAX_ID_NAME - 2];
+ RNA_property_string_get(op->ptr, prop_name, name);
+ return BKE_libblock_find_name(bmain, type, name);
+ }
+
+ if (prop_session_uuid && RNA_property_is_set(op->ptr, prop_session_uuid)) {
+ const uint32_t session_uuid = (uint32_t)RNA_property_int_get(op->ptr, prop_session_uuid);
+ return BKE_libblock_find_session_uuid(bmain, type, session_uuid);
+ }
+
+ return NULL;
+}
+
+void WM_operator_properties_id_lookup(wmOperatorType *ot, const bool add_name_prop)
+{
+ PropertyRNA *prop;
+
+ if (add_name_prop) {
+ prop = RNA_def_string(ot->srna,
+ "name",
+ NULL,
+ MAX_ID_NAME - 2,
+ "Name",
+ "Name of the data-block to use by the operator");
+ RNA_def_property_flag(prop, (PropertyFlag)(PROP_SKIP_SAVE | PROP_HIDDEN));
+ }
+
+ prop = RNA_def_int(ot->srna,
+ "session_uuid",
+ 0,
+ INT32_MIN,
+ INT32_MAX,
+ "Session UUID",
+ "Session UUID of the data-block to use by the operator",
+ INT32_MIN,
+ INT32_MAX);
+ RNA_def_property_flag(prop, (PropertyFlag)(PROP_SKIP_SAVE | PROP_HIDDEN));
+}
+
static void wm_operator_properties_select_action_ex(wmOperatorType *ot,
int default_action,
const EnumPropertyItem *select_actions,