Cleanup: de-dup popup/pie menu RNA definition

Also rename pupmenu -> popmenu
This commit is contained in:
Campbell Barton 2018-04-22 10:49:45 +02:00
parent 46a9038f60
commit 420e379e99
3 changed files with 19 additions and 27 deletions

View File

@ -137,12 +137,12 @@ class WindowManager(bpy_types.ID):
def popup_menu(self, draw_func, title="", icon='NONE'):
import bpy
popup = self.pupmenu_begin__internal(title, icon)
popup = self.popmenu_begin__internal(title, icon)
try:
draw_func(popup, bpy.context)
finally:
self.pupmenu_end__internal(popup)
self.popmenu_end__internal(popup)
def popup_menu_pie(self, event, draw_func, title="", icon='NONE'):
import bpy

View File

@ -1830,44 +1830,36 @@ static void rna_def_timer(BlenderRNA *brna)
RNA_define_verify_sdna(1); /* not in sdna */
}
static void rna_def_popupmenu(BlenderRNA *brna)
static void rna_def_popup_menu_wrapper(
BlenderRNA *brna, const char *rna_type, const char *c_type, const char *layout_get_fn)
{
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "UIPopupMenu", NULL);
RNA_def_struct_ui_text(srna, "PopupMenu", "");
RNA_def_struct_sdna(srna, "uiPopupMenu");
srna = RNA_def_struct(brna, rna_type, NULL);
/* UI name isn't visible, name same as type. */
RNA_def_struct_ui_text(srna, rna_type, "");
RNA_def_struct_sdna(srna, c_type);
RNA_define_verify_sdna(0); /* not in sdna */
/* could wrap more, for now this is enough */
prop = RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "UILayout");
RNA_def_property_pointer_funcs(prop, "rna_PopupMenu_layout_get",
RNA_def_property_pointer_funcs(prop, layout_get_fn,
NULL, NULL, NULL);
RNA_define_verify_sdna(1); /* not in sdna */
}
static void rna_def_popupmenu(BlenderRNA *brna)
{
rna_def_popup_menu_wrapper(brna, "UIPopupMenu", "uiPopupMenu", "rna_PopupMenu_layout_get");
}
static void rna_def_piemenu(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "UIPieMenu", NULL);
RNA_def_struct_ui_text(srna, "PieMenu", "");
RNA_def_struct_sdna(srna, "uiPieMenu");
RNA_define_verify_sdna(0); /* not in sdna */
/* could wrap more, for now this is enough */
prop = RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "UILayout");
RNA_def_property_pointer_funcs(prop, "rna_PieMenu_layout_get",
NULL, NULL, NULL);
RNA_define_verify_sdna(1); /* not in sdna */
rna_def_popup_menu_wrapper(brna, "UIPieMenu", "uiPieMenu", "rna_PieMenu_layout_get");
}
static void rna_def_window_stereo3d(BlenderRNA *brna)

View File

@ -298,7 +298,7 @@ static void rna_KeyConfig_remove(wmWindowManager *wm, ReportList *reports, Point
}
/* popup menu wrapper */
static PointerRNA rna_PupMenuBegin(bContext *C, const char *title, int icon)
static PointerRNA rna_PopMenuBegin(bContext *C, const char *title, int icon)
{
PointerRNA r_ptr;
void *data;
@ -310,7 +310,7 @@ static PointerRNA rna_PupMenuBegin(bContext *C, const char *title, int icon)
return r_ptr;
}
static void rna_PupMenuEnd(bContext *C, PointerRNA *handle)
static void rna_PopMenuEnd(bContext *C, PointerRNA *handle)
{
UI_popup_menu_end(C, handle->data);
}
@ -479,7 +479,7 @@ void RNA_api_wm(StructRNA *srna)
/* wrap UI_popup_menu_begin */
func = RNA_def_function(srna, "pupmenu_begin__internal", "rna_PupMenuBegin");
func = RNA_def_function(srna, "popmenu_begin__internal", "rna_PopMenuBegin");
RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT);
parm = RNA_def_string(func, "title", NULL, 0, "", "");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
@ -491,7 +491,7 @@ void RNA_api_wm(StructRNA *srna)
RNA_def_function_return(func, parm);
/* wrap UI_popup_menu_end */
func = RNA_def_function(srna, "pupmenu_end__internal", "rna_PupMenuEnd");
func = RNA_def_function(srna, "popmenu_end__internal", "rna_PopMenuEnd");
RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT);
parm = RNA_def_pointer(func, "menu", "UIPopupMenu", "", "");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_RNAPTR);