[Bf-blender-cvs] [81bf9a41e1d] blender2.8: Tool System: Utility to set the tool by name

Campbell Barton noreply at git.blender.org
Thu May 31 09:07:21 CEST 2018


Commit: 81bf9a41e1d769a52b58836f20f2252f214b927d
Author: Campbell Barton
Date:   Thu May 31 09:02:43 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB81bf9a41e1d769a52b58836f20f2252f214b927d

Tool System: Utility to set the tool by name

Wrapper for the Python operator.

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

M	source/blender/windowmanager/WM_toolsystem.h
M	source/blender/windowmanager/intern/wm_toolsystem.c

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

diff --git a/source/blender/windowmanager/WM_toolsystem.h b/source/blender/windowmanager/WM_toolsystem.h
index 2eb07d68afa..30470e17ed4 100644
--- a/source/blender/windowmanager/WM_toolsystem.h
+++ b/source/blender/windowmanager/WM_toolsystem.h
@@ -51,6 +51,9 @@ struct bToolRef *WM_toolsystem_ref_find(struct WorkSpace *workspace, const bTool
 bool WM_toolsystem_ref_ensure(
         struct WorkSpace *workspace, const bToolKey *tkey,
         struct bToolRef **r_tref);
+struct bToolRef *WM_toolsystem_ref_set_by_name(
+        bContext *C, struct WorkSpace *workspace, const bToolKey *tkey,
+        const char *name, bool cycle);
 
 struct bToolRef_Runtime *WM_toolsystem_runtime_from_context(struct bContext *C);
 struct bToolRef_Runtime *WM_toolsystem_runtime_find(struct WorkSpace *workspace, const bToolKey *tkey);
diff --git a/source/blender/windowmanager/intern/wm_toolsystem.c b/source/blender/windowmanager/intern/wm_toolsystem.c
index d734fee05ae..0ea933a852b 100644
--- a/source/blender/windowmanager/intern/wm_toolsystem.c
+++ b/source/blender/windowmanager/intern/wm_toolsystem.c
@@ -461,23 +461,52 @@ static void toolsystem_refresh_screen_from_active_tool(
 	}
 }
 
-static void toolsystem_reinit_with_toolref(
-        bContext *C, WorkSpace *workspace, bToolRef *tref)
+bToolRef *WM_toolsystem_ref_set_by_name(
+        bContext *C, WorkSpace *workspace, const bToolKey *tkey,
+        const char *name, bool cycle)
 {
 	wmOperatorType *ot = WM_operatortype_find("WM_OT_tool_set_by_name", false);
 	/* On startup, Python operatores are not yet loaded. */
 	if (ot == NULL) {
-		return;
+		return NULL;
 	}
 	PointerRNA op_props;
 	WM_operator_properties_create_ptr(&op_props, ot);
-	RNA_string_set(&op_props, "name", tref->idname);
-	RNA_enum_set(&op_props, "space_type", tref->space_type);
+	RNA_string_set(&op_props, "name", name);
+
+	/* Will get from context if not set. */
+	bToolKey tkey_from_context;
+	if (tkey == NULL) {
+		Scene *scene = CTX_data_scene(C);
+		ScrArea *sa = CTX_wm_area(C);
+		WM_toolsystem_key_from_context(workspace, scene, sa, &tkey_from_context);
+		tkey = &tkey_from_context;
+	}
+
+	RNA_enum_set(&op_props, "space_type", tkey->space_type);
+	RNA_boolean_set(&op_props, "cycle", cycle);
+
 	WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &op_props);
 	WM_operator_properties_free(&op_props);
 
-	Main *bmain = CTX_data_main(C);
-	toolsystem_refresh_screen_from_active_tool(bmain, workspace, tref);
+	bToolRef *tref = WM_toolsystem_ref_find(workspace, tkey);
+
+	if (tref) {
+		Main *bmain = CTX_data_main(C);
+		toolsystem_refresh_screen_from_active_tool(bmain, workspace, tref);
+	}
+
+	return (tref && STREQ(tref->idname, name)) ? tref : NULL;
+}
+
+static void toolsystem_reinit_with_toolref(
+        bContext *C, WorkSpace *workspace, bToolRef *tref)
+{
+	bToolKey tkey = {
+		.space_type = tref->space_type,
+		.mode = tref->mode,
+	};
+	WM_toolsystem_ref_set_by_name(C, workspace, &tkey, tref->idname, false);
 }
 
 /**



More information about the Bf-blender-cvs mailing list