diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-05-17 23:01:58 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-05-17 23:03:34 +0300 |
commit | 3af4a46a18d3427f53ab9703d69c0255e13294dc (patch) | |
tree | bf1113f3b6852715bd168bd0f916aed61cb63f37 /source | |
parent | 50e3af88992c96cf3bb8d7953e558aa0429f1872 (diff) |
Tool System: tools now initialize on startup
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_toolsystem.c | 57 |
2 files changed, 48 insertions, 11 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 5562e7880fa..39132184371 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -612,10 +612,12 @@ struct bToolRef_Runtime *WM_toolsystem_runtime_find(struct WorkSpace *workspace, void WM_toolsystem_unlink(struct bContext *C, struct WorkSpace *workspace, const bToolKey *tkey); void WM_toolsystem_link(struct bContext *C, struct WorkSpace *workspace, const bToolKey *tkey); void WM_toolsystem_refresh(struct bContext *C, struct WorkSpace *workspace, const bToolKey *tkey); +void WM_toolsystem_reinit(struct bContext *C, struct WorkSpace *workspace, const bToolKey *tkey); void WM_toolsystem_unlink_all(struct bContext *C, struct WorkSpace *workspace); void WM_toolsystem_link_all(struct bContext *C, struct WorkSpace *workspace); void WM_toolsystem_refresh_all(struct bContext *C, struct WorkSpace *workspace); +void WM_toolsystem_reinit_all(struct bContext *C, struct WorkSpace *workspace); void WM_toolsystem_ref_set_from_runtime( struct bContext *C, struct WorkSpace *workspace, struct bToolRef *tref, diff --git a/source/blender/windowmanager/intern/wm_toolsystem.c b/source/blender/windowmanager/intern/wm_toolsystem.c index 1191bec3f65..93481dcd56c 100644 --- a/source/blender/windowmanager/intern/wm_toolsystem.c +++ b/source/blender/windowmanager/intern/wm_toolsystem.c @@ -53,6 +53,10 @@ #include "WM_types.h" #include "WM_message.h" +static void toolsystem_reinit_with_toolref( + bContext *C, WorkSpace *UNUSED(workspace), const bToolRef *tref); +static void toolsystem_reinit_ensure_toolref( + bContext *C, WorkSpace *workspace, const bToolKey *tkey, const char *default_tool); /* -------------------------------------------------------------------- */ /** \name Tool Reference API @@ -202,6 +206,9 @@ void WM_toolsystem_link(bContext *C, WorkSpace *workspace, const bToolKey *tkey) static void toolsystem_refresh_ref(bContext *C, WorkSpace *workspace, bToolRef *tref) { + if (tref->runtime == NULL) { + return; + } /* currently same operation. */ toolsystem_ref_link(C, workspace, tref); } @@ -213,6 +220,18 @@ void WM_toolsystem_refresh(bContext *C, WorkSpace *workspace, const bToolKey *tk } } +static void toolsystem_reinit_ref(bContext *C, WorkSpace *workspace, bToolRef *tref) +{ + toolsystem_reinit_with_toolref(C, workspace, tref); +} +void WM_toolsystem_reinit(bContext *C, WorkSpace *workspace, const bToolKey *tkey) +{ + bToolRef *tref = WM_toolsystem_ref_find(workspace, tkey); + if (tref) { + toolsystem_reinit_ref(C, workspace, tref); + } +} + /* Operate on all active tools. */ void WM_toolsystem_unlink_all(struct bContext *C, struct WorkSpace *workspace) { @@ -233,8 +252,14 @@ void WM_toolsystem_link_all(struct bContext *C, struct WorkSpace *workspace) void WM_toolsystem_refresh_all(struct bContext *C, struct WorkSpace *workspace) { LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) { + toolsystem_refresh_ref(C, workspace, tref); + } +} +void WM_toolsystem_reinit_all(struct bContext *C, struct WorkSpace *workspace) +{ + LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) { if (tref->runtime) { - toolsystem_refresh_ref(C, workspace, tref); + toolsystem_reinit_ref(C, workspace, tref); } } } @@ -278,7 +303,7 @@ void WM_toolsystem_init(bContext *C) for (wmWindow *win = wm->windows.first; win; win = win->next) { WorkSpace *workspace = WM_window_get_active_workspace(win); - WM_toolsystem_link_all(C, workspace); + WM_toolsystem_refresh_all(C, workspace); } } @@ -335,23 +360,33 @@ bool WM_toolsystem_key_from_context( /** * Run after changing modes. */ -static void toolsystem_update_with_toolref( - bContext *C, WorkSpace *workspace, const bToolKey *tkey, const char *default_tool) +static void toolsystem_reinit_with_toolref( + bContext *C, WorkSpace *UNUSED(workspace), const bToolRef *tref) { - bToolRef *tref; - if (WM_toolsystem_ref_ensure(workspace, tkey, &tref)) { - STRNCPY(tref->idname, default_tool); - } - wmOperatorType *ot = WM_operatortype_find("WM_OT_tool_set_by_name", false); + /* On startup, Python operatores are not yet loaded. */ + if (ot == NULL) { + return; + } 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", tkey->space_type); + RNA_enum_set(&op_props, "space_type", tref->space_type); WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &op_props); WM_operator_properties_free(&op_props); } +static void toolsystem_reinit_ensure_toolref( + bContext *C, WorkSpace *workspace, const bToolKey *tkey, const char *default_tool) +{ + bToolRef *tref; + if (WM_toolsystem_ref_ensure(workspace, tkey, &tref)) { + STRNCPY(tref->idname, default_tool); + } + + toolsystem_reinit_with_toolref(C, workspace, tref); +} + void WM_toolsystem_update_from_context_view3d(bContext *C) { WorkSpace *workspace = CTX_wm_workspace(C); @@ -361,7 +396,7 @@ void WM_toolsystem_update_from_context_view3d(bContext *C) .space_type = space_type, .mode = WM_toolsystem_mode_from_spacetype(workspace, scene, NULL, space_type), }; - toolsystem_update_with_toolref(C, workspace, &tkey, "Cursor"); + toolsystem_reinit_ensure_toolref(C, workspace, &tkey, "Cursor"); } /** |