diff --git a/source/blender/blenkernel/BKE_screen.hh b/source/blender/blenkernel/BKE_screen.hh index 0bc7c18c2e1..8af22490bd2 100644 --- a/source/blender/blenkernel/BKE_screen.hh +++ b/source/blender/blenkernel/BKE_screen.hh @@ -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); diff --git a/source/blender/editors/screen/area.cc b/source/blender/editors/screen/area.cc index cbd03023aac..1d550489eeb 100644 --- a/source/blender/editors/screen/area.cc +++ b/source/blender/editors/screen/area.cc @@ -2602,7 +2602,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(area->spacedata.first); /* store area->type->exit callback */ void (*area_exit)(wmWindowManager *, ScrArea *) = area->type ? area->type->exit : nullptr; @@ -2711,10 +2713,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. */ diff --git a/source/blender/editors/space_action/space_action.cc b/source/blender/editors/space_action/space_action.cc index 1cacc5c1a10..7e41d35f721 100644 --- a/source/blender/editors/space_action/space_action.cc +++ b/source/blender/editors/space_action/space_action.cc @@ -875,15 +875,8 @@ static int action_space_subtype_get(ScrArea *area) static void action_space_subtype_set(ScrArea *area, int value) { SpaceAction *sact = static_cast(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*/, @@ -893,6 +886,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(area->spacedata.first); + return sact->mode_prev; +} + static blender::StringRefNull action_space_name_get(const ScrArea *area) { SpaceAction *sact = static_cast(area->spacedata.first); @@ -941,6 +940,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; diff --git a/source/blender/editors/space_file/space_file.cc b/source/blender/editors/space_file/space_file.cc index e6df554b896..5a4160b0ef2 100644 --- a/source/blender/editors/space_file/space_file.cc +++ b/source/blender/editors/space_file/space_file.cc @@ -825,6 +825,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; } @@ -833,6 +834,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(area->spacedata.first); + return sfile->browse_mode_prev; +} + static blender::StringRefNull file_space_name_get(const ScrArea *area) { SpaceFile *sfile = static_cast(area->spacedata.first); @@ -944,6 +951,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; diff --git a/source/blender/editors/space_graph/space_graph.cc b/source/blender/editors/space_graph/space_graph.cc index facd11643bd..b24312d77d7 100644 --- a/source/blender/editors/space_graph/space_graph.cc +++ b/source/blender/editors/space_graph/space_graph.cc @@ -866,6 +866,7 @@ static int graph_space_subtype_get(ScrArea *area) static void graph_space_subtype_set(ScrArea *area, int value) { SpaceGraph *sgraph = static_cast(area->spacedata.first); + sgraph->mode_prev = sgraph->mode; sgraph->mode = value; } @@ -876,6 +877,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(area->spacedata.first); + return sgraph->mode_prev; +} + static blender::StringRefNull graph_space_name_get(const ScrArea *area) { SpaceGraph *sgraph = static_cast(area->spacedata.first); @@ -938,6 +945,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; diff --git a/source/blender/editors/space_image/space_image.cc b/source/blender/editors/space_image/space_image.cc index 2c44a5d7b50..67ecad803d3 100644 --- a/source/blender/editors/space_image/space_image.cc +++ b/source/blender/editors/space_image/space_image.cc @@ -1063,15 +1063,8 @@ static int image_space_subtype_get(ScrArea *area) static void image_space_subtype_set(ScrArea *area, int value) { SpaceImage *sima = static_cast(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*/, @@ -1081,6 +1074,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(area->spacedata.first); + return sima->mode_prev; +} + static blender::StringRefNull image_space_name_get(const ScrArea *area) { SpaceImage *sima = static_cast(area->spacedata.first); @@ -1158,6 +1157,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; diff --git a/source/blender/editors/space_node/space_node.cc b/source/blender/editors/space_node/space_node.cc index 7a033149c88..dc2f56ce36d 100644 --- a/source/blender/editors/space_node/space_node.cc +++ b/source/blender/editors/space_node/space_node.cc @@ -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(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(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(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; diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h index eb0b1bb239b..b4fcf074c22 100644 --- a/source/blender/makesdna/DNA_screen_types.h +++ b/source/blender/makesdna/DNA_screen_types.h @@ -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; diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index ea89cb1c0f3..3f4308359ed 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -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;