Fix #124070: Improved Area Names Using a SpaceType Callback
Centralized method to obtain ScrArea names. Areas can add an optional space_name_get callback to provide a name that differs by subtype. If not defined then ED_area_name will return RNA UI name, which is correct in cases without area subtypes. This eliminates the current use of RNA_property_enum_name_gettexted using a temporary context, which results in the reported (hard to duplicate) error. Pull Request: https://projects.blender.org/blender/blender/pulls/124488
This commit is contained in:
committed by
Harley Acheson
parent
c3243f363d
commit
1f3d1048d4
@@ -126,6 +126,9 @@ struct SpaceType {
|
||||
void (*space_subtype_set)(ScrArea *area, int value);
|
||||
void (*space_subtype_item_extend)(bContext *C, EnumPropertyItem **item, int *totitem);
|
||||
|
||||
/* Return a custom name, based on subtype or other reason. */
|
||||
blender::StringRefNull (*space_name_get)(ScrArea *area);
|
||||
|
||||
/**
|
||||
* Update pointers for all structs directly owned by this space.
|
||||
*/
|
||||
|
||||
@@ -210,6 +210,7 @@ int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco);
|
||||
*/
|
||||
void ED_area_init(wmWindowManager *wm, wmWindow *win, ScrArea *area);
|
||||
void ED_area_exit(bContext *C, ScrArea *area);
|
||||
blender::StringRefNull ED_area_name(ScrArea *area);
|
||||
int ED_screen_area_active(const bContext *C);
|
||||
void ED_screen_global_areas_refresh(wmWindow *win);
|
||||
void ED_screen_global_areas_sync(wmWindow *win);
|
||||
|
||||
@@ -38,6 +38,9 @@
|
||||
#include "ED_screen.hh"
|
||||
#include "ED_screen_types.hh"
|
||||
|
||||
#include "RNA_access.hh"
|
||||
#include "RNA_enum_types.hh"
|
||||
|
||||
#include "UI_interface.hh"
|
||||
|
||||
#include "WM_message.hh"
|
||||
@@ -902,6 +905,17 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
|
||||
}
|
||||
}
|
||||
|
||||
blender::StringRefNull ED_area_name(ScrArea *area)
|
||||
{
|
||||
if (area->type->space_name_get) {
|
||||
return area->type->space_name_get(area);
|
||||
}
|
||||
|
||||
const int index = RNA_enum_from_value(rna_enum_space_type_items, area->spacetype);
|
||||
const EnumPropertyItem item = rna_enum_space_type_items[index];
|
||||
return item.name;
|
||||
}
|
||||
|
||||
/* *********************************** */
|
||||
|
||||
/* case when on area-edge or in azones, or outside window */
|
||||
|
||||
@@ -866,6 +866,14 @@ static void action_space_subtype_item_extend(bContext * /*C*/,
|
||||
RNA_enum_items_add(item, totitem, rna_enum_space_action_mode_items);
|
||||
}
|
||||
|
||||
static blender::StringRefNull action_space_name_get(ScrArea *area)
|
||||
{
|
||||
SpaceAction *sact = static_cast<SpaceAction *>(area->spacedata.first);
|
||||
const int index = RNA_enum_from_value(rna_enum_space_action_mode_items, sact->mode);
|
||||
const EnumPropertyItem item = rna_enum_space_action_mode_items[index];
|
||||
return item.name;
|
||||
}
|
||||
|
||||
static void action_space_blend_read_data(BlendDataReader * /*reader*/, SpaceLink *sl)
|
||||
{
|
||||
SpaceAction *saction = (SpaceAction *)sl;
|
||||
@@ -898,6 +906,7 @@ void ED_spacetype_action()
|
||||
st->space_subtype_item_extend = action_space_subtype_item_extend;
|
||||
st->space_subtype_get = action_space_subtype_get;
|
||||
st->space_subtype_set = action_space_subtype_set;
|
||||
st->space_name_get = action_space_name_get;
|
||||
st->blend_read_data = action_space_blend_read_data;
|
||||
st->blend_read_after_liblink = nullptr;
|
||||
st->blend_write = action_space_blend_write;
|
||||
|
||||
@@ -831,6 +831,14 @@ static void file_space_subtype_item_extend(bContext * /*C*/, EnumPropertyItem **
|
||||
RNA_enum_items_add(item, totitem, rna_enum_space_file_browse_mode_items);
|
||||
}
|
||||
|
||||
static blender::StringRefNull file_space_name_get(ScrArea *area)
|
||||
{
|
||||
SpaceFile *sfile = static_cast<SpaceFile *>(area->spacedata.first);
|
||||
const int index = RNA_enum_from_value(rna_enum_space_file_browse_mode_items, sfile->browse_mode);
|
||||
const EnumPropertyItem item = rna_enum_space_file_browse_mode_items[index];
|
||||
return item.name;
|
||||
}
|
||||
|
||||
static void file_id_remap(ScrArea *area,
|
||||
SpaceLink *sl,
|
||||
const blender::bke::id::IDRemapper & /*mappings*/)
|
||||
@@ -926,6 +934,7 @@ void ED_spacetype_file()
|
||||
st->space_subtype_item_extend = file_space_subtype_item_extend;
|
||||
st->space_subtype_get = file_space_subtype_get;
|
||||
st->space_subtype_set = file_space_subtype_set;
|
||||
st->space_name_get = file_space_name_get;
|
||||
st->context = file_context;
|
||||
st->id_remap = file_id_remap;
|
||||
st->foreach_id = file_foreach_id;
|
||||
|
||||
@@ -868,6 +868,14 @@ static void graph_space_subtype_item_extend(bContext * /*C*/,
|
||||
RNA_enum_items_add(item, totitem, rna_enum_space_graph_mode_items);
|
||||
}
|
||||
|
||||
static blender::StringRefNull graph_space_name_get(ScrArea *area)
|
||||
{
|
||||
SpaceGraph *sgraph = static_cast<SpaceGraph *>(area->spacedata.first);
|
||||
const int index = RNA_enum_from_value(rna_enum_space_graph_mode_items, sgraph->mode);
|
||||
const EnumPropertyItem item = rna_enum_space_graph_mode_items[index];
|
||||
return item.name;
|
||||
}
|
||||
|
||||
static void graph_space_blend_read_data(BlendDataReader *reader, SpaceLink *sl)
|
||||
{
|
||||
SpaceGraph *sipo = (SpaceGraph *)sl;
|
||||
@@ -914,6 +922,7 @@ void ED_spacetype_ipo()
|
||||
st->space_subtype_item_extend = graph_space_subtype_item_extend;
|
||||
st->space_subtype_get = graph_space_subtype_get;
|
||||
st->space_subtype_set = graph_space_subtype_set;
|
||||
st->space_name_get = graph_space_name_get;
|
||||
st->blend_read_data = graph_space_blend_read_data;
|
||||
st->blend_read_after_liblink = nullptr;
|
||||
st->blend_write = graph_space_blend_write;
|
||||
|
||||
@@ -1077,6 +1077,14 @@ static void image_space_subtype_item_extend(bContext * /*C*/,
|
||||
RNA_enum_items_add(item, totitem, rna_enum_space_image_mode_items);
|
||||
}
|
||||
|
||||
static blender::StringRefNull image_space_name_get(ScrArea *area)
|
||||
{
|
||||
SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
|
||||
const int index = RNA_enum_from_value(rna_enum_space_image_mode_items, sima->mode);
|
||||
const EnumPropertyItem item = rna_enum_space_image_mode_items[index];
|
||||
return item.name;
|
||||
}
|
||||
|
||||
static void image_space_blend_read_data(BlendDataReader * /*reader*/, SpaceLink *sl)
|
||||
{
|
||||
SpaceImage *sima = (SpaceImage *)sl;
|
||||
@@ -1132,6 +1140,7 @@ void ED_spacetype_image()
|
||||
st->space_subtype_item_extend = image_space_subtype_item_extend;
|
||||
st->space_subtype_get = image_space_subtype_get;
|
||||
st->space_subtype_set = image_space_subtype_set;
|
||||
st->space_name_get = image_space_name_get;
|
||||
st->blend_read_data = image_space_blend_read_data;
|
||||
st->blend_read_after_liblink = nullptr;
|
||||
st->blend_write = image_space_blend_write;
|
||||
|
||||
@@ -1334,6 +1334,13 @@ static void node_space_subtype_item_extend(bContext *C, EnumPropertyItem **item,
|
||||
}
|
||||
}
|
||||
|
||||
static blender::StringRefNull node_space_name_get(ScrArea *area)
|
||||
{
|
||||
SpaceNode *snode = (SpaceNode *)area->spacedata.first;
|
||||
bke::bNodeTreeType *tree_type = bke::ntreeTypeFind(snode->tree_idname);
|
||||
return tree_type->ui_name;
|
||||
}
|
||||
|
||||
static void node_space_blend_read_data(BlendDataReader *reader, SpaceLink *sl)
|
||||
{
|
||||
SpaceNode *snode = (SpaceNode *)sl;
|
||||
@@ -1387,6 +1394,7 @@ void ED_spacetype_node()
|
||||
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;
|
||||
st->space_name_get = node_space_name_get;
|
||||
st->blend_read_data = node_space_blend_read_data;
|
||||
st->blend_read_after_liblink = nullptr;
|
||||
st->blend_write = node_space_blend_write;
|
||||
|
||||
@@ -501,17 +501,8 @@ void WM_window_title(wmWindowManager *wm, wmWindow *win, const char *title)
|
||||
const bool is_single = screen && BLI_listbase_is_single(&screen->areabase);
|
||||
ScrArea *area = (screen) ? static_cast<ScrArea *>(screen->areabase.first) : nullptr;
|
||||
const char *name = "Blender";
|
||||
if (is_single && area) {
|
||||
PointerRNA ptr = RNA_pointer_create(&(screen->id), &RNA_Area, area);
|
||||
PropertyRNA *prop_ui_type = RNA_struct_find_property(&ptr, "ui_type");
|
||||
bContext *C = CTX_create();
|
||||
CTX_wm_manager_set(C, wm);
|
||||
CTX_wm_window_set(C, win);
|
||||
CTX_wm_screen_set(C, screen);
|
||||
CTX_wm_area_set(C, area);
|
||||
RNA_property_enum_name_gettexted(
|
||||
C, &ptr, prop_ui_type, RNA_property_enum_get(&ptr, prop_ui_type), &name);
|
||||
CTX_free(C);
|
||||
if (is_single && area && area->spacetype != SPACE_EMPTY) {
|
||||
name = IFACE_(ED_area_name(area).c_str());
|
||||
}
|
||||
GHOST_SetTitle(handle, name);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user