PyAPI: raise error when toolbar panels use tabs

Add-ons that register panels in the toolbar can
no longer use 'bl_categories' (tabs).
This commit is contained in:
Campbell Barton 2018-10-26 15:05:07 +11:00
parent 4c75cc488a
commit 6be7a98906
5 changed files with 22 additions and 7 deletions

@ -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'}

@ -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;

@ -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

@ -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)))

@ -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);