Fix T87187: Area.type & ui_type empty area access fails
Reading Area.type & ui_type printed an error from `pyrna_enum_to_py` and returned an empty string. As empty is a valid value, include it in the property enum list.
This commit is contained in:
parent
074b0b6da0
commit
3f3b4745b6
Notes:
blender-bot
2023-10-12 12:49:04 +02:00
Referenced by commit 947ba0d27b
, Fix T87355: Crash using menu search from the top bar
Referenced by issue #87355, Crash using menu search from the top bar
Referenced by issue #87187, pyrna_enum_to_py complains when iterate Python Console areas
|
@ -112,18 +112,6 @@ static bool rna_Screen_fullscreen_get(PointerRNA *ptr)
|
|||
return (screen->state == SCREENMAXIMIZED);
|
||||
}
|
||||
|
||||
/* UI compatible list: should not be needed, but for now we need to keep EMPTY
|
||||
* at least in the static version of this enum for python scripts. */
|
||||
static const EnumPropertyItem *rna_Area_type_itemf(bContext *UNUSED(C),
|
||||
PointerRNA *UNUSED(ptr),
|
||||
PropertyRNA *UNUSED(prop),
|
||||
bool *r_free)
|
||||
{
|
||||
/* +1 to skip SPACE_EMPTY */
|
||||
*r_free = false;
|
||||
return rna_enum_space_type_items + 1;
|
||||
}
|
||||
|
||||
static int rna_Area_type_get(PointerRNA *ptr)
|
||||
{
|
||||
ScrArea *area = (ScrArea *)ptr->data;
|
||||
|
@ -142,6 +130,11 @@ static void rna_Area_type_set(PointerRNA *ptr, int value)
|
|||
}
|
||||
|
||||
ScrArea *area = (ScrArea *)ptr->data;
|
||||
/* Empty areas are locked. */
|
||||
if ((value == SPACE_EMPTY) || (area->spacetype == SPACE_EMPTY)) {
|
||||
return;
|
||||
}
|
||||
|
||||
area->butspacetype = value;
|
||||
}
|
||||
|
||||
|
@ -188,16 +181,20 @@ static void rna_Area_type_update(bContext *C, PointerRNA *ptr)
|
|||
}
|
||||
|
||||
static const EnumPropertyItem *rna_Area_ui_type_itemf(bContext *C,
|
||||
PointerRNA *UNUSED(ptr),
|
||||
PointerRNA *ptr,
|
||||
PropertyRNA *UNUSED(prop),
|
||||
bool *r_free)
|
||||
{
|
||||
EnumPropertyItem *item = NULL;
|
||||
int totitem = 0;
|
||||
|
||||
/* +1 to skip SPACE_EMPTY */
|
||||
for (const EnumPropertyItem *item_from = rna_enum_space_type_items + 1; item_from->identifier;
|
||||
item_from++) {
|
||||
ScrArea *area = (ScrArea *)ptr->data;
|
||||
const EnumPropertyItem *item_from = rna_enum_space_type_items;
|
||||
if (area->spacetype != SPACE_EMPTY) {
|
||||
item_from += 1; /* +1 to skip SPACE_EMPTY */
|
||||
}
|
||||
|
||||
for (; item_from->identifier; item_from++) {
|
||||
if (ELEM(item_from->value, SPACE_TOPBAR, SPACE_STATUSBAR)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -224,6 +221,10 @@ static const EnumPropertyItem *rna_Area_ui_type_itemf(bContext *C,
|
|||
static int rna_Area_ui_type_get(PointerRNA *ptr)
|
||||
{
|
||||
ScrArea *area = ptr->data;
|
||||
/* This is for the Python API which may inspect empty areas. */
|
||||
if (UNLIKELY(area->spacetype == SPACE_EMPTY)) {
|
||||
return SPACE_EMPTY;
|
||||
}
|
||||
const int area_type = rna_Area_type_get(ptr);
|
||||
const bool area_changing = area->butspacetype != SPACE_EMPTY;
|
||||
int value = area_type << 16;
|
||||
|
@ -252,6 +253,10 @@ static void rna_Area_ui_type_set(PointerRNA *ptr, int value)
|
|||
{
|
||||
ScrArea *area = ptr->data;
|
||||
const int space_type = value >> 16;
|
||||
/* Empty areas are locked. */
|
||||
if ((space_type == SPACE_EMPTY) || (area->spacetype == SPACE_EMPTY)) {
|
||||
return;
|
||||
}
|
||||
SpaceType *st = BKE_spacetype_from_id(space_type);
|
||||
|
||||
rna_Area_type_set(ptr, space_type);
|
||||
|
@ -380,12 +385,17 @@ static void rna_def_area(BlenderRNA *brna)
|
|||
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", HEADER_NO_PULLDOWN);
|
||||
RNA_def_property_ui_text(prop, "Show Menus", "Show menus in the header");
|
||||
|
||||
/* Note on space type use of #SPACE_EMPTY, this is not visible to the user,
|
||||
* and script authors should be able to assign this value, however the value may be set
|
||||
* and needs to be read back by script authors.
|
||||
*
|
||||
* This happens when an area is full-screen (when #ScrArea.full is set).
|
||||
* in this case reading the empty value is needed, but it should never be set, see: T87187. */
|
||||
prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "spacetype");
|
||||
RNA_def_property_enum_items(prop, rna_enum_space_type_items);
|
||||
RNA_def_property_enum_default(prop, SPACE_VIEW3D);
|
||||
RNA_def_property_enum_funcs(
|
||||
prop, "rna_Area_type_get", "rna_Area_type_set", "rna_Area_type_itemf");
|
||||
RNA_def_property_enum_funcs(prop, "rna_Area_type_get", "rna_Area_type_set", NULL);
|
||||
RNA_def_property_ui_text(prop, "Editor Type", "Current editor type for this area");
|
||||
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
|
||||
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
|
|
Loading…
Reference in New Issue