[Bf-blender-cvs] [34743b1dfaa] userpref_redesign: UI: Move User-Preferences navigation tabs to a sidebar region

Julian Eisel noreply at git.blender.org
Fri Feb 23 11:08:16 CET 2018


Commit: 34743b1dfaa9a184305426a84c5c3fa0d64a392a
Author: Julian Eisel
Date:   Thu Feb 22 12:45:14 2018 +0100
Branches: userpref_redesign
https://developer.blender.org/rB34743b1dfaa9a184305426a84c5c3fa0d64a392a

UI: Move User-Preferences navigation tabs to a sidebar region

This is the first commit for a bigger User-Preferences redesign, see T54115.

===================================================================

M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/blenkernel/BKE_screen.h
M	source/blender/blenkernel/intern/screen.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/editors/space_userpref/space_userpref.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 6db538eacef..c1f3329129f 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -75,10 +75,10 @@ class USERPREF_HT_header(Header):
             layout.operator("wm.theme_install")
 
 
-class USERPREF_PT_tabs(Panel):
+class USERPREF_PT_navigation(Panel):
     bl_label = ""
     bl_space_type = 'USER_PREFERENCES'
-    bl_region_type = 'WINDOW'
+    bl_region_type = 'UI'
     bl_options = {'HIDE_HEADER'}
 
     def draw(self, context):
@@ -86,7 +86,9 @@ class USERPREF_PT_tabs(Panel):
 
         userpref = context.user_preferences
 
-        layout.row().prop(userpref, "active_section", expand=True)
+        col = layout.column()
+
+        col.prop(userpref, "active_section", expand=True)
 
 
 class USERPREF_MT_interaction_presets(Menu):
@@ -1582,7 +1584,7 @@ class USERPREF_PT_addons(Panel):
 
 classes = (
     USERPREF_HT_header,
-    USERPREF_PT_tabs,
+    USERPREF_PT_navigation,
     USERPREF_MT_interaction_presets,
     USERPREF_MT_templates_splash,
     USERPREF_MT_app_templates,
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 6669f3103da..0f8e7e9106d 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -293,6 +293,10 @@ void BKE_spacedata_freelist(ListBase *lb);
 void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2);
 void BKE_spacedata_draw_locks(int set);
 
+struct ARegion *BKE_spacedata_find_region_type(
+        const struct SpaceLink *slink, const struct ScrArea *area,
+        int region_type) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
+
 void BKE_spacedata_callback_id_remap_set(void (*func)(struct ScrArea *, struct SpaceLink *, struct ID *, struct ID *));
 void BKE_spacedata_id_unref(struct ScrArea *sa, struct SpaceLink *sl, struct ID *id);
 
@@ -304,7 +308,7 @@ void            BKE_screen_area_free(struct ScrArea *sa);
 void BKE_region_callback_free_manipulatormap_set(void (*callback)(struct wmManipulatorMap *));
 void BKE_region_callback_refresh_tag_manipulatormap_set(void (*callback)(struct wmManipulatorMap *));
 
-struct ARegion *BKE_area_find_region_type(struct ScrArea *sa, int type);
+struct ARegion *BKE_area_find_region_type(const struct ScrArea *sa, int type);
 struct ARegion *BKE_area_find_region_active_win(struct ScrArea *sa);
 struct ARegion *BKE_area_find_region_xy(struct ScrArea *sa, const int regiontype, int x, int y);
 struct ScrArea *BKE_screen_find_area_from_space(struct bScreen *sc, struct SpaceLink *sl) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2);
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index a985fb9275a..259da8c35e0 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -278,6 +278,30 @@ void BKE_spacedata_draw_locks(int set)
 	}
 }
 
+/**
+ * Version of #BKE_area_find_region_type that also works if \a slink is not the active space of \a area.
+ */
+ARegion *BKE_spacedata_find_region_type(const SpaceLink *slink, const ScrArea *area, int region_type)
+{
+	const bool is_slink_active = slink == area->spacedata.first;
+	const ListBase *regionbase = (is_slink_active) ?
+	                           &area->regionbase : &slink->regionbase;
+	ARegion *region = NULL;
+
+	BLI_assert(BLI_findindex(&area->spacedata, slink) != -1);
+	for (region = regionbase->first; region; region = region->next) {
+		if (region->regiontype == region_type) {
+			break;
+		}
+	}
+
+	/* Should really unit test this instead. */
+	BLI_assert(!is_slink_active || region == BKE_area_find_region_type(area, region_type));
+
+	return region;
+}
+
+
 static void (*spacedata_id_remap_cb)(struct ScrArea *sa, struct SpaceLink *sl, ID *old_id, ID *new_id) = NULL;
 
 void BKE_spacedata_callback_id_remap_set(void (*func)(ScrArea *sa, SpaceLink *sl, ID *, ID *))
@@ -455,17 +479,21 @@ unsigned int BKE_screen_visible_layers(bScreen *screen, Scene *scene)
 
 /* ***************** Utilities ********************** */
 
