UI: Expand space sub-types into the menu

Initial support for expanding editors, see: T54744
This commit is contained in:
Campbell Barton 2018-05-29 09:19:06 +02:00
parent d4ac65d003
commit 756b70c6c3
Notes: blender-bot 2023-02-14 07:08:26 +01:00
Referenced by issue #54744, UI: Expand List of Editors
9 changed files with 118 additions and 5 deletions

View File

@ -48,7 +48,8 @@ class NODE_HT_header(Header):
row = layout.row(align=True)
row.template_header()
layout.prop(snode, "tree_type", text="")
# Now expanded via the 'ui_type'
# layout.prop(snode, "tree_type", text="")
NODE_MT_editor_menus.draw_collapsible(context, layout)

View File

@ -114,6 +114,10 @@ typedef struct SpaceType {
/* Used when we want to replace an ID by another (or NULL). */
void (*id_remap)(struct ScrArea *, struct SpaceLink *, struct ID *, struct ID *);
int (*space_subtype_get)(struct ScrArea *sa);
void (*space_subtype_set)(struct ScrArea *sa, int value);
void (*space_subtype_item_extend)(struct bContext *C, EnumPropertyItem **item, int *totitem);
/* region type definitions */
ListBase regiontypes;

View File

@ -1753,7 +1753,7 @@ int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco)
RNA_pointer_create(&(scr->id), &RNA_Area, sa, &areaptr);
uiDefButR(block, UI_BTYPE_MENU, 0, "", xco, yco, 1.6 * U.widget_unit, U.widget_unit,
&areaptr, "type", 0, 0.0f, 0.0f, 0.0f, 0.0f, "");
&areaptr, "ui_type", 0, 0.0f, 0.0f, 0.0f, 0.0f, "");
return xco + 1.7 * U.widget_unit;
}

View File

@ -54,6 +54,8 @@
#include "UI_view2d.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
#include "WM_api.h"
#include "WM_types.h"
@ -942,6 +944,32 @@ static void node_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID
}
}
static int node_space_subtype_get(ScrArea *sa)
{
SpaceNode *snode = sa->spacedata.first;
return rna_node_tree_idname_to_enum(snode->tree_idname);
}
static void node_space_subtype_set(ScrArea *sa, int value)
{
SpaceNode *snode = sa->spacedata.first;
ED_node_set_tree_type(snode, rna_node_tree_type_from_enum(value));
}
static void node_space_subtype_item_extend(
bContext *C, EnumPropertyItem **item, int *totitem)
{
bool free;
const EnumPropertyItem *item_src = RNA_enum_node_tree_types_itemf_impl(C, &free);
for (const EnumPropertyItem *item_iter = item_src; item_iter->identifier; item_iter++) {
RNA_enum_item_add(item, totitem, item_iter);
}
if (free) {
MEM_freeN((void *)item_src);
}
}
/* only called once, from space/spacetypes.c */
void ED_spacetype_node(void)
{
@ -964,6 +992,10 @@ void ED_spacetype_node(void)
st->manipulators = node_widgets;
st->id_remap = node_id_remap;
st->space_subtype_item_extend = node_space_subtype_item_extend;
st->space_subtype_get = node_space_subtype_get;
st->space_subtype_set = node_space_subtype_set;
/* regions: main window */
art = MEM_callocN(sizeof(ARegionType), "spacetype node region");
art->regionid = RGN_TYPE_WINDOW;

View File

@ -245,4 +245,7 @@ const EnumPropertyItem *RNA_movieclip_local_itemf(struct bContext *C, struct Poi
const EnumPropertyItem *RNA_mask_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free);
const EnumPropertyItem *RNA_mask_local_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free);
/* Non confirming, utility function. */
const EnumPropertyItem *RNA_enum_node_tree_types_itemf_impl(struct bContext *C, bool *r_free);
#endif /* __RNA_ENUM_TYPES_H__ */

View File

