Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-12-19 05:21:41 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-12-19 05:30:18 +0300
commit7ba1489bd7235a333a4f99040b3c9e7501bf346c (patch)
tree5eeea838eb15f131b4c59033b1c89170e40af248 /source
parentf98e2c0427c1dc5e2f1cac58cfb43b464013a33b (diff)
Cleanup: use 'context' to make panels show in their section
All panels were calling poll to draw in their section causing a lot of repeated boiler plate poll functions. Also rename 'PreferencePanel' to 'CenterAlignMixIn' since this is it's purpose.
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/space_userpref/space_userpref.c28
-rw-r--r--source/blender/makesrna/RNA_enum_types.h1
-rw-r--r--source/blender/makesrna/intern/rna_userdef.c28
3 files changed, 39 insertions, 18 deletions
diff --git a/source/blender/editors/space_userpref/space_userpref.c b/source/blender/editors/space_userpref/space_userpref.c
index a42ab048907..731c8a3028e 100644
--- a/source/blender/editors/space_userpref/space_userpref.c
+++ b/source/blender/editors/space_userpref/space_userpref.c
@@ -35,6 +35,9 @@
#include "ED_screen.h"
#include "ED_space_api.h"
+#include "RNA_access.h"
+#include "RNA_enum_types.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -119,9 +122,27 @@ static void userpref_main_region_init(wmWindowManager *wm, ARegion *ar)
ED_region_panels_init(wm, ar);
}
-static void userpref_main_region_draw(const bContext *C, ARegion *ar)
+static void userpref_main_region_layout(const bContext *C, ARegion *ar)
{
- ED_region_panels_ex(C, ar, NULL, U.space_data.section_active, true);
+ char id_lower[64];
+ const char *contexts[2] = {id_lower, NULL};
+
+ /* Avoid duplicating identifiers, use existing RNA enum. */
+ {
+ const EnumPropertyItem *items = rna_enum_preference_section_items;
+ int i = RNA_enum_from_value(items, U.space_data.section_active);
+ /* File is from the future. */
+ if (i == -1) {
+ i = 0;
+ }
+ const char *id = items[i].identifier;
+ BLI_assert(strlen(id) < sizeof(id_lower));
+ STRNCPY(id_lower, id);
+ BLI_str_tolower_ascii(id_lower, strlen(id_lower));
+ }
+
+ ED_region_panels_layout_ex(
+ C, ar, &ar->type->paneltypes, contexts, U.space_data.section_active, true, NULL);
}
static void userpref_operatortypes(void)
@@ -225,7 +246,8 @@ void ED_spacetype_userpref(void)
art = MEM_callocN(sizeof(ARegionType), "spacetype userpref region");
art->regionid = RGN_TYPE_WINDOW;
art->init = userpref_main_region_init;
- art->draw = userpref_main_region_draw;
+ art->layout = userpref_main_region_layout;
+ art->draw = ED_region_panels_draw;
art->listener = userpref_main_region_listener;
art->keymapflag = ED_KEYMAP_UI;
diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h
index 318522427d8..d7f6ec1fb5a 100644
--- a/source/blender/makesrna/RNA_enum_types.h
+++ b/source/blender/makesrna/RNA_enum_types.h
@@ -219,6 +219,7 @@ extern const EnumPropertyItem rna_enum_abc_compression_items[];
extern const EnumPropertyItem rna_enum_context_mode_items[];
extern const EnumPropertyItem rna_enum_curveprofile_preset_items[];
+extern const EnumPropertyItem rna_enum_preference_section_items[];
/* API calls */
int rna_node_tree_type_to_enum(struct bNodeTreeType *typeinfo);
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index f1aaa13fcf5..ed89faf69cf 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -69,7 +69,7 @@ static const EnumPropertyItem opensubdiv_compute_type_items[] = {
};
#endif
-static const EnumPropertyItem preference_section_items[] = {
+const EnumPropertyItem rna_enum_preference_section_items[] = {
{USER_SECTION_INTERFACE, "INTERFACE", 0, "Interface", ""},
{USER_SECTION_THEME, "THEMES", 0, "Themes", ""},
{USER_SECTION_VIEWPORT, "VIEWPORT", 0, "Viewport", ""},
@@ -92,6 +92,8 @@ static const EnumPropertyItem preference_section_items[] = {
{USER_SECTION_SYSTEM, "SYSTEM", 0, "System", ""},
{USER_SECTION_SAVE_LOAD, "SAVE_LOAD", 0, "Save & Load", ""},
{USER_SECTION_FILE_PATHS, "FILE_PATHS", 0, "File Paths", ""},
+ {0, "", 0, NULL, NULL},
+ {USER_SECTION_EXPERIMENTAL, "EXPERIMENTAL", 0, "Experimental", ""},
{0, NULL, 0, NULL, NULL},
};
@@ -468,26 +470,22 @@ static const EnumPropertyItem *rna_UseDef_active_section_itemf(bContext *UNUSED(
{
UserDef *userdef = ptr->data;
- if ((userdef->flag & USER_DEVELOPER_UI) == 0) {
+ if ((userdef->flag & USER_DEVELOPER_UI) != 0) {
*r_free = false;
- return preference_section_items;
+ return rna_enum_preference_section_items;
}
EnumPropertyItem *items = NULL;
int totitem = 0;
- RNA_enum_items_add(&items, &totitem, preference_section_items);
- RNA_enum_item_add_separator(&items, &totitem);
-
- EnumPropertyItem item = {
- .value = USER_SECTION_EXPERIMENTAL,
- .name = "Experimental",
- .identifier = "EXPERIMENTAL",
- .icon = 0,
- .description = "",
- };
+ for (const EnumPropertyItem *it = rna_enum_preference_section_items; it->identifier != NULL;
+ it++) {
+ if (it->value == USER_SECTION_EXPERIMENTAL) {
+ continue;
+ }
+ RNA_enum_item_add(&items, &totitem, it);
+ }
- RNA_enum_item_add(&items, &totitem, &item);
RNA_enum_item_end(&items, &totitem);
*r_free = true;
@@ -5942,7 +5940,7 @@ void RNA_def_userdef(BlenderRNA *brna)
prop = RNA_def_property(srna, "active_section", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "space_data.section_active");
- RNA_def_property_enum_items(prop, preference_section_items);
+ RNA_def_property_enum_items(prop, rna_enum_preference_section_items);
RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_UseDef_active_section_itemf");
RNA_def_property_ui_text(
prop, "Active Section", "Active section of the preferences shown in the user interface");