Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_operators.c
| Show First 20 Lines • Show All 1,831 Lines • ▼ Show 20 Lines | |||||
| /* Developers note: in it's current form this doesn't need to be an operator, | /* Developers note: in it's current form this doesn't need to be an operator, | ||||
| * keep this as-is for now since it may end up setting an active key-map. | * keep this as-is for now since it may end up setting an active key-map. | ||||
| */ | */ | ||||
| static int wm_operator_tool_set_exec(bContext *C, wmOperator *op) | static int wm_operator_tool_set_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| bToolDef tool_def = {{0}}; | bToolRef_Runtime tref_rt = {{0}}; | ||||
| bToolKey tkey = { .space_type = -1, .mode = -1}; | |||||
| { | { | ||||
| WorkSpace *workspace = CTX_wm_workspace(C); | |||||
| Scene *scene = CTX_data_scene(C); | |||||
| PropertyRNA *prop = RNA_struct_find_property(op->ptr, "space_type"); | PropertyRNA *prop = RNA_struct_find_property(op->ptr, "space_type"); | ||||
| if (RNA_property_is_set(op->ptr, prop)) { | if (RNA_property_is_set(op->ptr, prop)) { | ||||
| tool_def.spacetype = RNA_property_enum_get(op->ptr, prop); | tkey.space_type = RNA_property_enum_get(op->ptr, prop); | ||||
| tkey.mode = WM_toolsystem_mode_from_spacetype(workspace, scene, sa, tkey.space_type); | |||||
| } | } | ||||
| else { | else { | ||||
| if (sa == NULL) { | if (sa == NULL) { | ||||
| BKE_report(op->reports, RPT_ERROR, "Space type not set"); | BKE_report(op->reports, RPT_ERROR, "Space type not set"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| tool_def.spacetype = sa->spacetype; | if (!WM_toolsystem_key_from_context(workspace, scene, sa, &tkey)) { | ||||
| BKE_report(op->reports, RPT_ERROR, "Context has no tool support"); | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| tool_def.index = RNA_int_get(op->ptr, "index"); | char idname[64]; | ||||
| RNA_string_get(op->ptr, "keymap", tool_def.keymap); | RNA_string_get(op->ptr, "name", idname); | ||||
| RNA_string_get(op->ptr, "manipulator_group", tool_def.manipulator_group); | |||||
| RNA_string_get(op->ptr, "data_block", tool_def.data_block); | tref_rt.index = RNA_int_get(op->ptr, "index"); | ||||
| RNA_string_get(op->ptr, "keymap", tref_rt.keymap); | |||||
| RNA_string_get(op->ptr, "manipulator_group", tref_rt.manipulator_group); | |||||
| RNA_string_get(op->ptr, "data_block", tref_rt.data_block); | |||||
| WM_toolsystem_set(C, &tkey, &tref_rt, idname); | |||||
| WM_toolsystem_set(C, &tool_def); | |||||
| /* For some reason redraw fails with menus (even though 'ar' isn't the menu's region). */ | /* For some reason redraw fails with menus (even though 'ar' isn't the menu's region). */ | ||||
| if (sa) { | if (sa) { | ||||
| ED_area_tag_redraw(sa); | ED_area_tag_redraw(sa); | ||||
| } | } | ||||
| else { | else { | ||||
| WM_event_add_notifier(C, NC_WINDOW, NULL); | WM_event_add_notifier(C, NC_WINDOW, NULL); | ||||
| } | } | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| static void WM_OT_tool_set(wmOperatorType *ot) | static void WM_OT_tool_set(wmOperatorType *ot) | ||||
| { | { | ||||
| ot->name = "Set Active Tool"; | ot->name = "Set Active Tool"; | ||||
| ot->idname = "WM_OT_tool_set"; | ot->idname = "WM_OT_tool_set"; | ||||
| ot->description = "Set the active tool"; | ot->description = "Set the active tool"; | ||||
| ot->exec = wm_operator_tool_set_exec; | ot->exec = wm_operator_tool_set_exec; | ||||
| ot->flag = OPTYPE_INTERNAL; | ot->flag = OPTYPE_INTERNAL; | ||||
| /* Used only to store the default tool. */ | |||||
| RNA_def_string(ot->srna, "name", NULL, KMAP_MAX_NAME, "Name", ""); | |||||
| RNA_def_enum(ot->srna, "space_type", rna_enum_space_type_items + 1, SPACE_EMPTY, "Space Type", ""); | RNA_def_enum(ot->srna, "space_type", rna_enum_space_type_items + 1, SPACE_EMPTY, "Space Type", ""); | ||||
| /* TODO: mode */ | |||||
| RNA_def_string(ot->srna, "keymap", NULL, KMAP_MAX_NAME, "Key Map", ""); | RNA_def_string(ot->srna, "keymap", NULL, KMAP_MAX_NAME, "Key Map", ""); | ||||
| RNA_def_string(ot->srna, "manipulator_group", NULL, MAX_NAME, "Manipulator Group", ""); | RNA_def_string(ot->srna, "manipulator_group", NULL, MAX_NAME, "Manipulator Group", ""); | ||||
| RNA_def_string(ot->srna, "data_block", NULL, MAX_NAME, "Data Block", ""); | RNA_def_string(ot->srna, "data_block", NULL, MAX_NAME, "Data Block", ""); | ||||
| RNA_def_int(ot->srna, "index", 0, INT_MIN, INT_MAX, "Index", "", INT_MIN, INT_MAX); | RNA_def_int(ot->srna, "index", 0, INT_MIN, INT_MAX, "Index", "", INT_MIN, INT_MAX); | ||||
| } | } | ||||
| #endif /* USE_WORKSPACE_TOOL */ | #endif /* USE_WORKSPACE_TOOL */ | ||||
| /* ***************** Splash Screen ************************* */ | /* ***************** Splash Screen ************************* */ | ||||
| ▲ Show 20 Lines • Show All 2,302 Lines • Show Last 20 Lines | |||||