@ -58,6 +58,7 @@ const EnumPropertyItem rna_enum_region_type_items[] = {
#include "BKE_global.h"
#include "BKE_workspace.h"
#include "BKE_screen.h"
#include "DEG_depsgraph.h"
@ -214,6 +215,63 @@ static void rna_Area_type_update(bContext *C, PointerRNA *ptr)
}
}
static const EnumPropertyItem *rna_Area_ui_type_itemf(
bContext *C, PointerRNA *UNUSED(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++) {
if (ELEM(item_from->value, SPACE_TOPBAR, SPACE_STATUSBAR)) {
continue;
}
SpaceType *st = item_from->identifier[0] ? BKE_spacetype_from_id(item_from->value) : NULL;
int totitem_prev = totitem;
if (st && st->space_subtype_item_extend != NULL) {
st->space_subtype_item_extend(C, &item, &totitem);
while (totitem_prev < totitem) {
item[totitem_prev++].value |= item_from->value << 16;
}
}
else {
RNA_enum_item_add(&item, &totitem, item_from);
item[totitem_prev++].value = item_from->value << 16;
}
}
RNA_enum_item_end(&item, &totitem);
*r_free = true;
return item;
}
static int rna_Area_ui_type_get(PointerRNA *ptr)
{
int value = rna_Area_type_get(ptr) << 16;
ScrArea *sa = (ScrArea *)ptr->data;
if (sa->type->space_subtype_item_extend != NULL) {
value |= sa->type->space_subtype_get(sa);
}
return value;
}
static void rna_Area_ui_type_set(PointerRNA *ptr, int value)
{
rna_Area_type_set(ptr, value >> 16);
ScrArea *sa = (ScrArea *)ptr->data;
if (sa->type->space_subtype_item_extend != NULL) {
sa->type->space_subtype_set(sa, value & 0xffff);
}
}
static void rna_Area_ui_type_update(bContext *C, PointerRNA *ptr)
{
rna_Area_type_update(C, ptr);
}
static void rna_View2D_region_to_view(struct View2D *v2d, int x, int y, float result[2])
{
UI_view2d_region_to_view(v2d, x, y, &result[0], &result[1]);
@ -284,6 +342,15 @@ static void rna_def_area(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_update(prop, 0, "rna_Area_type_update");
prop = RNA_def_property(srna, "ui_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, DummyRNA_DEFAULT_items); /* infact dummy */
RNA_def_property_enum_default(prop, 0);
RNA_def_property_enum_funcs(prop, "rna_Area_ui_type_get", "rna_Area_ui_type_set", "rna_Area_ui_type_itemf");
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);
RNA_def_property_update(prop, 0, "rna_Area_ui_type_update");
prop = RNA_def_property(srna, "x", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "totrct.xmin");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);

View File

@ -1494,11 +1494,17 @@ static int rna_SpaceNodeEditor_tree_type_poll(void *Cv, bNodeTreeType *type)
else
return true;
}
const EnumPropertyItem *RNA_enum_node_tree_types_itemf_impl(bContext *C, bool *r_free)
{
return rna_node_tree_type_itemf(C, rna_SpaceNodeEditor_tree_type_poll, r_free);
}
static const EnumPropertyItem *rna_SpaceNodeEditor_tree_type_itemf(
bContext *C, PointerRNA *UNUSED(ptr),
PropertyRNA *UNUSED(prop), bool *r_free)
{
return rna_node_tree_type_itemf(C, rna_SpaceNodeEditor_tree_type_poll, r_free);
return RNA_enum_node_tree_types_itemf_impl(C, r_free);
}
static void rna_SpaceNodeEditor_path_get(PointerRNA *ptr, char *value)

View File

@ -178,7 +178,7 @@ void register_node_tree_type_sh(void)
tt->type = NTREE_SHADER;
strcpy(tt->idname, "ShaderNodeTree");
strcpy(tt->ui_name, "Shader");
strcpy(tt->ui_name, "Shader Editor");
tt->ui_icon = 0; /* defined in drawnode.c */
strcpy(tt->ui_description, "Shader nodes");

View File

@ -164,7 +164,7 @@ void register_node_tree_type_tex(void)
tt->type = NTREE_TEXTURE;
strcpy(tt->idname, "TextureNodeTree");
strcpy(tt->ui_name, "Texture");
strcpy(tt->ui_name, "Texture Editor");
tt->ui_icon = 0; /* defined in drawnode.c */
strcpy(tt->ui_description, "Texture nodes");