-/* Find a region of the specified type from the given area */
-ARegion *BKE_area_find_region_type(ScrArea *sa, int type)
+/**
+ * Find a region of type \a region_type in the currently active space of \a area.
+ *
+ * \note This does __not__ work if the region to look up is not in the active
+ *       space. Use #BKE_spacedata_find_region_type if that may be the case.
+ */
+ARegion *BKE_area_find_region_type(const ScrArea *area, int region_type)
 {
-	if (sa) {
-		ARegion *ar;
-		
-		for (ar = sa->regionbase.first; ar; ar = ar->next) {
-			if (ar->regiontype == type)
-				return ar;
+	if (area) {
+		for (ARegion *region = area->regionbase.first; region; region = region->next) {
+			if (region->regiontype == region_type)
+				return region;
 		}
 	}
+
 	return NULL;
 }
 
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 46021a8b502..781814a3db0 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -52,6 +52,7 @@
 #include "DNA_genfile.h"
 #include "DNA_workspace_types.h"
 
+#include "BKE_screen.h"
 #include "BKE_collection.h"
 #include "BKE_customdata.h"
 #include "BKE_freestyle.h"
@@ -939,4 +940,27 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
 			}
 		}
 	}
+
+	{
+		for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
+			for (ScrArea *area = screen->areabase.first; area; area = area->next) {
+				for (SpaceLink *slink = area->spacedata.first; slink; slink = slink->next) {
+					if (slink->spacetype == SPACE_USERPREF) {
+						ARegion *navigation_region = BKE_spacedata_find_region_type(slink, area, RGN_TYPE_UI);
+
+						if (!navigation_region) {
+							ListBase *regionbase = (slink == area->spacedata.first) ?
+							                           &area->regionbase : &slink->regionbase;
+
+							navigation_region = MEM_callocN(sizeof(ARegion), "userpref navigation-region do_versions");
+
+							BLI_addhead(regionbase, navigation_region); /* order matters, addhead not addtail! */
+							navigation_region->regiontype = RGN_TYPE_UI;
+							navigation_region->alignment = RGN_ALIGN_LEFT;
+						}
+					}
+				}
+			}
+		}
+	}
 }
diff --git a/source/blender/editors/space_userpref/space_userpref.c b/source/blender/editors/space_userpref/space_userpref.c
index f640fe63f93..58b934b7f59 100644
--- a/source/blender/editors/space_userpref/space_userpref.c
+++ b/source/blender/editors/space_userpref/space_userpref.c
@@ -47,6 +47,8 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
+#include "UI_interface.h"
+
 
 
 /* ******************** default callbacks for userpref space ***************** */
@@ -59,6 +61,13 @@ static SpaceLink *userpref_new(const bContext *UNUSED(C))
 	spref = MEM_callocN(sizeof(SpaceUserPref), "inituserpref");
 	spref->spacetype = SPACE_USERPREF;
 
+	/* navigation region */
+	ar = MEM_callocN(sizeof(ARegion), "navigation region for userpref");
+
+	BLI_addtail(&spref->regionbase, ar);
+	ar->regiontype = RGN_TYPE_UI;
+	ar->alignment = RGN_ALIGN_LEFT;
+
 	/* header */
 	ar = MEM_callocN(sizeof(ARegion), "header for userpref");
 
@@ -136,6 +145,19 @@ static void userpref_header_region_draw(const bContext *C, ARegion *ar)
 	ED_region_header(C, ar);
 }
 
+/* add handlers, stuff you only do once or on area/region changes */
+static void userpref_navigation_region_init(wmWindowManager *wm, ARegion *ar)
+{
+	ar->v2d.scroll = V2D_SCROLL_RIGHT | V2D_SCROLL_VERTICAL_HIDE;
+
+	ED_region_panels_init(wm, ar);
+}
+
+static void userpref_navigation_region_draw(const bContext *C, ARegion *ar)
+{
+	ED_region_panels(C, ar, NULL, -1, true);
+}
+
 static void userpref_main_region_listener(
         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar),
         wmNotifier *UNUSED(wmn), const Scene *UNUSED(scene))
@@ -156,6 +178,13 @@ static void userpref_header_listener(
 #endif
 }
 
+static void userpref_navigation_region_listener(
+        bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar),
+        wmNotifier *UNUSED(wmn), const Scene *UNUSED(scene))
+{
+	/* context changes */
+}
+
 /* only called once, from space/spacetypes.c */
 void ED_spacetype_userpref(void)
 {
@@ -193,6 +222,17 @@ void ED_spacetype_userpref(void)
 
 	BLI_addhead(&st->regiontypes, art);
 
+	/* regions: navigation window */
+	art = MEM_callocN(sizeof(ARegionType), "spacetype userpref region");
+	art->regionid = RGN_TYPE_UI;
+	art->prefsizex = UI_COMPACT_PANEL_WIDTH;
+	art->init = userpref_navigation_region_init;
+	art->draw = userpref_navigation_region_draw;
+	art->listener = userpref_navigation_region_listener;
+	art->keymapflag = ED_KEYMAP_UI;
+
+	BLI_addhead(&st->regiontypes, art);
+
 
 	BKE_spacetype_register(st);
 }



More information about the Bf-blender-cvs mailing list