Fix T59137: Prefs moves header to bottom

Only use a new spaces header alignment when no previous header exists.
This commit is contained in:
Campbell Barton 2018-12-14 09:07:22 +11:00
parent cb6d018ec9
commit 26c8e09cff
Notes: blender-bot 2023-02-14 09:29:42 +01:00
Referenced by issue #59340, Python custom Operators fail to Undo properly if executed while in edit mode
Referenced by issue #59137, User Preferences editor moves header to bottom.
2 changed files with 26 additions and 17 deletions

View File

@ -149,6 +149,7 @@ void ED_area_newspace(struct bContext *C, ScrArea *sa, int type, const bool s
void ED_area_prevspace(struct bContext *C, ScrArea *sa);
void ED_area_swapspace(struct bContext *C, ScrArea *sa1, ScrArea *sa2);
int ED_area_headersize(void);
int ED_area_header_alignment_or_fallback(const ScrArea *area, int fallback);
int ED_area_header_alignment(const ScrArea *area);
int ED_area_global_size_y(const ScrArea *area);
int ED_area_global_min_size_y(const ScrArea *area);

View File

@ -1816,11 +1816,17 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exi
/* When the user switches between space-types from the type-selector,
* changing the header-type is jarring (especially when using Ctrl-MouseWheel).
*
* However, add-on install for example -forces the header to the top which shouldn't
* However, add-on install for example, forces the header to the top which shouldn't
* be applied back to the previous space type when closing - see: T57724
*
* Newly created windows wont have any space data, use the alignment
* the space type defaults to in this case instead
* (needed for preferences to have space-type on bottom).
*/
const bool sync_header_alignment = (sa->flag & AREA_FLAG_TEMP_TYPE) == 0;
int header_alignment = ED_area_header_alignment(sa);
int header_alignment = ED_area_header_alignment_or_fallback(sa, -1);
const bool sync_header_alignment = (
(header_alignment != -1) &&
(sa->flag & AREA_FLAG_TEMP_TYPE) == 0);
/* in some cases (opening temp space) we don't want to
* call area exit callback, so we temporarily unset it */
@ -1869,17 +1875,6 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exi
/* put in front of list */
BLI_remlink(&sa->spacedata, sl);
BLI_addhead(&sa->spacedata, sl);
/* Sync header alignment. */
if (sync_header_alignment) {
for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
if (ar->regiontype == RGN_TYPE_HEADER) {
ar->alignment = header_alignment;
break;
}
}
}
}
else {
/* new space */
@ -1897,6 +1892,16 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exi
}
}
/* Sync header alignment. */
if (sync_header_alignment) {
for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
if (ar->regiontype == RGN_TYPE_HEADER) {
ar->alignment = header_alignment;
break;
}
}
}
ED_area_initialize(CTX_wm_manager(C), win, sa);
/* tell WM to refresh, cursor types etc */
@ -2498,16 +2503,19 @@ int ED_area_headersize(void)
return (int)(HEADERY * UI_DPI_FAC);
}
int ED_area_header_alignment(const ScrArea *area)
int ED_area_header_alignment_or_fallback(const ScrArea *area, int fallback)
{
for (ARegion *ar = area->regionbase.first; ar; ar = ar->next) {
if (ar->regiontype == RGN_TYPE_HEADER) {
return ar->alignment;
}
}
return fallback;
}
return RGN_ALIGN_TOP;
int ED_area_header_alignment(const ScrArea *area)
{
return ED_area_header_alignment_or_fallback(area, RGN_ALIGN_TOP);
}
/**