Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_operators.c
| Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | |||||
| #include "wm.h" | #include "wm.h" | ||||
| #include "wm_draw.h" | #include "wm_draw.h" | ||||
| #include "wm_event_system.h" | #include "wm_event_system.h" | ||||
| #include "wm_event_types.h" | #include "wm_event_types.h" | ||||
| #include "wm_files.h" | #include "wm_files.h" | ||||
| #include "wm_window.h" | #include "wm_window.h" | ||||
| static GHash *global_ops_hash = NULL; | static GHash *global_ops_hash = NULL; | ||||
| /** Counter for operator-properties that should not be tagged with #OP_PROP_TAG_ADVANCED. */ | |||||
| static int ot_prop_basic_count = -1; | |||||
| #define UNDOCUMENTED_OPERATOR_TIP N_("(undocumented operator)") | #define UNDOCUMENTED_OPERATOR_TIP N_("(undocumented operator)") | ||||
| /* ************ operator API, exported ********** */ | /* ************ operator API, exported ********** */ | ||||
| wmOperatorType *WM_operatortype_find(const char *idname, bool quiet) | wmOperatorType *WM_operatortype_find(const char *idname, bool quiet) | ||||
| { | { | ||||
| Show All 29 Lines | |||||
| } | } | ||||
| /** \name Operator Type Append | /** \name Operator Type Append | ||||
| * \{ */ | * \{ */ | ||||
| static wmOperatorType *wm_operatortype_append__begin(void) | static wmOperatorType *wm_operatortype_append__begin(void) | ||||
| { | { | ||||
| wmOperatorType *ot = MEM_callocN(sizeof(wmOperatorType), "operatortype"); | wmOperatorType *ot = MEM_callocN(sizeof(wmOperatorType), "operatortype"); | ||||
| BLI_assert(ot_prop_basic_count == -1); | |||||
| ot->srna = RNA_def_struct_ptr(&BLENDER_RNA, "", &RNA_OperatorProperties); | ot->srna = RNA_def_struct_ptr(&BLENDER_RNA, "", &RNA_OperatorProperties); | ||||
| RNA_def_struct_property_tags(ot->srna, rna_enum_operator_property_tags); | |||||
| /* Set the default i18n context now, so that opfunc can redefine it if needed! */ | /* Set the default i18n context now, so that opfunc can redefine it if needed! */ | ||||
| RNA_def_struct_translation_context(ot->srna, BLT_I18NCONTEXT_OPERATOR_DEFAULT); | RNA_def_struct_translation_context(ot->srna, BLT_I18NCONTEXT_OPERATOR_DEFAULT); | ||||
| ot->translation_context = BLT_I18NCONTEXT_OPERATOR_DEFAULT; | ot->translation_context = BLT_I18NCONTEXT_OPERATOR_DEFAULT; | ||||
| return ot; | return ot; | ||||
| } | } | ||||
| static void wm_operatortype_append__end(wmOperatorType *ot) | static void wm_operatortype_append__end(wmOperatorType *ot) | ||||
| { | { | ||||
| if (ot->name == NULL) { | if (ot->name == NULL) { | ||||
| fprintf(stderr, "ERROR: Operator %s has no name property!\n", ot->idname); | fprintf(stderr, "ERROR: Operator %s has no name property!\n", ot->idname); | ||||
| ot->name = N_("Dummy Name"); | ot->name = N_("Dummy Name"); | ||||
| } | } | ||||
| /* Allow calling _begin without _end in operatortype creation. Also tags all props as advanced by default. */ | |||||
| WM_operatortype_props_advanced_end(ot); | |||||
| /* XXX All ops should have a description but for now allow them not to. */ | /* XXX All ops should have a description but for now allow them not to. */ | ||||
| RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description : UNDOCUMENTED_OPERATOR_TIP); | RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description : UNDOCUMENTED_OPERATOR_TIP); | ||||
| RNA_def_struct_identifier(&BLENDER_RNA, ot->srna, ot->idname); | RNA_def_struct_identifier(&BLENDER_RNA, ot->srna, ot->idname); | ||||
| BLI_ghash_insert(global_ops_hash, (void *)ot->idname, ot); | BLI_ghash_insert(global_ops_hash, (void *)ot->idname, ot); | ||||
| } | } | ||||
| /* all ops in 1 list (for time being... needs evaluation later) */ | /* all ops in 1 list (for time being... needs evaluation later) */ | ||||
| ▲ Show 20 Lines • Show All 338 Lines • ▼ Show 20 Lines | for (WM_operatortype_iter(&iter); | ||||
| if (ot->last_properties) { | if (ot->last_properties) { | ||||
| IDP_FreeProperty(ot->last_properties); | IDP_FreeProperty(ot->last_properties); | ||||
| MEM_freeN(ot->last_properties); | MEM_freeN(ot->last_properties); | ||||
| ot->last_properties = NULL; | ot->last_properties = NULL; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Tag all operator-properties of \a ot defined after calling this with | |||||
| * #OP_PROP_TAG_ADVANCED. Previously defined ones are not touched. | |||||
| * | |||||
| * Calling this multiple times without a call to #WM_operatortype_props_advanced_end, | |||||
| * all calls after the first one are ignored. Meaning all propereties defined after the | |||||
| * first call are tagged as advanced. | |||||
| * | |||||
| * This doesn't do the actual tagging, #WM_operatortype_props_advanced_end does which is | |||||
| * called for all operators during registration (see #wm_operatortype_append__end). | |||||
| */ | |||||
| void WM_operatortype_props_advanced_begin(wmOperatorType *ot) | |||||
| { | |||||
| if (ot_prop_basic_count == -1) { /* Don't do anything if _begin was called before, but not _end */ | |||||
| ot_prop_basic_count = RNA_struct_count_properties(ot->srna); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Tags all operator-properties of \ot defined since the first #WM_operatortype_props_advanced_begin | |||||
| * call, or the last #WM_operatortype_props_advanced_end call, with #OP_PROP_TAG_ADVANCED. | |||||
| * Note that this is called for all operators during registration (see #wm_operatortype_append__end). | |||||
| * So it does not need to be explicitly called in operator-type definition. | |||||
| */ | |||||
| void WM_operatortype_props_advanced_end(wmOperatorType *ot) | |||||
| { | |||||
| PointerRNA struct_ptr; | |||||
| int counter = 0; | |||||
| if (ot_prop_basic_count == -1) { | |||||
| /* WM_operatortype_props_advanced_begin was not called. Don't do anything. */ | |||||
| return; | |||||
| } | |||||
| RNA_pointer_create(NULL, ot->srna, NULL, &struct_ptr); | |||||
| RNA_STRUCT_BEGIN (&struct_ptr, prop) | |||||
| { | |||||
| counter++; | |||||
| if (counter > ot_prop_basic_count) { | |||||
| WM_operatortype_prop_tag(prop, OP_PROP_TAG_ADVANCED); | |||||
| } | |||||
| } | |||||
| RNA_STRUCT_END; | |||||
| ot_prop_basic_count = -1; | |||||
| } | |||||
| /* SOME_OT_op -> some.op */ | /* SOME_OT_op -> some.op */ | ||||
| void WM_operator_py_idname(char *to, const char *from) | void WM_operator_py_idname(char *to, const char *from) | ||||
| { | { | ||||
| const char *sep = strstr(from, "_OT_"); | const char *sep = strstr(from, "_OT_"); | ||||
| if (sep) { | if (sep) { | ||||
| int ofs = (sep - from); | int ofs = (sep - from); | ||||
| /* note, we use ascii tolower instead of system tolower, because the | /* note, we use ascii tolower instead of system tolower, because the | ||||
| ▲ Show 20 Lines • Show All 3,527 Lines • Show Last 20 Lines | |||||