Fix #130372: Implements memory of the previous state of eSpace_Types.

This implements the memorization of the previous state of a space's
subtype for those that have multiple modes. Introduces an optional
space_subtype_prev_get callback, implemented for SPACE_ACTION,
SPACE_FILE, SPACE_GRAPH, SPACE_IMAGE and SPACE_NODE. This means we
can always return to the previous mode.

Pull Request: https://projects.blender.org/blender/blender/pulls/133846
This commit is contained in:
Fabricio Luis
2025-02-13 18:45:00 +01:00
committed by Harley Acheson
parent ee8b9a3799
commit afec64739a
9 changed files with 66 additions and 24 deletions

View File

@@ -130,6 +130,7 @@ struct SpaceType {
int (*space_subtype_get)(ScrArea *area);
void (*space_subtype_set)(ScrArea *area, int value);
void (*space_subtype_item_extend)(bContext *C, EnumPropertyItem **item, int *totitem);
int (*space_subtype_prev_get)(ScrArea *area);
/* Return a custom name, based on subtype or other reason. */
blender::StringRefNull (*space_name_get)(const ScrArea *area);

View File

@@ -2601,7 +2601,9 @@ void ED_area_newspace(bContext *C, ScrArea *area, int type, const bool skip_regi
wmWindow *win = CTX_wm_window(C);
SpaceType *st = BKE_spacetype_from_id(type);
if (area->spacetype != type) {
const bool change_spacetype = area->spacetype != type;
if (change_spacetype) {
SpaceLink *slold = static_cast<SpaceLink *>(area->spacedata.first);
/* store area->type->exit callback */
void (*area_exit)(wmWindowManager *, ScrArea *) = area->type ? area->type->exit : nullptr;
@@ -2710,10 +2712,13 @@ void ED_area_newspace(bContext *C, ScrArea *area, int type, const bool skip_regi
}
/* Set area space subtype if applicable. */
if (st->space_subtype_item_extend != nullptr) {
if (st && st->space_subtype_item_extend != nullptr) {
BLI_assert(st->space_subtype_prev_get != nullptr);
st->space_subtype_set(area, area->butspacetype_subtype);
if (change_spacetype) {
st->space_subtype_set(area, st->space_subtype_prev_get(area));
}
}
area->butspacetype_subtype = 0;
if (BLI_listbase_is_single(&CTX_wm_screen(C)->areabase)) {
/* If there is only one area update the window title. */

View File

@@ -874,15 +874,8 @@ static int action_space_subtype_get(ScrArea *area)
static void action_space_subtype_set(ScrArea *area, int value)
{
SpaceAction *sact = static_cast<SpaceAction *>(area->spacedata.first);
if (value == SACTCONT_TIMELINE) {
if (sact->mode != SACTCONT_TIMELINE) {
sact->mode_prev = sact->mode;
}
sact->mode = value;
}
else {
sact->mode = sact->mode_prev;
}
sact->mode_prev = sact->mode;
sact->mode = value;
}
static void action_space_subtype_item_extend(bContext * /*C*/,
@@ -892,6 +885,12 @@ static void action_space_subtype_item_extend(bContext * /*C*/,
RNA_enum_items_add(item, totitem, rna_enum_space_action_mode_items);
}
static int action_space_subtype_prev_get(ScrArea *area)
{
SpaceAction *sact = static_cast<SpaceAction *>(area->spacedata.first);
return sact->mode_prev;
}
static blender::StringRefNull action_space_name_get(const ScrArea *area)
{
SpaceAction *sact = static_cast<SpaceAction *>(area->spacedata.first);
@@ -940,6 +939,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_subtype_prev_get = action_space_subtype_prev_get;
st->space_name_get = action_space_name_get;
st->space_icon_get = action_space_icon_get;
st->blend_read_data = action_space_blend_read_data;

View File

@@ -824,6 +824,7 @@ static void file_space_subtype_set(ScrArea *area, int value)
LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
region->v2d.flag &= ~V2D_IS_INIT;
}
sfile->browse_mode_prev = sfile->browse_mode;
sfile->browse_mode = value;
}
@@ -832,6 +833,12 @@ static void file_space_subtype_item_extend(bContext * /*C*/, EnumPropertyItem **
RNA_enum_items_add(item, totitem, rna_enum_space_file_browse_mode_items);
}
static int file_space_subtype_prev_get(ScrArea *area)
{
SpaceFile *sfile = static_cast<SpaceFile *>(area->spacedata.first);
return sfile->browse_mode_prev;
}
static blender::StringRefNull file_space_name_get(const ScrArea *area)
{
SpaceFile *sfile = static_cast<SpaceFile *>(area->spacedata.first);
@@ -943,6 +950,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_subtype_prev_get = file_space_subtype_prev_get;
st->space_name_get = file_space_name_get;
st->space_icon_get = file_space_icon_get;
st->context = file_context;

View File

@@ -865,6 +865,7 @@ static int graph_space_subtype_get(ScrArea *area)
static void graph_space_subtype_set(ScrArea *area, int value)
{
SpaceGraph *sgraph = static_cast<SpaceGraph *>(area->spacedata.first);
sgraph->mode_prev = sgraph->mode;
sgraph->mode = value;
}
@@ -875,6 +876,12 @@ static void graph_space_subtype_item_extend(bContext * /*C*/,
RNA_enum_items_add(item, totitem, rna_enum_space_graph_mode_items);
}
static int graph_space_subtype_prev_get(ScrArea *area)
{
SpaceGraph *sgraph = static_cast<SpaceGraph *>(area->spacedata.first);
return sgraph->mode_prev;
}
static blender::StringRefNull graph_space_name_get(const ScrArea *area)
{
SpaceGraph *sgraph = static_cast<SpaceGraph *>(area->spacedata.first);
@@ -937,6 +944,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_subtype_prev_get = graph_space_subtype_prev_get;
st->space_name_get = graph_space_name_get;
st->space_icon_get = graph_space_icon_get;
st->blend_read_data = graph_space_blend_read_data;

View File

@@ -1062,15 +1062,8 @@ static int image_space_subtype_get(ScrArea *area)
static void image_space_subtype_set(ScrArea *area, int value)
{
SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
if (value == SI_MODE_UV) {
if (sima->mode != SI_MODE_UV) {
sima->mode_prev = sima->mode;
}
sima->mode = value;
}
else {
sima->mode = sima->mode_prev;
}
sima->mode_prev = sima->mode;
sima->mode = value;
}
static void image_space_subtype_item_extend(bContext * /*C*/,
@@ -1080,6 +1073,12 @@ static void image_space_subtype_item_extend(bContext * /*C*/,
RNA_enum_items_add(item, totitem, rna_enum_space_image_mode_items);
}
static int image_space_subtype_prev_get(ScrArea *area)
{
SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
return sima->mode_prev;
}
static blender::StringRefNull image_space_name_get(const ScrArea *area)
{
SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
@@ -1157,6 +1156,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_subtype_prev_get = image_space_subtype_prev_get;
st->space_name_get = image_space_name_get;
st->space_icon_get = image_space_icon_get;
st->blend_read_data = image_space_blend_read_data;

View File

@@ -1310,6 +1310,17 @@ static int node_space_subtype_get(ScrArea *area)
static void node_space_subtype_set(ScrArea *area, int value)
{
SpaceNode *snode = static_cast<SpaceNode *>(area->spacedata.first);
int value_prev = node_space_subtype_get(area);
/* Save the subtype. */
blender::bke::bNodeTreeType *typeinfo = rna_node_tree_type_from_enum(value_prev);
if (typeinfo) {
STRNCPY(snode->tree_idname_prev, typeinfo->idname.c_str());
}
else {
snode->tree_idname_prev[0] = '\0';
}
ED_node_set_tree_type(snode, rna_node_tree_type_from_enum(value));
}
@@ -1323,6 +1334,12 @@ static void node_space_subtype_item_extend(bContext *C, EnumPropertyItem **item,
}
}
static int node_space_subtype_prev_get(ScrArea *area)
{
SpaceNode *snode = static_cast<SpaceNode *>(area->spacedata.first);
return rna_node_tree_idname_to_enum(snode->tree_idname_prev);
}
static blender::StringRefNull node_space_name_get(const ScrArea *area)
{
SpaceNode *snode = static_cast<SpaceNode *>(area->spacedata.first);
@@ -1390,6 +1407,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_subtype_prev_get = node_space_subtype_prev_get;
st->space_name_get = node_space_name_get;
st->space_icon_get = node_space_icon_get;
st->blend_read_data = node_space_blend_read_data;

View File

@@ -439,6 +439,7 @@ typedef struct ScrArea {
*/
char butspacetype;
short butspacetype_subtype;
short butspacetype_subtype_prev;
/** Size. */
short winx, winy;
@@ -453,7 +454,6 @@ typedef struct ScrArea {
* runtime variable, updated by executing operators.
*/
short region_active_win;
char _pad[2];
/** Callbacks for this space type. */
struct SpaceType *type;

View File

@@ -484,8 +484,10 @@ typedef struct SpaceGraph {
/** Mode for the Graph editor (eGraphEdit_Mode). */
short mode;
short mode_prev;
/* Snapping now lives on the Scene. */
short autosnap DNA_DEPRECATED;
char _pad[2];
/** Settings for Graph editor (eGraphEdit_Flag). */
int flag;
@@ -495,7 +497,6 @@ typedef struct SpaceGraph {
float cursorVal;
/** Pivot point for transforms. */
int around;
char _pad[4];
SpaceGraph_Runtime runtime;
} SpaceGraph;
@@ -914,7 +915,7 @@ typedef struct SpaceFile {
/** Is this a File Browser or an Asset Browser? */
char browse_mode; /* eFileBrowse_Mode */
char _pad1[1];
char browse_mode_prev;
short tags;
@@ -1609,6 +1610,7 @@ typedef struct SpaceNode {
/* tree type for the current node tree */
char tree_idname[64];
char tree_idname_prev[64];
/** Same as #bNodeTree::type (deprecated). */
int treetype DNA_DEPRECATED;