Fix T61136: Header alignment preference has no effect
authorCampbell Barton <ideasman42@gmail.com>
Wed, 6 Feb 2019 10:15:39 +0000 (21:15 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 6 Feb 2019 10:20:15 +0000 (21:20 +1100)
Users expect this to apply to existing files,
adjust this to apply on load, defaults to off.

release/scripts/startup/bl_ui/space_userpref.py
source/blender/blenkernel/BKE_screen.h
source/blender/blenkernel/intern/screen.c
source/blender/blenloader/intern/versioning_userdef.c
source/blender/editors/screen/screen_edit.c
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesrna/intern/rna_userdef.c

index 8db0689ad9cbb305d8b3220dfd22411850a63a73..814e527cbc5e7d1ea2fe87e2af610116f53a240d 100644 (file)
@@ -210,7 +210,7 @@ class USERPREF_PT_interface_editors(PreferencePanel):
 
         flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=False)
 
-        flow.row().prop(view, "header_align_default", expand=True)
+        flow.row().prop(view, "header_align")
         flow.prop(system, "use_region_overlap")
         flow.prop(view, "show_layout_ui", text="Corner Splitting")
         flow.prop(view, "color_picker_type")
index 60cfc15a9284f771a755980cffadf8f71e379ea2..d064929848d508f195c82f2542231fca79a82d01 100644 (file)
@@ -357,4 +357,6 @@ void BKE_screen_remove_double_scredges(struct bScreen *sc);
 void BKE_screen_remove_unused_scredges(struct bScreen *sc);
 void BKE_screen_remove_unused_scrverts(struct bScreen *sc);
 
+void BKE_screen_header_alignment_reset(struct bScreen *screen);
+
 #endif
index 2f1393e43d250a852acb71f77d5b06fe0caa328c..af3384d20234479e4aa7190462ce574561a266fd 100644 (file)
@@ -846,3 +846,19 @@ bool BKE_screen_is_used(const bScreen *screen)
 {
        return (screen->winid != 0);
 }
+
+void BKE_screen_header_alignment_reset(bScreen *screen)
+{
+       int alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP;
+       for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+               for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
+                       if (ar->regiontype == RGN_TYPE_HEADER) {
+                               if (ELEM(sa->spacetype, SPACE_FILE, SPACE_USERPREF, SPACE_OUTLINER, SPACE_BUTS)) {
+                                       ar->alignment = RGN_ALIGN_TOP;
+                                       continue;
+                               }
+                               ar->alignment = alignment;
+                       }
+               }
+       }
+}
index c02f5638452fb32205619e1dbb836bdba36a0bb8..72e4e2d0fe10f3f4bcc34c1c2591d3ffa72c0201 100644 (file)
@@ -455,7 +455,7 @@ void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef)
                        USER_FLAG_DEPRECATED_4);
 
                userdef->uiflag &= ~(
-                       USER_UIFLAG_DEPRECATED_8 |
+                       USER_HEADER_FROM_PREF |
                        USER_UIFLAG_DEPRECATED_12 |
                        USER_UIFLAG_DEPRECATED_22);
        }
index 69a4bde4821ddda77a647c8db45a9abec7d5ed6d..7d76140f741680feb8d082a4c5daac982f8714f8 100644 (file)
@@ -477,6 +477,12 @@ void ED_screens_initialize(Main *bmain, wmWindowManager *wm)
                        ED_screen_set_active_region(NULL, win, &win->eventstate->x);
                }
        }
+
+       if (U.uiflag & USER_HEADER_FROM_PREF) {
+               for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
+                       BKE_screen_header_alignment_reset(screen);
+               }
+       }
 }
 
 void ED_screen_ensure_updated(wmWindowManager *wm, wmWindow *win, bScreen *screen)
index 23bd962760b33de9849ff251e8d7f8c0f36da746..228812cd2431314b906d3da4d2806388f1bbb5f7 100644 (file)
@@ -872,7 +872,8 @@ typedef enum eUserpref_UI_Flag {
        USER_PLAINMENUS             = (1 << 5),
        USER_LOCK_CURSOR_ADJUST     = (1 << 6),
        USER_HEADER_BOTTOM          = (1 << 7),
-       USER_UIFLAG_DEPRECATED_8    = (1 << 8),  /* cleared */
+       /** Otherwise use header alignment from the file. */
+       USER_HEADER_FROM_PREF       = (1 << 8),
        USER_MENUOPENAUTO           = (1 << 9),
        USER_DEPTH_CURSOR           = (1 << 10),
        USER_AUTOPERSP              = (1 << 11),
index 35e7c28647164b0fd68dd8fb7164de4ff7558cb0..b2536ba5cfa9d9e9251104c7972dbc8ddd73d8dd 100644 (file)
@@ -101,6 +101,7 @@ static const EnumPropertyItem rna_enum_studio_light_type_items[] = {
 #include "BKE_mesh_runtime.h"
 #include "BKE_pbvh.h"
 #include "BKE_paint.h"
+#include "BKE_screen.h"
 
 #include "DEG_depsgraph.h"
 
@@ -152,6 +153,16 @@ static void rna_userdef_update_ui(Main *UNUSED(bmain), Scene *UNUSED(scene), Poi
        WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);    /* refresh region sizes */
 }
 
+static void rna_userdef_update_ui_header_default(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+       if (U.uiflag & USER_HEADER_FROM_PREF) {
+               for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
+                       BKE_screen_header_alignment_reset(screen);
+               }
+               rna_userdef_update_ui(bmain, scene, ptr);
+       }
+}
+
 static void rna_userdef_language_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
 {
        BLF_cache_clear();
@@ -3839,16 +3850,17 @@ static void rna_def_userdef_view(BlenderRNA *brna)
                                 "Otherwise menus, etc will always be top to bottom, left to right, "
                                 "no matter opening direction");
 
-       static const EnumPropertyItem header_align_default_items[] = {
-               {0, "TOP", 0, "Top", ""},
-               {USER_HEADER_BOTTOM, "BOTTOM", 0, "Bottom", ""},
+       static const EnumPropertyItem header_align_items[] = {
+               {0, "NONE", 0, "Default", "Keep existing header alignment"},
+               {USER_HEADER_FROM_PREF, "TOP", 0, "Top", "Top aligned on load"},
+               {USER_HEADER_FROM_PREF | USER_HEADER_BOTTOM, "BOTTOM", 0, "Bottom", "Bottom align on load (except for property editors)"},
                {0, NULL, 0, NULL, NULL},
        };
-       prop = RNA_def_property(srna, "header_align_default", PROP_ENUM, PROP_NONE);
-       RNA_def_property_enum_items(prop, header_align_default_items);
+       prop = RNA_def_property(srna, "header_align", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_items(prop, header_align_items);
        RNA_def_property_enum_bitflag_sdna(prop, NULL, "uiflag");
        RNA_def_property_ui_text(prop, "Header Position", "Default header position for new space-types");
-       RNA_def_property_update(prop, 0, "rna_userdef_update");
+       RNA_def_property_update(prop, 0, "rna_userdef_update_ui_header_default");
 
        static const EnumPropertyItem text_hinting_items[] = {
                {0, "AUTO", 0, "Auto", ""},