[Bf-blender-cvs] [8a661f5dd15] soc-2020-custom-menus: Custom Menu: display items of QF in preferences
TempoDev
noreply at git.blender.org
Sun Jun 7 19:26:42 CEST 2020
Commit: 8a661f5dd15bee4fa68bcd82f84ff999f76a6831
Author: TempoDev
Date: Sun Jun 7 19:26:30 2020 +0200
Branches: soc-2020-custom-menus
https://developer.blender.org/rB8a661f5dd15bee4fa68bcd82f84ff999f76a6831
Custom Menu: display items of QF in preferences
===================================================================
M release/scripts/modules/rna_custom_menu_ui.py
M release/scripts/startup/bl_operators/userpref.py
M release/scripts/startup/bl_ui/space_userpref.py
M source/blender/makesrna/intern/rna_userdef.c
===================================================================
diff --git a/release/scripts/modules/rna_custom_menu_ui.py b/release/scripts/modules/rna_custom_menu_ui.py
index e6ef7d9312d..44f39c9a198 100644
--- a/release/scripts/modules/rna_custom_menu_ui.py
+++ b/release/scripts/modules/rna_custom_menu_ui.py
@@ -177,7 +177,6 @@ def draw_custom_menu(context, layout):
rowsub = split.row(align=True)
rowsub.prop(cm, "cm_space_selected", text="")
-
rowsub = split.row(align=True)
rowsub.prop(cm, "cm_context_selected", text="")
@@ -201,4 +200,11 @@ def draw_custom_menu(context, layout):
col = layout.column()
rowsub = row.split(factor=0.4, align=True)
+ item_index = 0
+ active = cm.refresh(context=cm.cm_context_selected, index=0, spacetype=cm.cm_space_selected)
+ while active != "":
+ col.label(text=active)
+ item_index = item_index + 1
+ active = cm.refresh(context=cm.cm_context_selected, index=item_index, spacetype=cm.cm_space_selected)
+
layout.separator()
diff --git a/release/scripts/startup/bl_operators/userpref.py b/release/scripts/startup/bl_operators/userpref.py
index 4743dc68712..521fdaa175f 100644
--- a/release/scripts/startup/bl_operators/userpref.py
+++ b/release/scripts/startup/bl_operators/userpref.py
@@ -1138,6 +1138,9 @@ class PREFERENCES_OT_studiolight_show(Operator):
bpy.ops.screen.userpref_show('INVOKE_DEFAULT')
return {'FINISHED'}
+# -----------------------------------------------------------------------------
+# Custom Menus Operators
+
class PREFERENCES_OT_custommenu_select(Operator):
bl_idname = "preferences.custommenu_select"
bl_label = "select custom menu to edit"
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 4feba212c58..94d0f5bdecd 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -1646,7 +1646,7 @@ class KeymapPanel:
class USERPREF_MT_keyconfigs(Menu):
bl_label = "KeyPresets"
preset_subdir = "keyconfig"
- preset_operator = "preferences.custommenu_select"
+ preset_operator = "preferences.keyconfig_activate"
def draw(self, context):
Menu.draw_preset(self, context)
@@ -1684,22 +1684,6 @@ class USERPREF_MT_menu_select(Menu):
def draw(self, context):
Menu.draw_preset(self, context)
-class USERPREF_MT_menu_space_select(Menu):
- bl_label = "Menu select"
- preset_subdir = "custom_menu_editor"
- preset_operator = "preferences.custommenu_select"
-
- def draw(self, context):
- Menu.draw_preset(self, context)
-
-class USERPREF_MT_menu_space_select(Menu):
- bl_label = "Menu select"
- preset_subdir = "custom_menu_editor"
- preset_operator = "preferences.custommenu_select"
-
- def draw(self, context):
- Menu.draw_preset(self, context)
-
class USERPREF_PT_custom_menu(CustomMenuPanel, Panel):
bl_label = "custom_menu"
bl_options = {'HIDE_HEADER'}
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index 2897923acad..4dcba82ec5f 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -185,6 +185,7 @@ static const EnumPropertyItem rna_enum_userdef_viewport_aa_items[] = {
# include "BKE_paint.h"
# include "BKE_pbvh.h"
# include "BKE_screen.h"
+# include "BKE_blender_user_menu.h"
# include "DEG_depsgraph.h"
@@ -793,7 +794,8 @@ static const EnumPropertyItem *rna_userdef_spacetypes_itemf(bContext *UNUSED(C),
SpaceType *st = NULL;
for (i = 0, st = spacetypes->first; st; st = st->next, i++) {
- EnumPropertyItem new_item = {i, st->name, 0, st->name, st->name};
+ int id = st->spaceid;
+ EnumPropertyItem new_item = {id, st->name, 0, st->name, st->name};
RNA_enum_item_add(&item, &totitem, &new_item);
}
@@ -1139,10 +1141,36 @@ static void rna_UserDef_studiolight_light_ambient_get(PointerRNA *ptr, float *va
static void rna_userdef_cm_space_selected_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
- BKE_sound_init(bmain);
USERDEF_TAG_DIRTY;
}
+static const char *rna_CustomMenus_refresh(UserDef *userdef, const char *spacetype, const char *context, int index)
+{
+ int i = 0;
+ const ListBase *spacetypes = BKE_spacetypes_list();
+ SpaceType *st = NULL;
+
+ for (i = 0, st = spacetypes->first; st; st = st->next, i++) {
+ int id = st->spaceid;
+ char *space_name = st->name;
+ if (!strcmp(space_name, spacetype))
+ break;
+ }
+ if (st == NULL) return "";
+
+ bUserMenu *bum = BKE_blender_user_menu_find(&userdef->user_menus, st->spaceid, context);
+ if (!bum) return "";
+
+ ListBase *lb = &bum->items;
+ i = 0;
+ for (bUserMenuItem *umi = lb->first; umi; umi = umi->next, i++) {
+ if (i == index)
+ return umi->ui_name;
+ }
+
+ return "";
+}
+
#else
# define USERDEF_TAG_DIRTY_PROPERTY_UPDATE_ENABLE \
@@ -5962,8 +5990,9 @@ static void rna_def_userdef_keymap(BlenderRNA *brna)
static void rna_def_userdef_custom_menu(BlenderRNA *brna)
{
PropertyRNA *prop;
+ FunctionRNA *func;
+ PropertyRNA *parm;
- //U.user_menus.
static const EnumPropertyItem custom_menu_space_default_items[] = {
{0, "NULL", 0, "None", "No spacetypes found"},
{0, NULL, 0, NULL, NULL},
@@ -6004,6 +6033,34 @@ static void rna_def_userdef_custom_menu(BlenderRNA *brna)
RNA_def_property_ui_text(
prop, "context selected", "the context selected");
RNA_def_property_update(prop, 0, "rna_userdef_cm_space_selected_update");
+
+ func = RNA_def_function(srna, "refresh", "rna_CustomMenus_refresh");
+ RNA_def_function_ui_description(func, "Refresh custom menu editor");
+ parm = RNA_def_string(func,
+ "spacetype",
+ NULL,
+ 0,
+ "SpaceType",
+ "space type of the menu");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ parm = RNA_def_string(func,
+ "context",
+ NULL,
+ 0,
+ "Context",
+ "context of the menu");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ parm = RNA_def_int(func, "index", 0, 0, 100, "Index", "index of the item in list", 0, 100);
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ parm = RNA_def_string(func,
+ "user_menu",
+ NULL,
+ 0,
+ "",
+ "active user menu");
+ //parm = RNA_def_pointer(func, "user_menu", "bUserMenu", "", "found user menu");
+ RNA_def_function_return(func, parm);
+
}
static void rna_def_userdef_filepaths(BlenderRNA *brna)
More information about the Bf-blender-cvs
mailing list