Fix T58256: error message w/ missing Select Box tool
authorCampbell Barton <ideasman42@gmail.com>
Tue, 4 Dec 2018 02:34:11 +0000 (13:34 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 4 Dec 2018 02:55:50 +0000 (13:55 +1100)
Support space modes not having tools.

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

index 4318179c203a6969da4aaae1e7dfeb0bffd9a987..23f9161025e6234f32500cdf53f78e4b46bef2f6 100644 (file)
@@ -82,6 +82,9 @@ void WM_toolsystem_ref_sync_from_context(
 
 void WM_toolsystem_init(struct bContext *C);
 
+int WM_toolsystem_mode_from_spacetype_ex(
+        struct ViewLayer *view_layer, struct ScrArea *sa, int space_type,
+        bool *r_ensure);
 int WM_toolsystem_mode_from_spacetype(
         struct ViewLayer *view_layer, struct ScrArea *sa, int space_type);
 bool WM_toolsystem_key_from_context(
index 3b91b351b253b5d90d442137fc416ba94b08aa35..f070ac59e8f57961c23232fbdc0599927e43f784 100644 (file)
@@ -559,10 +559,12 @@ void WM_toolsystem_init(bContext *C)
        /* Rely on screen initialization for gizmos. */
 }
 
-int WM_toolsystem_mode_from_spacetype(
-        ViewLayer *view_layer, ScrArea *sa, int spacetype)
+int WM_toolsystem_mode_from_spacetype_ex(
+        ViewLayer *view_layer, ScrArea *sa, int spacetype,
+        bool *r_ensure)
 {
        int mode = -1;
+       bool ensure = false;
        switch (spacetype) {
                case SPACE_VIEW3D:
                {
@@ -575,23 +577,39 @@ int WM_toolsystem_mode_from_spacetype(
                        else {
                                mode = CTX_MODE_OBJECT;
                        }
+                       ensure = true;
                        break;
                }
                case SPACE_IMAGE:
                {
                        SpaceImage *sima = sa->spacedata.first;
                        mode = sima->mode;
+                       if (ELEM(mode, SI_MODE_PAINT, SI_MODE_UV)) {
+                               ensure = true;
+                       }
                        break;
                }
                case SPACE_NODE:
                {
                        mode = 0;
+                       ensure = true;
                        break;
                }
        }
+       if (r_ensure) {
+               *r_ensure = ensure;
+       }
        return mode;
 }
 
+int WM_toolsystem_mode_from_spacetype(
+        ViewLayer *view_layer, ScrArea *sa, int spacetype)
+{
+       return WM_toolsystem_mode_from_spacetype_ex(
+               view_layer, sa, spacetype,
+               NULL);
+}
+
 bool WM_toolsystem_key_from_context(
         ViewLayer *view_layer, ScrArea *sa, bToolKey *tkey)
 {
@@ -787,6 +805,12 @@ static const char *toolsystem_default_tool(const bToolKey *tkey)
                                        return "Comb";
                        }
                        break;
+               case SPACE_IMAGE:
+                       switch (tkey->mode) {
+                               case SI_MODE_PAINT:
+                                       return "Draw";
+                       }
+                       break;
        }
 
        return "Select Box";
@@ -825,11 +849,14 @@ void WM_toolsystem_update_from_context(
         bContext *C, WorkSpace *workspace, ViewLayer *view_layer,
         ScrArea *sa)
 {
+       bool ensure = false;
        const bToolKey tkey = {
                .space_type = sa->spacetype,
-               .mode = WM_toolsystem_mode_from_spacetype(view_layer, sa, sa->spacetype),
+               .mode = WM_toolsystem_mode_from_spacetype_ex(view_layer, sa, sa->spacetype, &ensure),
        };
-       toolsystem_reinit_ensure_toolref(C, workspace, &tkey, NULL);
+       if (ensure) {
+               toolsystem_reinit_ensure_toolref(C, workspace, &tkey, NULL);
+       }
 }