generic operator menu was searching for "type" and using the first enum property if it wasnt found.

this is too arbitrary and could break if roperty order is changed.
store the property in the operator type that is to be used for menu and enum search func's.

python function for searching operator enums on invoke. (just need dynamic python enums now)
 wm.invoke_search_popup(self)
This commit is contained in:
2010-01-15 22:40:33 +00:00
parent 2b3a6b38b7
commit 5272991e8b
33 changed files with 159 additions and 118 deletions

View File

@@ -144,18 +144,42 @@ static void rna_Operator_report(wmOperator *op, int type, char *msg)
BKE_report(op->reports, type, msg);
}
/* since event isnt needed... */
static int rna_Operator_enum_search_invoke(bContext *C, wmOperator *op)
{
WM_enum_search_invoke(C, op, NULL);
}
#else
static void rna_generic_op_invoke(FunctionRNA *func, int use_event, int use_ret)
{
PropertyRNA *parm;
RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT);
parm= RNA_def_pointer(func, "operator", "Operator", "", "Operator to call.");
RNA_def_property_flag(parm, PROP_REQUIRED);
if(use_event) {
parm= RNA_def_pointer(func, "event", "Event", "", "Event.");
RNA_def_property_flag(parm, PROP_REQUIRED);
}
if(use_ret) {
parm= RNA_def_enum(func, "result", operator_return_items, 0, "result", "");
RNA_def_property_flag(parm, PROP_ENUM_FLAG);
RNA_def_function_return(func, parm);
}
}
void RNA_api_wm(StructRNA *srna)
{
FunctionRNA *func;
PropertyRNA *parm;
func= RNA_def_function(srna, "add_fileselect", "WM_event_add_fileselect");
RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Show up the file selector.");
parm= RNA_def_pointer(func, "operator", "Operator", "", "Operator to call.");
RNA_def_property_flag(parm, PROP_REQUIRED);
rna_generic_op_invoke(func, 0, 0);
func= RNA_def_function(srna, "add_keyconfig", "WM_keyconfig_add");
parm= RNA_def_string(func, "name", "", 0, "Name", "");
@@ -165,24 +189,17 @@ void RNA_api_wm(StructRNA *srna)
/* invoke functions, for use with python */
func= RNA_def_function(srna, "invoke_props_popup", "WM_operator_props_popup");
RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Operator popup invoke.");
parm= RNA_def_pointer(func, "operator", "Operator", "", "Operator to call.");
RNA_def_property_flag(parm, PROP_REQUIRED);
parm= RNA_def_pointer(func, "event", "Event", "", "Event.");
RNA_def_property_flag(parm, PROP_REQUIRED);
parm= RNA_def_enum(func, "result", operator_return_items, 0, "result", ""); // better name?
RNA_def_property_flag(parm, PROP_ENUM_FLAG);
RNA_def_function_return(func, parm);
rna_generic_op_invoke(func, 1, 1);
/* invoke enum */
func= RNA_def_function(srna, "invoke_search_popup", "rna_Operator_enum_search_invoke");
rna_generic_op_invoke(func, 0, 1);
/* invoke functions, for use with python */
func= RNA_def_function(srna, "invoke_popup", "WM_operator_ui_popup");
RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Operator popup invoke.");
parm= RNA_def_pointer(func, "operator", "Operator", "", "Operator to call.");
RNA_def_property_flag(parm, PROP_REQUIRED);
rna_generic_op_invoke(func, 0, 0);
parm= RNA_def_int(func, "width", 300, 0, INT_MAX, "", "Width of the popup.", 0, INT_MAX);
parm= RNA_def_int(func, "height", 20, 0, INT_MAX, "", "Height of the popup.", 0, INT_MAX);
}