Commit: 6be7a98906b769c1496127552b524124a0e70c5a
Author: Campbell Barton
Date:   Fri Oct 26 15:05:07 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB6be7a98906b769c1496127552b524124a0e70c5a

PyAPI: raise error when toolbar panels use tabs

Add-ons that register panels in the toolbar can
no longer use 'bl_categories' (tabs).

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

M       release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M       source/blender/editors/screen/area.c
M       source/blender/makesdna/DNA_screen_types.h
M       source/blender/makesrna/intern/rna_ui.c
M       source/blender/windowmanager/WM_toolsystem.h

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

diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py 
b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 9c8d3c8eb9a..c698327e5d9 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1753,7 +1753,6 @@ class TOPBAR_PT_gpencil_materials(Panel):
 class IMAGE_PT_tools_active(ToolSelectPanelHelper, Panel):
     bl_space_type = 'IMAGE_EDITOR'
     bl_region_type = 'TOOLS'
-    bl_category = "Tools"
     bl_label = "Tools"  # not visible
     bl_options = {'HIDE_HEADER'}
 
@@ -1832,7 +1831,6 @@ class IMAGE_PT_tools_active(ToolSelectPanelHelper, Panel):
 class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
     bl_space_type = 'VIEW_3D'
     bl_region_type = 'TOOLS'
-    bl_category = "Tools"
     bl_label = "Tools"  # not visible
     bl_options = {'HIDE_HEADER'}
 
diff --git a/source/blender/editors/screen/area.c 
b/source/blender/editors/screen/area.c
index 5faa35729c4..b914dd5ecae 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -2076,7 +2076,7 @@ void ED_region_panels_layout_ex(
        int scroll;
 
        /* XXX, should use some better check? */
-       bool use_category_tabs = (ELEM(ar->regiontype, RGN_TYPE_TOOLS, 
RGN_TYPE_UI));
+       bool use_category_tabs = (1 << ar->regiontype) & 
RGN_TYPE_HAS_CATEGORY_MASK;
        /* offset panels for small vertical tab area */
        const char *category = NULL;
        const int category_tabs_width = UI_PANEL_CATEGORY_MARGIN_WIDTH;
diff --git a/source/blender/makesdna/DNA_screen_types.h 
b/source/blender/makesdna/DNA_screen_types.h
index 9a57f1ae37b..50bf24e0b55 100644
--- a/source/blender/makesdna/DNA_screen_types.h
+++ b/source/blender/makesdna/DNA_screen_types.h
@@ -477,6 +477,9 @@ enum {
 /* use for function args */
 #define RGN_TYPE_ANY -1
 
+/* Region supports panel tabs (categories). */
+#define RGN_TYPE_HAS_CATEGORY_MASK (1 << RGN_TYPE_UI)
+
 /* region alignment */
 #define RGN_ALIGN_NONE         0
 #define RGN_ALIGN_TOP          1
diff --git a/source/blender/makesrna/intern/rna_ui.c 
b/source/blender/makesrna/intern/rna_ui.c
index 0756d5e39ee..9d395f3ec9b 100644
--- a/source/blender/makesrna/intern/rna_ui.c
+++ b/source/blender/makesrna/intern/rna_ui.c
@@ -28,6 +28,7 @@
 #include <stdlib.h>
 
 #include "DNA_screen_types.h"
+#include "DNA_space_types.h"
 
 #include "BLT_translation.h"
 
@@ -41,6 +42,7 @@
 #include "UI_interface.h"
 
 #include "WM_types.h"
+#include "WM_toolsystem.h"
 
 /* see WM_types.h */
 const EnumPropertyItem rna_enum_operator_context_items[] = {
@@ -243,9 +245,20 @@ static StructRNA *rna_Panel_register(
                return NULL;
        }
 
-       if ((dummypt.category[0] == '\0') && (dummypt.region_type == 
RGN_TYPE_TOOLS)) {
-               /* Use a fallback, otherwise an empty value will draw the panel 
in every category. */
-               strcpy(dummypt.category, PNL_CATEGORY_FALLBACK);
+       if ((1 << dummypt.region_type) & RGN_TYPE_HAS_CATEGORY_MASK) {
+               if (dummypt.category[0] == '\0') {
+                       /* Use a fallback, otherwise an empty value will draw 
the panel in every category. */
+                       strcpy(dummypt.category, PNL_CATEGORY_FALLBACK);
+               }
+       }
+       else {
+               if (dummypt.category[0] != '\0') {
+                       if ((1 << dummypt.space_type) & 
WM_TOOLSYSTEM_SPACE_MASK) {
+                               BKE_reportf(reports, RPT_ERROR, "Registering 
panel class: '%s' has category '%s' ",
+                                           dummypt.idname, dummypt.category);
+                               return NULL;
+                       }
+               }
        }
 
        if (!(art = region_type_find(reports, dummypt.space_type, 
dummypt.region_type)))
diff --git a/source/blender/windowmanager/WM_toolsystem.h 
b/source/blender/windowmanager/WM_toolsystem.h
index 21408896877..fd61e5c9699 100644
--- a/source/blender/windowmanager/WM_toolsystem.h
+++ b/source/blender/windowmanager/WM_toolsystem.h
@@ -41,6 +41,7 @@ struct PointerRNA;
 struct ScrArea;
 struct Main;
 struct StructRNA;
+struct WorkSpace;
 
 /* wm_toolsystem.c  */
 
@@ -58,7 +59,7 @@ 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,
+        struct bContext *C, struct WorkSpace *workspace, const bToolKey *tkey,
         const char *name, bool cycle);
 
 struct bToolRef_Runtime *WM_toolsystem_runtime_from_context(struct bContext 
*C);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to