4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2007 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
35 #include "DNA_object_types.h"
36 #include "DNA_screen_types.h"
37 #include "DNA_scene_types.h"
38 #include "DNA_userdef_types.h"
39 #include "DNA_windowmanager_types.h"
41 #include "MEM_guardedalloc.h"
47 #include "BLI_blenlib.h"
48 #include "BLI_dynstr.h" /*for WM_operator_pystring */
51 #include "BLO_readfile.h"
53 #include "BKE_blender.h"
54 #include "BKE_context.h"
55 #include "BKE_depsgraph.h"
56 #include "BKE_idprop.h"
57 #include "BKE_library.h"
58 #include "BKE_global.h"
60 #include "BKE_report.h"
61 #include "BKE_scene.h"
62 #include "BKE_screen.h" /* BKE_ST_MAXNAME */
63 #include "BKE_utildefines.h"
66 #include "BIF_glutil.h" /* for paint cursor */
68 #include "IMB_imbuf_types.h"
70 #include "ED_screen.h"
73 #include "RNA_access.h"
74 #include "RNA_define.h"
76 #include "UI_interface.h"
77 #include "UI_resources.h"
84 #include "wm_event_system.h"
85 #include "wm_event_types.h"
86 #include "wm_subwindow.h"
87 #include "wm_window.h"
91 static ListBase global_ops= {NULL, NULL};
93 /* ************ operator API, exported ********** */
96 wmOperatorType *WM_operatortype_find(const char *idname, int quiet)
100 char idname_bl[OP_MAX_TYPENAME]; // XXX, needed to support python style names without the _OT_ syntax
101 WM_operator_bl_idname(idname_bl, idname);
104 for(ot= global_ops.first; ot; ot= ot->next) {
105 if(strncmp(ot->idname, idname_bl, OP_MAX_TYPENAME)==0)
111 printf("search for unknown operator %s, %s\n", idname_bl, idname);
116 wmOperatorType *WM_operatortype_exists(const char *idname)
120 char idname_bl[OP_MAX_TYPENAME]; // XXX, needed to support python style names without the _OT_ syntax
121 WM_operator_bl_idname(idname_bl, idname);
124 for(ot= global_ops.first; ot; ot= ot->next) {
125 if(strncmp(ot->idname, idname_bl, OP_MAX_TYPENAME)==0)
132 wmOperatorType *WM_operatortype_first(void)
134 return global_ops.first;
137 /* all ops in 1 list (for time being... needs evaluation later) */
138 void WM_operatortype_append(void (*opfunc)(wmOperatorType*))
142 ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
143 ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
147 static char dummy_name[] = "Dummy Name";
148 fprintf(stderr, "ERROR: Operator %s has no name property!\n", ot->idname);
149 ot->name= dummy_name;
152 RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description:"(undocumented operator)"); // XXX All ops should have a description but for now allow them not to.
153 RNA_def_struct_identifier(ot->srna, ot->idname);
154 BLI_addtail(&global_ops, ot);
157 void WM_operatortype_append_ptr(void (*opfunc)(wmOperatorType*, void*), void *userdata)
161 ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
162 ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
163 opfunc(ot, userdata);
164 RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description:"(undocumented operator)");
165 RNA_def_struct_identifier(ot->srna, ot->idname);
166 BLI_addtail(&global_ops, ot);
169 /* ********************* macro operator ******************** */
175 static void wm_macro_start(wmOperator *op)
177 if (op->customdata == NULL) {
178 op->customdata = MEM_callocN(sizeof(MacroData), "MacroData");
182 static int wm_macro_end(wmOperator *op, int retval)
184 if (retval & OPERATOR_CANCELLED) {
185 MacroData *md = op->customdata;
187 if (md->retval & OPERATOR_FINISHED) {
188 retval |= OPERATOR_FINISHED;
189 retval &= ~OPERATOR_CANCELLED;
193 /* if modal is ending, free custom data */
194 if (retval & (OPERATOR_FINISHED|OPERATOR_CANCELLED)) {
195 if (op->customdata) {
196 MEM_freeN(op->customdata);
197 op->customdata = NULL;
204 /* macro exec only runs exec calls */
205 static int wm_macro_exec(bContext *C, wmOperator *op)
208 int retval= OPERATOR_FINISHED;
212 for(opm= op->macro.first; opm; opm= opm->next) {
214 if(opm->type->exec) {
215 retval= opm->type->exec(C, opm);
217 if (retval & OPERATOR_FINISHED) {
218 MacroData *md = op->customdata;
219 md->retval = OPERATOR_FINISHED; /* keep in mind that at least one operator finished */
221 break; /* operator didn't finish, end macro */
226 return wm_macro_end(op, retval);
229 int wm_macro_invoke_internal(bContext *C, wmOperator *op, wmEvent *event, wmOperator *opm)
231 int retval= OPERATOR_FINISHED;
233 /* start from operator received as argument */
234 for( ; opm; opm= opm->next) {
235 if(opm->type->invoke)
236 retval= opm->type->invoke(C, opm, event);
237 else if(opm->type->exec)
238 retval= opm->type->exec(C, opm);
240 if (retval & OPERATOR_FINISHED) {
241 MacroData *md = op->customdata;
242 md->retval = OPERATOR_FINISHED; /* keep in mind that at least one operator finished */
244 break; /* operator didn't finish, end macro */
248 return wm_macro_end(op, retval);
251 static int wm_macro_invoke(bContext *C, wmOperator *op, wmEvent *event)
254 return wm_macro_invoke_internal(C, op, event, op->macro.first);
257 static int wm_macro_modal(bContext *C, wmOperator *op, wmEvent *event)
259 wmOperator *opm = op->opm;
260 int retval= OPERATOR_FINISHED;
263 printf("macro error, calling NULL modal()\n");
265 retval = opm->type->modal(C, opm, event);
267 /* if this one is done but it's not the last operator in the macro */
268 if ((retval & OPERATOR_FINISHED) && opm->next) {
269 MacroData *md = op->customdata;
271 md->retval = OPERATOR_FINISHED; /* keep in mind that at least one operator finished */
273 retval = wm_macro_invoke_internal(C, op, event, opm->next);
275 /* if new operator is modal and also added its own handler */
276 if (retval & OPERATOR_RUNNING_MODAL && op->opm != opm) {
277 wmWindow *win = CTX_wm_window(C);
278 wmEventHandler *handler = NULL;
280 for (handler = win->modalhandlers.first; handler; handler = handler->next) {
281 /* first handler in list is the new one */
282 if (handler->op == op)
287 BLI_remlink(&win->modalhandlers, handler);
288 wm_event_free_handler(handler);
291 /* if operator is blocking, grab cursor
292 * This may end up grabbing twice, but we don't care.
294 if(op->opm->type->flag & OPTYPE_BLOCKING) {
295 int bounds[4] = {-1,-1,-1,-1};
296 int wrap = (U.uiflag & USER_CONTINUOUS_MOUSE) && ((op->opm->flag & OP_GRAB_POINTER) || (op->opm->type->flag & OPTYPE_GRAB_POINTER));
299 ARegion *ar= CTX_wm_region(C);
301 bounds[0]= ar->winrct.xmin;
302 bounds[1]= ar->winrct.ymax;
303 bounds[2]= ar->winrct.xmax;
304 bounds[3]= ar->winrct.ymin;
308 WM_cursor_grab(CTX_wm_window(C), wrap, FALSE, bounds);
314 return wm_macro_end(op, retval);
317 static int wm_macro_cancel(bContext *C, wmOperator *op)
319 /* call cancel on the current modal operator, if any */
320 if (op->opm && op->opm->type->cancel) {
321 op->opm->type->cancel(C, op->opm);
324 return wm_macro_end(op, OPERATOR_CANCELLED);
327 /* Names have to be static for now */
328 wmOperatorType *WM_operatortype_append_macro(char *idname, char *name, int flag)
332 if(WM_operatortype_exists(idname)) {
333 printf("Macro error: operator %s exists\n", idname);
337 ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
338 ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
342 ot->flag= OPTYPE_MACRO|flag;
344 ot->exec= wm_macro_exec;
345 ot->invoke= wm_macro_invoke;
346 ot->modal= wm_macro_modal;
347 ot->cancel= wm_macro_cancel;
351 ot->description= "(undocumented operator)";
353 RNA_def_struct_ui_text(ot->srna, ot->name, ot->description); // XXX All ops should have a description but for now allow them not to.
354 RNA_def_struct_identifier(ot->srna, ot->idname);
356 BLI_addtail(&global_ops, ot);
361 void WM_operatortype_append_macro_ptr(void (*opfunc)(wmOperatorType*, void*), void *userdata)
365 ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
366 ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
368 ot->flag= OPTYPE_MACRO;
369 ot->exec= wm_macro_exec;
370 ot->invoke= wm_macro_invoke;
371 ot->modal= wm_macro_modal;
372 ot->cancel= wm_macro_cancel;
376 ot->description= "(undocumented operator)";
378 opfunc(ot, userdata);
380 RNA_def_struct_ui_text(ot->srna, ot->name, ot->description);
381 RNA_def_struct_identifier(ot->srna, ot->idname);
383 BLI_addtail(&global_ops, ot);
386 wmOperatorTypeMacro *WM_operatortype_macro_define(wmOperatorType *ot, const char *idname)
388 wmOperatorTypeMacro *otmacro= MEM_callocN(sizeof(wmOperatorTypeMacro), "wmOperatorTypeMacro");
390 BLI_strncpy(otmacro->idname, idname, OP_MAX_TYPENAME);
392 /* do this on first use, since operatordefinitions might have been not done yet */
393 WM_operator_properties_alloc(&(otmacro->ptr), &(otmacro->properties), idname);
395 BLI_addtail(&ot->macro, otmacro);
398 wmOperatorType *otsub = WM_operatortype_find(idname, 0);
399 RNA_def_pointer_runtime(ot->srna, otsub->idname, otsub->srna,
400 otsub->name, otsub->description);
406 static void wm_operatortype_free_macro(wmOperatorType *ot)
408 wmOperatorTypeMacro *otmacro;
410 for(otmacro= ot->macro.first; otmacro; otmacro= otmacro->next) {
412 WM_operator_properties_free(otmacro->ptr);
413 MEM_freeN(otmacro->ptr);
416 BLI_freelistN(&ot->macro);
420 int WM_operatortype_remove(const char *idname)
422 wmOperatorType *ot = WM_operatortype_find(idname, 0);
427 BLI_remlink(&global_ops, ot);
428 RNA_struct_free(&BLENDER_RNA, ot->srna);
431 wm_operatortype_free_macro(ot);
438 /* SOME_OT_op -> some.op */
439 void WM_operator_py_idname(char *to, const char *from)
441 char *sep= strstr(from, "_OT_");
443 int i, ofs= (sep-from);
446 to[i]= tolower(from[i]);
449 BLI_strncpy(to+(ofs+1), sep+4, OP_MAX_TYPENAME);
452 /* should not happen but support just incase */
453 BLI_strncpy(to, from, OP_MAX_TYPENAME);
457 /* some.op -> SOME_OT_op */
458 void WM_operator_bl_idname(char *to, const char *from)
461 char *sep= strchr(from, '.');
464 int i, ofs= (sep-from);
467 to[i]= toupper(from[i]);
469 BLI_strncpy(to+ofs, "_OT_", OP_MAX_TYPENAME);
470 BLI_strncpy(to+(ofs+4), sep+1, OP_MAX_TYPENAME);
473 /* should not happen but support just incase */
474 BLI_strncpy(to, from, OP_MAX_TYPENAME);
481 /* print a string representation of the operator, with the args that it runs
482 * so python can run it again,
484 * When calling from an existing wmOperator do.
485 * WM_operator_pystring(op->type, op->ptr);
487 char *WM_operator_pystring(bContext *C, wmOperatorType *ot, PointerRNA *opptr, int all_args)
489 const char *arg_name= NULL;
490 char idname_py[OP_MAX_TYPENAME];
492 PropertyRNA *prop, *iterprop;
494 /* for building the string */
495 DynStr *dynstr= BLI_dynstr_new();
497 int first_iter=1, ok= 1;
500 /* only to get the orginal props for comparisons */
501 PointerRNA opptr_default;
502 PropertyRNA *prop_default;
504 if(all_args==0 || opptr==NULL) {
505 WM_operator_properties_create_ptr(&opptr_default, ot);
508 opptr = &opptr_default;
512 WM_operator_py_idname(idname_py, ot->idname);
513 BLI_dynstr_appendf(dynstr, "bpy.ops.%s(", idname_py);
515 iterprop= RNA_struct_iterator_property(opptr->type);
517 RNA_PROP_BEGIN(opptr, propptr, iterprop) {
519 arg_name= RNA_property_identifier(prop);
521 if (strcmp(arg_name, "rna_type")==0) continue;
523 buf= RNA_property_as_string(C, opptr, prop);
528 /* not verbose, so only add in attributes that use non-default values
529 * slow but good for tooltips */
530 prop_default= RNA_struct_find_property(&opptr_default, arg_name);
533 buf_default= RNA_property_as_string(C, &opptr_default, prop_default);
535 if(strcmp(buf, buf_default)==0)
536 ok= 0; /* values match, dont bother printing */
538 MEM_freeN(buf_default);
543 BLI_dynstr_appendf(dynstr, first_iter?"%s=%s":", %s=%s", arg_name, buf);
552 if(all_args==0 || opptr==&opptr_default )
553 WM_operator_properties_free(&opptr_default);
555 BLI_dynstr_append(dynstr, ")");
557 cstring = BLI_dynstr_get_cstring(dynstr);
558 BLI_dynstr_free(dynstr);
562 void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot)
564 RNA_pointer_create(NULL, ot->srna, NULL, ptr);
567 void WM_operator_properties_create(PointerRNA *ptr, const char *opstring)
569 wmOperatorType *ot= WM_operatortype_find(opstring, 0);
572 WM_operator_properties_create_ptr(ptr, ot);
574 RNA_pointer_create(NULL, &RNA_OperatorProperties, NULL, ptr);
577 /* similar to the function above except its uses ID properties
578 * used for keymaps and macros */
579 void WM_operator_properties_alloc(PointerRNA **ptr, IDProperty **properties, const char *opstring)
581 if(*properties==NULL) {
582 IDPropertyTemplate val = {0};
583 *properties= IDP_New(IDP_GROUP, val, "wmOpItemProp");
587 *ptr= MEM_callocN(sizeof(PointerRNA), "wmOpItemPtr");
588 WM_operator_properties_create(*ptr, opstring);
591 (*ptr)->data= *properties;
596 void WM_operator_properties_free(PointerRNA *ptr)
598 IDProperty *properties= ptr->data;
601 IDP_FreeProperty(properties);
602 MEM_freeN(properties);
606 /* ************ default op callbacks, exported *********** */
608 /* invoke callback, uses enum property named "type" */
609 int WM_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
611 PropertyRNA *prop= op->type->prop;
616 printf("WM_menu_invoke: %s has no enum property set\n", op->type->idname);
618 else if (RNA_property_type(prop) != PROP_ENUM) {
619 printf("WM_menu_invoke: %s \"%s\" is not an enum property\n", op->type->idname, RNA_property_identifier(prop));
621 else if (RNA_property_is_set(op->ptr, RNA_property_identifier(prop))) {
622 return op->type->exec(C, op);
625 pup= uiPupMenuBegin(C, op->type->name, 0);
626 layout= uiPupMenuLayout(pup);
627 uiItemsFullEnumO(layout, op->type->idname, (char*)RNA_property_identifier(prop), op->ptr->data, WM_OP_EXEC_REGION_WIN, 0);
628 uiPupMenuEnd(C, pup);
631 return OPERATOR_CANCELLED;
635 /* generic enum search invoke popup */
636 static void operator_enum_search_cb(const struct bContext *C, void *arg_ot, char *str, uiSearchItems *items)
638 wmOperatorType *ot = (wmOperatorType *)arg_ot;
639 PropertyRNA *prop= ot->prop;
642 printf("WM_enum_search_invoke: %s has no enum property set\n", ot->idname);
644 else if (RNA_property_type(prop) != PROP_ENUM) {
645 printf("WM_enum_search_invoke: %s \"%s\" is not an enum property\n", ot->idname, RNA_property_identifier(prop));
650 EnumPropertyItem *item, *item_array;
653 RNA_pointer_create(NULL, ot->srna, NULL, &ptr);
654 RNA_property_enum_items((bContext *)C, &ptr, prop, &item_array, NULL, &free);
656 for(item= item_array; item->identifier; item++) {
657 /* note: need to give the intex rather then the dientifier because the enum can be freed */
658 if(BLI_strcasestr(item->name, str))
659 if(0==uiSearchItemAdd(items, item->name, SET_INT_IN_POINTER(item->value), 0))
664 MEM_freeN(item_array);
668 static void operator_enum_call_cb(struct bContext *C, void *arg1, void *arg2)
670 wmOperatorType *ot= arg1;
673 PointerRNA props_ptr;
674 WM_operator_properties_create_ptr(&props_ptr, ot);
675 RNA_property_enum_set(&props_ptr, ot->prop, GET_INT_FROM_POINTER(arg2));
676 WM_operator_name_call(C, ot->idname, WM_OP_EXEC_DEFAULT, &props_ptr);
677 WM_operator_properties_free(&props_ptr);
681 static uiBlock *wm_enum_search_menu(bContext *C, ARegion *ar, void *arg_op)
683 static char search[256]= "";
685 wmWindow *win= CTX_wm_window(C);
688 wmOperator *op= (wmOperator *)arg_op;
690 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
691 uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT);
693 //uiDefBut(block, LABEL, 0, op->type->name, 10, 10, 180, 19, NULL, 0.0, 0.0, 0, 0, ""); // ok, this isnt so easy...
694 but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 10, 180, 19, 0, 0, "");
695 uiButSetSearchFunc(but, operator_enum_search_cb, op->type, operator_enum_call_cb, NULL);
697 /* fake button, it holds space for search items */
698 uiDefBut(block, LABEL, 0, "", 10, 10 - uiSearchBoxhHeight(), 180, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
700 uiPopupBoundsBlock(block, 6.0f, 0, -20); /* move it downwards, mouse over button */
701 uiEndBlock(C, block);
703 event= *(win->eventstate); /* XXX huh huh? make api call */
704 event.type= EVT_BUT_OPEN;
706 event.customdata= but;
707 event.customdatafree= FALSE;
708 wm_event_add(win, &event);
714 int WM_enum_search_invoke(bContext *C, wmOperator *op, wmEvent *event)
716 uiPupBlock(C, wm_enum_search_menu, op);
717 return OPERATOR_CANCELLED;
720 /* Can't be used as an invoke directly, needs message arg (can be NULL) */
721 int WM_operator_confirm_message(bContext *C, wmOperator *op, char *message)
725 IDProperty *properties= op->ptr->data;
727 if(properties && properties->len)
728 properties= IDP_CopyProperty(op->ptr->data);
732 pup= uiPupMenuBegin(C, "OK?", ICON_QUESTION);
733 layout= uiPupMenuLayout(pup);
734 uiItemFullO(layout, message, 0, op->type->idname, properties, WM_OP_EXEC_REGION_WIN, 0);
735 uiPupMenuEnd(C, pup);
737 return OPERATOR_CANCELLED;
741 int WM_operator_confirm(bContext *C, wmOperator *op, wmEvent *event)
743 return WM_operator_confirm_message(C, op, NULL);
746 /* op->invoke, opens fileselect if path property not set, otherwise executes */
747 int WM_operator_filesel(bContext *C, wmOperator *op, wmEvent *event)
749 if (RNA_property_is_set(op->ptr, "path")) {
750 return WM_operator_call(C, op);
753 WM_event_add_fileselect(C, op);
754 return OPERATOR_RUNNING_MODAL;
758 /* default properties for fileselect */
759 void WM_operator_properties_filesel(wmOperatorType *ot, int filter, short type)
763 RNA_def_string_file_path(ot->srna, "path", "", FILE_MAX, "File Path", "Path to file.");
764 RNA_def_string_file_name(ot->srna, "filename", "", FILE_MAX, "File Name", "Name of the file.");
765 RNA_def_string_dir_path(ot->srna, "directory", "", FILE_MAX, "Directory", "Directory of the file.");
767 prop= RNA_def_boolean(ot->srna, "filter_blender", (filter & BLENDERFILE), "Filter .blend files", "");
768 RNA_def_property_flag(prop, PROP_HIDDEN);
769 prop= RNA_def_boolean(ot->srna, "filter_image", (filter & IMAGEFILE), "Filter image files", "");
770 RNA_def_property_flag(prop, PROP_HIDDEN);
771 prop= RNA_def_boolean(ot->srna, "filter_movie", (filter & MOVIEFILE), "Filter movie files", "");
772 RNA_def_property_flag(prop, PROP_HIDDEN);
773 prop= RNA_def_boolean(ot->srna, "filter_python", (filter & PYSCRIPTFILE), "Filter python files", "");
774 RNA_def_property_flag(prop, PROP_HIDDEN);
775 prop= RNA_def_boolean(ot->srna, "filter_font", (filter & FTFONTFILE), "Filter font files", "");
776 RNA_def_property_flag(prop, PROP_HIDDEN);
777 prop= RNA_def_boolean(ot->srna, "filter_sound", (filter & SOUNDFILE), "Filter sound files", "");
778 RNA_def_property_flag(prop, PROP_HIDDEN);
779 prop= RNA_def_boolean(ot->srna, "filter_text", (filter & TEXTFILE), "Filter text files", "");
780 RNA_def_property_flag(prop, PROP_HIDDEN);
781 prop= RNA_def_boolean(ot->srna, "filter_btx", (filter & BTXFILE), "Filter btx files", "");
782 RNA_def_property_flag(prop, PROP_HIDDEN);
783 prop= RNA_def_boolean(ot->srna, "filter_folder", (filter & FOLDERFILE), "Filter folders", "");
784 RNA_def_property_flag(prop, PROP_HIDDEN);
786 prop= RNA_def_int(ot->srna, "filemode", type, FILE_LOADLIB, FILE_SPECIAL,
787 "File Browser Mode", "The setting for the file browser mode to load a .blend file, a library or a special file.",
788 FILE_LOADLIB, FILE_SPECIAL);
789 RNA_def_property_flag(prop, PROP_HIDDEN);
792 void WM_operator_properties_select_all(wmOperatorType *ot) {
793 static EnumPropertyItem select_all_actions[] = {
794 {SEL_TOGGLE, "TOGGLE", 0, "Toggle", "Toggle selection for all elements"},
795 {SEL_SELECT, "SELECT", 0, "Select", "Select all elements"},
796 {SEL_DESELECT, "DESELECT", 0, "Deselect", "Deselect all elements"},
797 {SEL_INVERT, "INVERT", 0, "Invert", "Invert selection of all elements"},
798 {0, NULL, 0, NULL, NULL}
801 RNA_def_enum(ot->srna, "action", select_all_actions, SEL_TOGGLE, "Action", "Selection action to execute");
804 void WM_operator_properties_gesture_border(wmOperatorType *ot, int extend)
806 RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX);
807 RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX);
808 RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX);
809 RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX);
810 RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX);
813 RNA_def_boolean(ot->srna, "extend", 1, "Extend", "Extend selection instead of deselecting everything first.");
818 int WM_operator_winactive(bContext *C)
820 if(CTX_wm_window(C)==NULL) return 0;
825 static void redo_cb(bContext *C, void *arg_op, int event)
827 wmOperator *lastop= arg_op;
830 ED_undo_pop_op(C, lastop);
831 WM_operator_repeat(C, lastop);
835 static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op)
837 wmWindowManager *wm= CTX_wm_manager(C);
838 wmOperator *op= arg_op;
842 uiStyle *style= U.uistyles.first;
843 int columns= 2, width= 300;
846 block= uiBeginBlock(C, ar, "redo_popup", UI_EMBOSS);
847 uiBlockClearFlag(block, UI_BLOCK_LOOP);
848 uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT);
849 uiBlockSetHandleFunc(block, redo_cb, arg_op);
851 if(!op->properties) {
852 IDPropertyTemplate val = {0};
853 op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
856 // XXX - hack, only for editing docs
857 if(strcmp(op->type->idname, "WM_OT_doc_edit")==0) {
862 RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
863 layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, width, 20, style);
864 uiItemL(layout, op->type->name, 0);
868 op->type->ui((bContext*)C, op);
872 uiDefAutoButsRNA(C, layout, &ptr, columns);
874 uiPopupBoundsBlock(block, 4.0f, 0, 0);
875 uiEndBlock(C, block);
881 static uiBlock *wm_operator_create_ui(bContext *C, ARegion *ar, void *userData)
883 struct { wmOperator *op; int width; int height; } * data = userData;
884 wmWindowManager *wm= CTX_wm_manager(C);
885 wmOperator *op= data->op;
889 uiStyle *style= U.uistyles.first;
891 block= uiBeginBlock(C, ar, "opui_popup", UI_EMBOSS);
892 uiBlockClearFlag(block, UI_BLOCK_LOOP);
893 uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT);
895 if(!op->properties) {
896 IDPropertyTemplate val = {0};
897 op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
900 RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
901 layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, data->width, data->height, style);
905 op->type->ui((bContext*)C, op);
909 uiPopupBoundsBlock(block, 4.0f, 0, 0);
910 uiEndBlock(C, block);
915 int WM_operator_props_popup(bContext *C, wmOperator *op, wmEvent *event)
917 int retval= OPERATOR_CANCELLED;
920 retval= op->type->exec(C, op);
922 if(retval != OPERATOR_CANCELLED)
923 uiPupBlock(C, wm_block_create_redo, op);
928 void WM_operator_ui_popup(bContext *C, wmOperator *op, int width, int height)
930 struct { wmOperator *op; int width; int height; } data;
933 data.height = height;
934 uiPupBlock(C, wm_operator_create_ui, &data);
937 int WM_operator_redo_popup(bContext *C, wmOperator *op)
939 uiPupBlock(C, wm_block_create_redo, op);
941 return OPERATOR_CANCELLED;
944 /* ***************** Debug menu ************************* */
946 static uiBlock *wm_block_create_menu(bContext *C, ARegion *ar, void *arg_op)
948 wmOperator *op= arg_op;
951 uiStyle *style= U.uistyles.first;
953 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
954 uiBlockClearFlag(block, UI_BLOCK_LOOP);
955 uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT);
957 layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 300, 20, style);
958 uiItemL(layout, op->type->name, 0);
966 uiDefAutoButsRNA(C, layout, op->ptr, 2);
968 uiPopupBoundsBlock(block, 4.0f, 0, 0);
969 uiEndBlock(C, block);
974 static int wm_debug_menu_exec(bContext *C, wmOperator *op)
976 G.rt= RNA_int_get(op->ptr, "debugval");
977 ED_screen_refresh(CTX_wm_manager(C), CTX_wm_window(C));
978 WM_event_add_notifier(C, NC_WINDOW, NULL);
980 return OPERATOR_FINISHED;
983 static int wm_debug_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
986 RNA_int_set(op->ptr, "debugval", G.rt);
988 /* pass on operator, so return modal */
989 uiPupBlockOperator(C, wm_block_create_menu, op, WM_OP_EXEC_DEFAULT);
991 return OPERATOR_RUNNING_MODAL;
994 static void WM_OT_debug_menu(wmOperatorType *ot)
996 ot->name= "Debug Menu";
997 ot->idname= "WM_OT_debug_menu";
998 ot->description= "Open a popup to set the debug level.";
1000 ot->invoke= wm_debug_menu_invoke;
1001 ot->exec= wm_debug_menu_exec;
1002 ot->poll= WM_operator_winactive;
1004 RNA_def_int(ot->srna, "debugval", 0, -10000, 10000, "Debug Value", "", INT_MIN, INT_MAX);
1008 /* ***************** Splash Screen ************************* */
1010 static void wm_block_splash_close(bContext *C, void *arg_block, void *arg_unused)
1012 uiPupBlockClose(C, arg_block);
1015 static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *arg_unused)
1019 uiLayout *layout, *split, *col;
1020 uiStyle *style= U.uistyles.first;
1021 struct RecentFile *recent;
1024 #ifdef NAN_BUILDINFO
1025 int ver_width, rev_width;
1026 char *version_str = NULL;
1027 char *revision_str = NULL;
1028 char version_buf[128];
1029 char revision_buf[128];
1030 extern char * build_rev;
1033 version_str = &version_buf[0];
1034 revision_str = &revision_buf[0];
1036 sprintf(version_str, "%d.%02d.%d", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION);
1037 sprintf(revision_str, "r%s", build_rev);
1039 /* here on my system I get ugly double quotes around the revision number.
1040 * if so, clip it off: */
1041 cp = strchr(revision_str, '"');
1043 memmove(cp, cp+1, strlen(cp+1));
1044 cp = strchr(revision_str, '"');
1049 BLF_size(style->widgetlabel.points, U.dpi);
1050 ver_width = BLF_width(version_str)+5;
1051 rev_width = BLF_width(revision_str)+5;
1052 #endif //NAN_BUILDINFO
1054 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
1055 uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1);
1057 but= uiDefBut(block, BUT_IMAGE, 0, "", 0, 10, 501, 282, NULL, 0.0, 0.0, 0, 0, "");
1058 uiButSetFunc(but, wm_block_splash_close, block, NULL);
1060 #ifdef NAN_BUILDINFO
1061 uiDefBut(block, LABEL, 0, version_str, 500-ver_width, 282-24, ver_width, 20, NULL, 0, 0, 0, 0, NULL);
1062 uiDefBut(block, LABEL, 0, revision_str, 500-rev_width, 282-36, rev_width, 20, NULL, 0, 0, 0, 0, NULL);
1063 #endif //NAN_BUILDINFO
1066 uiBlockSetEmboss(block, UI_EMBOSSP);
1068 layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 10, 10, 480, 110, style);
1070 uiLayoutSetOperatorContext(layout, WM_OP_EXEC_REGION_WIN);
1072 split = uiLayoutSplit(layout, 0, 0);
1073 col = uiLayoutColumn(split, 0);
1074 uiItemL(col, "Links", 0);
1075 uiItemO(col, NULL, ICON_URL, "HELP_OT_release_logs");
1076 uiItemO(col, NULL, ICON_URL, "HELP_OT_manual");
1077 uiItemO(col, NULL, ICON_URL, "HELP_OT_blender_website");
1078 uiItemO(col, NULL, ICON_URL, "HELP_OT_user_community");
1079 uiItemO(col, NULL, ICON_URL, "HELP_OT_python_api");
1080 uiItemL(col, "", 0);
1082 col = uiLayoutColumn(split, 0);
1083 uiItemL(col, "Recent", 0);
1084 for(recent = G.recent_files.first, i=0; (i<6) && (recent); recent = recent->next, i++) {
1085 char *display_name= BLI_last_slash(recent->filename);
1086 if(display_name) display_name++; /* skip the slash */
1087 else display_name= recent->filename;
1088 uiItemStringO(col, display_name, ICON_FILE_BLEND, "WM_OT_open_mainfile", "path", recent->filename);
1091 uiItemL(col, "", 0);
1093 uiCenteredBoundsBlock(block, 0.0f);
1094 uiEndBlock(C, block);
1099 static int wm_splash_invoke(bContext *C, wmOperator *op, wmEvent *event)
1101 uiPupBlock(C, wm_block_create_splash, NULL);
1103 return OPERATOR_FINISHED;
1106 static void WM_OT_splash(wmOperatorType *ot)
1108 ot->name= "Splash Screen";
1109 ot->idname= "WM_OT_splash";
1110 ot->description= "Opens a blocking popup region with release info";
1112 ot->invoke= wm_splash_invoke;
1113 ot->poll= WM_operator_winactive;
1117 /* ***************** Search menu ************************* */
1118 static void operator_call_cb(struct bContext *C, void *arg1, void *arg2)
1120 wmOperatorType *ot= arg2;
1123 WM_operator_name_call(C, ot->idname, WM_OP_INVOKE_DEFAULT, NULL);
1126 static void operator_search_cb(const struct bContext *C, void *arg, char *str, uiSearchItems *items)
1128 wmOperatorType *ot = WM_operatortype_first();
1130 for(; ot; ot= ot->next) {
1132 if(BLI_strcasestr(ot->name, str)) {
1133 if(WM_operator_poll((bContext*)C, ot)) {
1135 int len= strlen(ot->name);
1137 /* display name for menu, can hold hotkey */
1138 BLI_strncpy(name, ot->name, 256);
1140 /* check for hotkey */
1142 if(WM_key_event_operator_string(C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, &name[len+1], 256-len-1))
1146 if(0==uiSearchItemAdd(items, name, ot, 0))
1153 static uiBlock *wm_block_search_menu(bContext *C, ARegion *ar, void *arg_op)
1155 static char search[256]= "";
1157 wmWindow *win= CTX_wm_window(C);
1161 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
1162 uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_RET_1|UI_BLOCK_MOVEMOUSE_QUIT);
1164 but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 10, 180, 19, 0, 0, "");
1165 uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb, NULL);
1167 /* fake button, it holds space for search items */
1168 uiDefBut(block, LABEL, 0, "", 10, 10 - uiSearchBoxhHeight(), 180, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
1170 uiPopupBoundsBlock(block, 6.0f, 0, -20); /* move it downwards, mouse over button */
1171 uiEndBlock(C, block);
1173 event= *(win->eventstate); /* XXX huh huh? make api call */
1174 event.type= EVT_BUT_OPEN;
1175 event.val= KM_PRESS;
1176 event.customdata= but;
1177 event.customdatafree= FALSE;
1178 wm_event_add(win, &event);
1183 static int wm_search_menu_exec(bContext *C, wmOperator *op)
1186 return OPERATOR_FINISHED;
1189 static int wm_search_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
1192 uiPupBlock(C, wm_block_search_menu, op);
1194 return OPERATOR_CANCELLED;
1198 static int wm_search_menu_poll(bContext *C)
1200 if(CTX_wm_window(C)==NULL) return 0;
1201 if(CTX_wm_area(C) && CTX_wm_area(C)->spacetype==SPACE_CONSOLE) return 0; // XXX - so we can use the shortcut in the console
1202 if(CTX_wm_area(C) && CTX_wm_area(C)->spacetype==SPACE_TEXT) return 0; // XXX - so we can use the spacebar in the text editor
1203 if(CTX_data_edit_object(C) && CTX_data_edit_object(C)->type==OB_CURVE) return 0; // XXX - so we can use the spacebar for entering text
1207 static void WM_OT_search_menu(wmOperatorType *ot)
1209 ot->name= "Search Menu";
1210 ot->idname= "WM_OT_search_menu";
1212 ot->invoke= wm_search_menu_invoke;
1213 ot->exec= wm_search_menu_exec;
1214 ot->poll= wm_search_menu_poll;
1217 static int wm_call_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
1219 char idname[BKE_ST_MAXNAME];
1220 RNA_string_get(op->ptr, "name", idname);
1222 uiPupMenuInvoke(C, idname);
1224 return OPERATOR_CANCELLED;
1227 static void WM_OT_call_menu(wmOperatorType *ot)
1229 ot->name= "Call Menu";
1230 ot->idname= "WM_OT_call_menu";
1232 ot->invoke= wm_call_menu_invoke;
1234 RNA_def_string(ot->srna, "name", "", BKE_ST_MAXNAME, "Name", "Name of the menu");
1237 /* ************ window / screen operator definitions ************** */
1239 static void WM_OT_window_duplicate(wmOperatorType *ot)
1241 ot->name= "Duplicate Window";
1242 ot->idname= "WM_OT_window_duplicate";
1243 ot->description="Duplicate the current Blender window.";
1245 ot->exec= wm_window_duplicate_op;
1246 ot->poll= WM_operator_winactive;
1249 static void WM_OT_save_homefile(wmOperatorType *ot)
1251 ot->name= "Save User Settings";
1252 ot->idname= "WM_OT_save_homefile";
1253 ot->description="Make the current file the default .blend file.";
1255 ot->invoke= WM_operator_confirm;
1256 ot->exec= WM_write_homefile;
1257 ot->poll= WM_operator_winactive;
1260 static void WM_OT_read_homefile(wmOperatorType *ot)
1262 ot->name= "Reload Start-Up File";
1263 ot->idname= "WM_OT_read_homefile";
1264 ot->description="Open the default file (doesn't save the current file).";
1266 ot->invoke= WM_operator_confirm;
1267 ot->exec= WM_read_homefile;
1268 ot->poll= WM_operator_winactive;
1270 RNA_def_boolean(ot->srna, "factory", 0, "Factory Settings", "");
1273 /* *************** open file **************** */
1275 static void open_set_load_ui(wmOperator *op)
1277 if(!RNA_property_is_set(op->ptr, "load_ui"))
1278 RNA_boolean_set(op->ptr, "load_ui", !(U.flag & USER_FILENOUI));
1281 static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
1283 RNA_string_set(op->ptr, "path", G.sce);
1284 open_set_load_ui(op);
1286 WM_event_add_fileselect(C, op);
1288 return OPERATOR_RUNNING_MODAL;
1291 static int wm_open_mainfile_exec(bContext *C, wmOperator *op)
1293 char path[FILE_MAX];
1295 RNA_string_get(op->ptr, "path", path);
1296 open_set_load_ui(op);
1298 if(RNA_boolean_get(op->ptr, "load_ui"))
1299 G.fileflags &= ~G_FILE_NO_UI;
1301 G.fileflags |= G_FILE_NO_UI;
1303 // XXX wm in context is not set correctly after WM_read_file -> crash
1304 // do it before for now, but is this correct with multiple windows?
1305 WM_event_add_notifier(C, NC_WINDOW, NULL);
1307 WM_read_file(C, path, op->reports);
1309 return OPERATOR_FINISHED;
1312 static void WM_OT_open_mainfile(wmOperatorType *ot)
1314 ot->name= "Open Blender File";
1315 ot->idname= "WM_OT_open_mainfile";
1316 ot->description="Open a Blender file.";
1318 ot->invoke= wm_open_mainfile_invoke;
1319 ot->exec= wm_open_mainfile_exec;
1320 ot->poll= WM_operator_winactive;
1322 WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_BLENDER);
1324 RNA_def_boolean(ot->srna, "load_ui", 1, "Load UI", "Load user interface setup in the .blend file.");
1327 /* **************** link/append *************** */
1329 static int wm_link_append_invoke(bContext *C, wmOperator *op, wmEvent *event)
1331 if(RNA_property_is_set(op->ptr, "path")) {
1332 return WM_operator_call(C, op);
1335 /* XXX TODO solve where to get last linked library from */
1336 RNA_string_set(op->ptr, "path", G.lib);
1337 WM_event_add_fileselect(C, op);
1338 return OPERATOR_RUNNING_MODAL;
1342 static short wm_link_append_flag(wmOperator *op)
1346 if(RNA_boolean_get(op->ptr, "autoselect")) flag |= FILE_AUTOSELECT;
1347 if(RNA_boolean_get(op->ptr, "active_layer")) flag |= FILE_ACTIVELAY;
1348 if(RNA_boolean_get(op->ptr, "relative_paths")) flag |= FILE_STRINGCODE;
1349 if(RNA_boolean_get(op->ptr, "link")) flag |= FILE_LINK;
1350 if(RNA_boolean_get(op->ptr, "instance_groups")) flag |= FILE_GROUP_INSTANCE;
1354 static void wm_link_make_library_local(Main *main, const char *libname)
1358 /* and now find the latest append lib file */
1359 for(lib= main->library.first; lib; lib=lib->id.next)
1360 if(BLI_streq(libname, lib->filename))
1369 static int wm_link_append_exec(bContext *C, wmOperator *op)
1371 Main *bmain= CTX_data_main(C);
1372 Scene *scene= CTX_data_scene(C);
1376 char name[FILE_MAX], dir[FILE_MAX], libname[FILE_MAX], group[GROUP_MAX];
1377 int idcode, totfiles=0;
1381 RNA_string_get(op->ptr, "filename", name);
1382 RNA_string_get(op->ptr, "directory", dir);
1384 /* test if we have a valid data */
1385 if(BLO_is_a_library(dir, libname, group) == 0) {
1386 BKE_report(op->reports, RPT_ERROR, "Not a library");
1387 return OPERATOR_CANCELLED;
1389 else if(group[0] == 0) {
1390 BKE_report(op->reports, RPT_ERROR, "Nothing indicated");
1391 return OPERATOR_CANCELLED;
1393 else if(BLI_streq(bmain->name, libname)) {
1394 BKE_report(op->reports, RPT_ERROR, "Cannot use current file as library");
1395 return OPERATOR_CANCELLED;
1398 /* check if something is indicated for append/link */
1399 prop = RNA_struct_find_property(op->ptr, "files");
1401 totfiles= RNA_property_collection_length(op->ptr, prop);
1403 if(name[0] == '\0') {
1404 BKE_report(op->reports, RPT_ERROR, "Nothing indicated");
1405 return OPERATOR_CANCELLED;
1409 else if(name[0] == '\0') {
1410 BKE_report(op->reports, RPT_ERROR, "Nothing indicated");
1411 return OPERATOR_CANCELLED;
1414 /* now we have or selected, or an indicated file */
1415 if(RNA_boolean_get(op->ptr, "autoselect"))
1416 scene_deselect_all(scene);
1418 bh = BLO_blendhandle_from_file(libname);
1419 idcode = BLO_idcode_from_name(group);
1421 flag = wm_link_append_flag(op);
1423 /* tag everything, all untagged data can be made local
1424 * its also generally useful to know what is new
1426 * take extra care flag_all_listbases_ids(LIB_LINK_TAG, 0) is called after! */
1427 flag_all_listbases_ids(LIB_PRE_EXISTING, 1);
1429 /* here appending/linking starts */
1430 mainl = BLO_library_append_begin(C, &bh, libname);
1432 BLO_library_append_named_part(C, mainl, &bh, name, idcode, flag);
1435 RNA_BEGIN(op->ptr, itemptr, "files") {
1436 RNA_string_get(&itemptr, "name", name);
1437 BLO_library_append_named_part(C, mainl, &bh, name, idcode, flag);
1441 BLO_library_append_end(C, mainl, &bh, idcode, flag);
1443 /* mark all library linked objects to be updated */
1444 recalc_all_library_objects(bmain);
1446 /* append, rather than linking */
1447 if((flag & FILE_LINK)==0)
1448 wm_link_make_library_local(bmain, libname);
1450 /* important we unset, otherwise these object wont
1451 * link into other scenes from this blend file */
1452 flag_all_listbases_ids(LIB_PRE_EXISTING, 0);
1454 /* recreate dependency graph to include new objects */
1455 DAG_scene_sort(scene);
1456 DAG_ids_flush_update(0);
1458 BLO_blendhandle_close(bh);
1460 /* XXX TODO: align G.lib with other directory storage (like last opened image etc...) */
1461 BLI_strncpy(G.lib, dir, FILE_MAX);
1463 WM_event_add_notifier(C, NC_WINDOW, NULL);
1465 return OPERATOR_FINISHED;
1468 static void WM_OT_link_append(wmOperatorType *ot)
1470 ot->name= "Link/Append from Library";
1471 ot->idname= "WM_OT_link_append";
1472 ot->description= "Link or Append from a Library .blend file";
1474 ot->invoke= wm_link_append_invoke;
1475 ot->exec= wm_link_append_exec;
1476 ot->poll= WM_operator_winactive;
1478 ot->flag |= OPTYPE_UNDO;
1480 WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_LOADLIB);
1482 RNA_def_boolean(ot->srna, "link", 1, "Link", "Link the objects or datablocks rather than appending.");
1483 RNA_def_boolean(ot->srna, "autoselect", 1, "Select", "Select the linked objects.");
1484 RNA_def_boolean(ot->srna, "active_layer", 1, "Active Layer", "Put the linked objects on the active layer.");
1485 RNA_def_boolean(ot->srna, "instance_groups", 1, "Instance Groups", "Create instances for each group as a DupliGroup.");
1486 RNA_def_boolean(ot->srna, "relative_paths", 1, "Relative Paths", "Store the library path as a relative path to current .blend file.");
1488 RNA_def_collection_runtime(ot->srna, "files", &RNA_OperatorFileListElement, "Files", "");
1491 /* *************** recover last session **************** */
1493 static int wm_recover_last_session_exec(bContext *C, wmOperator *op)
1495 char filename[FILE_MAX];
1497 G.fileflags |= G_FILE_RECOVER;
1499 // XXX wm in context is not set correctly after WM_read_file -> crash
1500 // do it before for now, but is this correct with multiple windows?
1501 WM_event_add_notifier(C, NC_WINDOW, NULL);
1504 BLI_make_file_string("/", filename, btempdir, "quit.blend");
1505 WM_read_file(C, filename, op->reports);
1507 G.fileflags &= ~G_FILE_RECOVER;
1509 return OPERATOR_FINISHED;
1512 static void WM_OT_recover_last_session(wmOperatorType *ot)
1514 ot->name= "Recover Last Session";
1515 ot->idname= "WM_OT_recover_last_session";
1516 ot->description="Open the last closed file (\"quit.blend\").";
1518 ot->exec= wm_recover_last_session_exec;
1519 ot->poll= WM_operator_winactive;
1522 /* *************** recover auto save **************** */
1524 static int wm_recover_auto_save_exec(bContext *C, wmOperator *op)
1526 char path[FILE_MAX];
1528 RNA_string_get(op->ptr, "path", path);
1530 G.fileflags |= G_FILE_RECOVER;
1532 // XXX wm in context is not set correctly after WM_read_file -> crash
1533 // do it before for now, but is this correct with multiple windows?
1534 WM_event_add_notifier(C, NC_WINDOW, NULL);
1537 WM_read_file(C, path, op->reports);
1539 G.fileflags &= ~G_FILE_RECOVER;
1541 return OPERATOR_FINISHED;
1544 static int wm_recover_auto_save_invoke(bContext *C, wmOperator *op, wmEvent *event)
1546 char filename[FILE_MAX];
1548 wm_autosave_location(filename);
1549 RNA_string_set(op->ptr, "path", filename);
1550 WM_event_add_fileselect(C, op);
1552 return OPERATOR_RUNNING_MODAL;
1555 static void WM_OT_recover_auto_save(wmOperatorType *ot)
1557 ot->name= "Recover Auto Save";
1558 ot->idname= "WM_OT_recover_auto_save";
1559 ot->description="Open an automatically saved file to recover it.";
1561 ot->exec= wm_recover_auto_save_exec;
1562 ot->invoke= wm_recover_auto_save_invoke;
1563 ot->poll= WM_operator_winactive;
1565 WM_operator_properties_filesel(ot, BLENDERFILE, FILE_BLENDER);
1568 /* *************** save file as **************** */
1570 static void untitled(char *name)
1572 if(G.save_over == 0 && strlen(name) < FILE_MAX-16) {
1573 char *c= BLI_last_slash(name);
1576 strcpy(&c[1], "untitled.blend");
1578 strcpy(name, "untitled.blend");
1582 static void save_set_compress(wmOperator *op)
1584 if(!RNA_property_is_set(op->ptr, "compress")) {
1585 if(G.save_over) /* keep flag for existing file */
1586 RNA_boolean_set(op->ptr, "compress", G.fileflags & G_FILE_COMPRESS);
1587 else /* use userdef for new file */
1588 RNA_boolean_set(op->ptr, "compress", U.flag & USER_FILECOMPRESS);
1592 static int wm_save_as_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
1594 char name[FILE_MAX];
1596 save_set_compress(op);
1598 BLI_strncpy(name, G.sce, FILE_MAX);
1600 RNA_string_set(op->ptr, "path", name);
1602 WM_event_add_fileselect(C, op);
1604 return OPERATOR_RUNNING_MODAL;
1607 /* function used for WM_OT_save_mainfile too */
1608 static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
1610 char path[FILE_MAX];
1613 save_set_compress(op);
1615 if(RNA_property_is_set(op->ptr, "path"))
1616 RNA_string_get(op->ptr, "path", path);
1618 BLI_strncpy(path, G.sce, FILE_MAX);
1622 fileflags= G.fileflags;
1624 /* set compression flag */
1625 if(RNA_boolean_get(op->ptr, "compress")) fileflags |= G_FILE_COMPRESS;
1626 else fileflags &= ~G_FILE_COMPRESS;
1627 if(RNA_boolean_get(op->ptr, "relative_remap")) fileflags |= G_FILE_RELATIVE_REMAP;
1628 else fileflags &= ~G_FILE_RELATIVE_REMAP;
1630 WM_write_file(C, path, fileflags, op->reports);
1632 WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL);
1637 static void WM_OT_save_as_mainfile(wmOperatorType *ot)
1639 ot->name= "Save As Blender File";
1640 ot->idname= "WM_OT_save_as_mainfile";
1641 ot->description="Save the current file in the desired location.";
1643 ot->invoke= wm_save_as_mainfile_invoke;
1644 ot->exec= wm_save_as_mainfile_exec;
1645 ot->poll= WM_operator_winactive;
1647 WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_BLENDER);
1648 RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file.");
1649 RNA_def_boolean(ot->srna, "relative_remap", 0, "Remap Relative", "Remap relative paths when saving in a different directory.");
1652 /* *************** save file directly ******** */
1654 static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
1656 char name[FILE_MAX];
1658 /* cancel if no active window */
1659 if (CTX_wm_window(C) == NULL)
1660 return OPERATOR_CANCELLED;
1662 save_set_compress(op);
1664 BLI_strncpy(name, G.sce, FILE_MAX);
1666 RNA_string_set(op->ptr, "path", name);
1669 uiPupMenuSaveOver(C, op, name);
1671 WM_event_add_fileselect(C, op);
1673 return OPERATOR_RUNNING_MODAL;
1676 static void WM_OT_save_mainfile(wmOperatorType *ot)
1678 ot->name= "Save Blender File";
1679 ot->idname= "WM_OT_save_mainfile";
1680 ot->description="Save the current Blender file.";
1682 ot->invoke= wm_save_mainfile_invoke;
1683 ot->exec= wm_save_as_mainfile_exec;
1686 WM_operator_properties_filesel(ot, FOLDERFILE|BLENDERFILE, FILE_BLENDER);
1687 RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file.");
1688 RNA_def_boolean(ot->srna, "relative_remap", 0, "Remap Relative", "Remap relative paths when saving in a different directory.");
1692 /* XXX: move these collada operators to a more appropriate place */
1695 #include "../../collada/collada.h"
1697 static int wm_collada_export_invoke(bContext *C, wmOperator *op, wmEvent *event)
1699 //char name[FILE_MAX];
1700 //BLI_strncpy(name, G.sce, FILE_MAX);
1703 /* RNA_string_set(op->ptr, "path", "/tmp/test.dae"); */
1705 WM_event_add_fileselect(C, op);
1707 return OPERATOR_RUNNING_MODAL;
1710 /* function used for WM_OT_save_mainfile too */
1711 static int wm_collada_export_exec(bContext *C, wmOperator *op)
1713 char filename[FILE_MAX];
1715 if(RNA_property_is_set(op->ptr, "path"))
1716 RNA_string_get(op->ptr, "path", filename);
1718 BLI_strncpy(filename, G.sce, FILE_MAX);
1722 //WM_write_file(C, filename, op->reports);
1723 collada_export(CTX_data_scene(C), filename);
1725 /* WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL); */
1727 return OPERATOR_FINISHED;
1730 static void WM_OT_collada_export(wmOperatorType *ot)
1732 ot->name= "Export COLLADA";
1733 ot->idname= "WM_OT_collada_export";
1735 ot->invoke= wm_collada_export_invoke;
1736 ot->exec= wm_collada_export_exec;
1737 ot->poll= WM_operator_winactive;
1741 RNA_def_property(ot->srna, "path", PROP_STRING, PROP_FILEPATH);
1744 static int wm_collada_import_invoke(bContext *C, wmOperator *op, wmEvent *event)
1746 /* RNA_string_set(op->ptr, "path", "/tmp/test.dae"); */
1748 WM_event_add_fileselect(C, op);
1750 return OPERATOR_RUNNING_MODAL;
1753 /* function used for WM_OT_save_mainfile too */
1754 static int wm_collada_import_exec(bContext *C, wmOperator *op)
1756 char filename[FILE_MAX];
1758 if(RNA_property_is_set(op->ptr, "path"))
1759 RNA_string_get(op->ptr, "path", filename);
1761 BLI_strncpy(filename, G.sce, FILE_MAX);
1765 //WM_write_file(C, filename, op->reports);
1766 collada_import(C, filename);
1768 /* WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL); */
1770 return OPERATOR_FINISHED;
1773 static void WM_OT_collada_import(wmOperatorType *ot)
1775 ot->name= "Import COLLADA";
1776 ot->idname= "WM_OT_collada_import";
1778 ot->invoke= wm_collada_import_invoke;
1779 ot->exec= wm_collada_import_exec;
1780 ot->poll= WM_operator_winactive;
1784 RNA_def_property(ot->srna, "path", PROP_STRING, PROP_FILEPATH);
1791 /* *********************** */
1793 static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
1795 ot->name= "Toggle Fullscreen";
1796 ot->idname= "WM_OT_window_fullscreen_toggle";
1797 ot->description="Toggle the current window fullscreen.";
1799 ot->exec= wm_window_fullscreen_toggle_op;
1800 ot->poll= WM_operator_winactive;
1803 static int wm_exit_blender_op(bContext *C, wmOperator *op)
1805 WM_operator_free(op);
1809 return OPERATOR_FINISHED;
1812 static void WM_OT_exit_blender(wmOperatorType *ot)
1814 ot->name= "Exit Blender";
1815 ot->idname= "WM_OT_exit_blender";
1816 ot->description= "Quit Blender.";
1818 ot->invoke= WM_operator_confirm;
1819 ot->exec= wm_exit_blender_op;
1820 ot->poll= WM_operator_winactive;
1823 /* ************ default paint cursors, draw always around cursor *********** */
1825 - returns handler to free
1826 - poll(bContext): returns 1 if draw should happen
1827 - draw(bContext): drawing callback for paint cursor
1830 void *WM_paint_cursor_activate(wmWindowManager *wm, int (*poll)(bContext *C),
1831 wmPaintCursorDraw draw, void *customdata)
1833 wmPaintCursor *pc= MEM_callocN(sizeof(wmPaintCursor), "paint cursor");
1835 BLI_addtail(&wm->paintcursors, pc);
1837 pc->customdata = customdata;
1844 void WM_paint_cursor_end(wmWindowManager *wm, void *handle)
1848 for(pc= wm->paintcursors.first; pc; pc= pc->next) {
1849 if(pc == (wmPaintCursor *)handle) {
1850 BLI_remlink(&wm->paintcursors, pc);
1857 /* ************ window gesture operator-callback definitions ************** */
1859 * These are default callbacks for use in operators requiring gesture input
1862 /* **************** Border gesture *************** */
1864 /* Border gesture has two types:
1865 1) WM_GESTURE_CROSS_RECT: starts a cross, on mouse click it changes to border
1866 2) WM_GESTURE_RECT: starts immediate as a border, on mouse click or release it ends
1868 It stores 4 values (xmin, xmax, ymin, ymax) and event it ended with (event_type)
1871 static int border_apply(bContext *C, wmOperator *op, int gesture_mode)
1873 wmGesture *gesture= op->customdata;
1874 rcti *rect= gesture->customdata;
1876 if(rect->xmin > rect->xmax)
1877 SWAP(int, rect->xmin, rect->xmax);
1878 if(rect->ymin > rect->ymax)
1879 SWAP(int, rect->ymin, rect->ymax);
1881 if(rect->xmin==rect->xmax || rect->ymin==rect->ymax)
1884 /* operator arguments and storage. */
1885 RNA_int_set(op->ptr, "xmin", rect->xmin);
1886 RNA_int_set(op->ptr, "ymin", rect->ymin);
1887 RNA_int_set(op->ptr, "xmax", rect->xmax);
1888 RNA_int_set(op->ptr, "ymax", rect->ymax);
1890 /* XXX weak; border should be configured for this without reading event types */
1891 if( RNA_struct_find_property(op->ptr, "gesture_mode") )
1892 RNA_int_set(op->ptr, "gesture_mode", gesture_mode);
1894 op->type->exec(C, op);
1899 static void wm_gesture_end(bContext *C, wmOperator *op)
1901 wmGesture *gesture= op->customdata;
1903 WM_gesture_end(C, gesture); /* frees gesture itself, and unregisters from window */
1904 op->customdata= NULL;
1906 ED_area_tag_redraw(CTX_wm_area(C));
1908 if( RNA_struct_find_property(op->ptr, "cursor") )
1909 WM_cursor_restore(CTX_wm_window(C));
1912 int WM_border_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
1914 if(ISTWEAK(event->type))
1915 op->customdata= WM_gesture_new(C, event, WM_GESTURE_RECT);
1917 op->customdata= WM_gesture_new(C, event, WM_GESTURE_CROSS_RECT);
1919 /* add modal handler */
1920 WM_event_add_modal_handler(C, op);
1922 wm_gesture_tag_redraw(C);
1924 return OPERATOR_RUNNING_MODAL;
1927 int WM_border_select_modal(bContext *C, wmOperator *op, wmEvent *event)
1929 wmGesture *gesture= op->customdata;
1930 rcti *rect= gesture->customdata;
1933 if(event->type== MOUSEMOVE) {
1934 wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
1936 if(gesture->type==WM_GESTURE_CROSS_RECT && gesture->mode==0) {
1937 rect->xmin= rect->xmax= event->x - sx;
1938 rect->ymin= rect->ymax= event->y - sy;
1941 rect->xmax= event->x - sx;
1942 rect->ymax= event->y - sy;
1945 wm_gesture_tag_redraw(C);
1947 else if (event->type==EVT_MODAL_MAP) {
1948 switch (event->val) {
1949 case GESTURE_MODAL_BORDER_BEGIN:
1950 if(gesture->type==WM_GESTURE_CROSS_RECT && gesture->mode==0) {
1952 wm_gesture_tag_redraw(C);
1955 case GESTURE_MODAL_SELECT:
1956 case GESTURE_MODAL_DESELECT:
1957 if(border_apply(C, op, event->val)) {
1958 wm_gesture_end(C, op);
1959 return OPERATOR_FINISHED;
1961 wm_gesture_end(C, op);
1962 return OPERATOR_CANCELLED;
1965 case GESTURE_MODAL_CANCEL:
1966 wm_gesture_end(C, op);
1967 return OPERATOR_CANCELLED;
1971 // // Allow view navigation???
1973 // return OPERATOR_PASS_THROUGH;
1976 return OPERATOR_RUNNING_MODAL;
1979 /* **************** circle gesture *************** */
1980 /* works now only for selection or modal paint stuff, calls exec while hold mouse, exit on release */
1982 #ifdef GESTURE_MEMORY
1983 int circle_select_size= 25; // XXX - need some operator memory thing\!
1986 int WM_gesture_circle_invoke(bContext *C, wmOperator *op, wmEvent *event)
1988 op->customdata= WM_gesture_new(C, event, WM_GESTURE_CIRCLE);
1990 /* add modal handler */
1991 WM_event_add_modal_handler(C, op);
1993 wm_gesture_tag_redraw(C);
1995 return OPERATOR_RUNNING_MODAL;
1998 static void gesture_circle_apply(bContext *C, wmOperator *op)
2000 wmGesture *gesture= op->customdata;
2001 rcti *rect= gesture->customdata;
2003 if(RNA_int_get(op->ptr, "gesture_mode")==GESTURE_MODAL_NOP)
2006 /* operator arguments and storage. */
2007 RNA_int_set(op->ptr, "x", rect->xmin);
2008 RNA_int_set(op->ptr, "y", rect->ymin);
2009 RNA_int_set(op->ptr, "radius", rect->xmax);
2012 op->type->exec(C, op);
2014 #ifdef GESTURE_MEMORY
2015 circle_select_size= rect->xmax;
2019 int WM_gesture_circle_modal(bContext *C, wmOperator *op, wmEvent *event)
2021 wmGesture *gesture= op->customdata;
2022 rcti *rect= gesture->customdata;
2025 if(event->type== MOUSEMOVE) {
2026 wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
2028 rect->xmin= event->x - sx;
2029 rect->ymin= event->y - sy;
2031 wm_gesture_tag_redraw(C);
2034 gesture_circle_apply(C, op);
2036 else if (event->type==EVT_MODAL_MAP) {
2037 switch (event->val) {
2038 case GESTURE_MODAL_CIRCLE_ADD:
2039 rect->xmax += 2 + rect->xmax/10;
2040 wm_gesture_tag_redraw(C);
2042 case GESTURE_MODAL_CIRCLE_SUB:
2043 rect->xmax -= 2 + rect->xmax/10;
2044 if(rect->xmax < 1) rect->xmax= 1;
2045 wm_gesture_tag_redraw(C);
2047 case GESTURE_MODAL_SELECT:
2048 case GESTURE_MODAL_DESELECT:
2049 case GESTURE_MODAL_NOP:
2050 if(RNA_struct_find_property(op->ptr, "gesture_mode"))
2051 RNA_int_set(op->ptr, "gesture_mode", event->val);
2053 if(event->val != GESTURE_MODAL_NOP) {
2054 /* apply first click */
2055 gesture_circle_apply(C, op);
2060 case GESTURE_MODAL_CANCEL:
2061 case GESTURE_MODAL_CONFIRM:
2062 wm_gesture_end(C, op);
2063 return OPERATOR_FINISHED; /* use finish or we dont get an undo */
2066 // // Allow view navigation???
2068 // return OPERATOR_PASS_THROUGH;
2071 return OPERATOR_RUNNING_MODAL;
2075 /* template to copy from */
2076 void WM_OT_circle_gesture(wmOperatorType *ot)
2078 ot->name= "Circle Gesture";
2079 ot->idname= "WM_OT_circle_gesture";
2080 ot->description="Enter rotate mode with a circular gesture.";
2082 ot->invoke= WM_gesture_circle_invoke;
2083 ot->modal= WM_gesture_circle_modal;
2085 ot->poll= WM_operator_winactive;
2087 RNA_def_property(ot->srna, "x", PROP_INT, PROP_NONE);
2088 RNA_def_property(ot->srna, "y", PROP_INT, PROP_NONE);
2089 RNA_def_property(ot->srna, "radius", PROP_INT, PROP_NONE);
2094 /* **************** Tweak gesture *************** */
2096 static void tweak_gesture_modal(bContext *C, wmEvent *event)
2098 wmWindow *window= CTX_wm_window(C);
2099 wmGesture *gesture= window->tweak;
2100 rcti *rect= gesture->customdata;
2103 switch(event->type) {
2106 wm_subwindow_getorigin(window, gesture->swinid, &sx, &sy);
2108 rect->xmax= event->x - sx;
2109 rect->ymax= event->y - sy;
2111 if((val= wm_gesture_evaluate(C, gesture))) {
2114 event= *(window->eventstate);
2115 if(gesture->event_type==LEFTMOUSE)
2116 event.type= EVT_TWEAK_L;
2117 else if(gesture->event_type==RIGHTMOUSE)
2118 event.type= EVT_TWEAK_R;
2120 event.type= EVT_TWEAK_M;
2123 wm_event_add(window, &event);
2125 WM_gesture_end(C, gesture); /* frees gesture itself, and unregisters from window */
2133 if(gesture->event_type==event->type) {
2134 WM_gesture_end(C, gesture);
2136 /* when tweak fails we should give the other keymap entries a chance */
2137 event->val= KM_RELEASE;
2141 if(!ISTIMER(event->type)) {
2142 WM_gesture_end(C, gesture);
2148 /* standard tweak, called after window handlers passed on event */
2149 void wm_tweakevent_test(bContext *C, wmEvent *event, int action)
2151 wmWindow *win= CTX_wm_window(C);
2153 if(win->tweak==NULL) {
2154 if(CTX_wm_region(C)) {
2155 if(event->val==KM_PRESS) {
2156 if( ELEM3(event->type, LEFTMOUSE, MIDDLEMOUSE, RIGHTMOUSE) )
2157 win->tweak= WM_gesture_new(C, event, WM_GESTURE_TWEAK);
2162 /* no tweaks if event was handled */
2163 if((action & WM_HANDLER_BREAK)) {
2164 WM_gesture_end(C, win->tweak);
2167 tweak_gesture_modal(C, event);
2171 /* *********************** lasso gesture ****************** */
2173 int WM_gesture_lasso_invoke(bContext *C, wmOperator *op, wmEvent *event)
2175 op->customdata= WM_gesture_new(C, event, WM_GESTURE_LASSO);
2177 /* add modal handler */
2178 WM_event_add_modal_handler(C, op);
2180 wm_gesture_tag_redraw(C);
2182 if( RNA_struct_find_property(op->ptr, "cursor") )
2183 WM_cursor_modal(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
2185 return OPERATOR_RUNNING_MODAL;
2188 int WM_gesture_lines_invoke(bContext *C, wmOperator *op, wmEvent *event)
2190 op->customdata= WM_gesture_new(C, event, WM_GESTURE_LINES);
2192 /* add modal handler */
2193 WM_event_add_modal_handler(C, op);
2195 wm_gesture_tag_redraw(C);
2197 if( RNA_struct_find_property(op->ptr, "cursor") )
2198 WM_cursor_modal(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
2200 return OPERATOR_RUNNING_MODAL;
2204 static void gesture_lasso_apply(bContext *C, wmOperator *op, int event_type)
2206 wmGesture *gesture= op->customdata;
2210 short *lasso= gesture->customdata;
2212 /* operator storage as path. */
2214 for(i=0; i<gesture->points; i++, lasso+=2) {
2217 RNA_collection_add(op->ptr, "path", &itemptr);
2218 RNA_float_set_array(&itemptr, "loc", loc);
2221 wm_gesture_end(C, op);
2224 op->type->exec(C, op);
2228 int WM_gesture_lasso_modal(bContext *C, wmOperator *op, wmEvent *event)
2230 wmGesture *gesture= op->customdata;
2233 switch(event->type) {
2236 wm_gesture_tag_redraw(C);
2238 wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
2240 if(gesture->points == gesture->size) {
2241 short *old_lasso = gesture->customdata;
2242 gesture->customdata= MEM_callocN(2*sizeof(short)*(gesture->size + WM_LASSO_MIN_POINTS), "lasso points");
2243 memcpy(gesture->customdata, old_lasso, 2*sizeof(short)*gesture->size);
2244 gesture->size = gesture->size + WM_LASSO_MIN_POINTS;
2245 MEM_freeN(old_lasso);
2246 printf("realloc\n");
2250 short *lasso= gesture->customdata;
2251 lasso += 2 * gesture->points;
2252 lasso[0] = event->x - sx;
2253 lasso[1] = event->y - sy;
2261 if(event->val==KM_RELEASE) { /* key release */
2262 gesture_lasso_apply(C, op, event->type);
2263 return OPERATOR_FINISHED;
2267 wm_gesture_end(C, op);
2268 return OPERATOR_CANCELLED;
2270 return OPERATOR_RUNNING_MODAL;
2273 int WM_gesture_lines_modal(bContext *C, wmOperator *op, wmEvent *event)
2275 return WM_gesture_lasso_modal(C, op, event);
2279 /* template to copy from */
2281 static int gesture_lasso_exec(bContext *C, wmOperator *op)
2283 RNA_BEGIN(op->ptr, itemptr, "path") {
2286 RNA_float_get_array(&itemptr, "loc", loc);
2287 printf("Location: %f %f\n", loc[0], loc[1]);
2291 return OPERATOR_FINISHED;
2294 void WM_OT_lasso_gesture(wmOperatorType *ot)
2298 ot->name= "Lasso Gesture";
2299 ot->idname= "WM_OT_lasso_gesture";
2300 ot->description="Select objects within the lasso as you move the pointer.";
2302 ot->invoke= WM_gesture_lasso_invoke;
2303 ot->modal= WM_gesture_lasso_modal;
2304 ot->exec= gesture_lasso_exec;
2306 ot->poll= WM_operator_winactive;
2308 prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
2309 RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
2313 /* *********************** radial control ****************** */
2315 const int WM_RADIAL_CONTROL_DISPLAY_SIZE = 200;
2317 typedef struct wmRadialControl {
2319 float initial_value, value, max_value;
2320 int initial_mouse[2];
2325 static void wm_radial_control_paint(bContext *C, int x, int y, void *customdata)
2327 wmRadialControl *rc = (wmRadialControl*)customdata;
2328 ARegion *ar = CTX_wm_region(C);
2329 float r1=0.0f, r2=0.0f, r3=0.0f, angle=0.0f;
2331 /* Keep cursor in the original place */
2332 x = rc->initial_mouse[0] - ar->winrct.xmin;
2333 y = rc->initial_mouse[1] - ar->winrct.ymin;
2337 glTranslatef((float)x, (float)y, 0.0f);
2339 if(rc->mode == WM_RADIALCONTROL_SIZE) {
2341 r2= rc->initial_value;
2343 } else if(rc->mode == WM_RADIALCONTROL_STRENGTH) {
2344 r1= (1 - rc->value) * WM_RADIAL_CONTROL_DISPLAY_SIZE;
2345 r2= WM_RADIAL_CONTROL_DISPLAY_SIZE;
2346 r3= WM_RADIAL_CONTROL_DISPLAY_SIZE;
2347 } else if(rc->mode == WM_RADIALCONTROL_ANGLE) {
2348 r1= r2= WM_RADIAL_CONTROL_DISPLAY_SIZE;
2349 r3= WM_RADIAL_CONTROL_DISPLAY_SIZE;
2353 glColor4ub(255, 255, 255, 128);
2354 glEnable( GL_LINE_SMOOTH );
2357 if(rc->mode == WM_RADIALCONTROL_ANGLE)
2358 fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
2361 const float str = rc->mode == WM_RADIALCONTROL_STRENGTH ? (rc->value + 0.5) : 1;
2363 if(rc->mode == WM_RADIALCONTROL_ANGLE) {
2364 glRotatef(angle, 0, 0, 1);
2365 fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
2368 glBindTexture(GL_TEXTURE_2D, rc->tex);
2370 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2371 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2373 glEnable(GL_TEXTURE_2D);
2375 glColor4f(0,0,0, str);
2377 glVertex2f(-r3, -r3);
2379 glVertex2f(r3, -r3);
2383 glVertex2f(-r3, r3);
2385 glDisable(GL_TEXTURE_2D);
2388 glColor4ub(255, 255, 255, 128);
2389 glutil_draw_lined_arc(0.0, M_PI*2.0, r1, 40);
2390 glutil_draw_lined_arc(0.0, M_PI*2.0, r2, 40);
2391 glDisable(GL_BLEND);
2392 glDisable( GL_LINE_SMOOTH );
2397 int WM_radial_control_modal(bContext *C, wmOperator *op, wmEvent *event)
2399 wmRadialControl *rc = (wmRadialControl*)op->customdata;
2400 int mode, initial_mouse[2], delta[2];
2402 double new_value = RNA_float_get(op->ptr, "new_value");
2403 int ret = OPERATOR_RUNNING_MODAL;
2405 mode = RNA_int_get(op->ptr, "mode");
2406 RNA_int_get_array(op->ptr, "initial_mouse", initial_mouse);
2408 switch(event->type) {
2410 delta[0]= initial_mouse[0] - event->x;
2411 delta[1]= initial_mouse[1] - event->y;
2412 dist= sqrt(delta[0]*delta[0]+delta[1]*delta[1]);
2414 if(mode == WM_RADIALCONTROL_SIZE)
2416 else if(mode == WM_RADIALCONTROL_STRENGTH) {
2417 new_value = 1 - dist / WM_RADIAL_CONTROL_DISPLAY_SIZE;
2418 } else if(mode == WM_RADIALCONTROL_ANGLE)
2419 new_value = ((int)(atan2(delta[1], delta[0]) * (180.0 / M_PI)) + 180);
2422 if(mode == WM_RADIALCONTROL_STRENGTH)
2423 new_value = ((int)ceil(new_value * 10.f) * 10.0f) / 100.f;
2425 new_value = ((int)new_value + 5) / 10*10;
2431 ret = OPERATOR_CANCELLED;
2435 op->type->exec(C, op);
2436 ret = OPERATOR_FINISHED;
2441 if(new_value > rc->max_value)
2442 new_value = rc->max_value;
2443 else if(new_value < 0)
2446 /* Update paint data */
2447 rc->value = new_value;
2449 RNA_float_set(op->ptr, "new_value", new_value);
2451 if(ret != OPERATOR_RUNNING_MODAL) {
2452 WM_paint_cursor_end(CTX_wm_manager(C), rc->cursor);
2456 ED_region_tag_redraw(CTX_wm_region(C));
2461 /* Expects the operator customdata to be an ImBuf (or NULL) */
2462 int WM_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
2464 wmRadialControl *rc = MEM_callocN(sizeof(wmRadialControl), "radial control");
2465 int mode = RNA_int_get(op->ptr, "mode");
2466 float initial_value = RNA_float_get(op->ptr, "initial_value");
2467 int mouse[2] = {event->x, event->y};
2469 if(mode == WM_RADIALCONTROL_SIZE) {
2470 rc->max_value = 200;
2471 mouse[0]-= initial_value;
2473 else if(mode == WM_RADIALCONTROL_STRENGTH) {
2475 mouse[0]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * (1 - initial_value);
2477 else if(mode == WM_RADIALCONTROL_ANGLE) {
2478 rc->max_value = 360;
2479 mouse[0]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * cos(initial_value);
2480 mouse[1]-= WM_RADIAL_CONTROL_DISPLAY_SIZE * sin(initial_value);
2481 initial_value *= 180.0f/M_PI;
2484 if(op->customdata) {
2485 ImBuf *im = (ImBuf*)op->customdata;
2486 /* Build GL texture */
2487 glGenTextures(1, &rc->tex);
2488 glBindTexture(GL_TEXTURE_2D, rc->tex);
2489 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, im->x, im->y, 0, GL_ALPHA, GL_FLOAT, im->rect_float);
2490 MEM_freeN(im->rect_float);
2494 RNA_int_set_array(op->ptr, "initial_mouse", mouse);
2495 RNA_float_set(op->ptr, "new_value", initial_value);
2497 op->customdata = rc;
2499 rc->initial_value = initial_value;
2500 rc->initial_mouse[0] = mouse[0];
2501 rc->initial_mouse[1] = mouse[1];
2502 rc->cursor = WM_paint_cursor_activate(CTX_wm_manager(C), op->type->poll,
2503 wm_radial_control_paint, op->customdata);
2505 /* add modal handler */
2506 WM_event_add_modal_handler(C, op);
2508 WM_radial_control_modal(C, op, event);
2510 return OPERATOR_RUNNING_MODAL;
2513 /* Gets a descriptive string of the operation */
2514 void WM_radial_control_string(wmOperator *op, char str[], int maxlen)
2516 int mode = RNA_int_get(op->ptr, "mode");
2517 float v = RNA_float_get(op->ptr, "new_value");
2519 if(mode == WM_RADIALCONTROL_SIZE)
2520 sprintf(str, "Size: %d", (int)v);
2521 else if(mode == WM_RADIALCONTROL_STRENGTH)
2522 sprintf(str, "Strength: %d", (int)v);
2523 else if(mode == WM_RADIALCONTROL_ANGLE)
2524 sprintf(str, "Angle: %d", (int)(v * 180.0f/M_PI));
2527 /** Important: this doesn't define an actual operator, it
2528 just sets up the common parts of the radial control op. **/
2529 void WM_OT_radial_control_partial(wmOperatorType *ot)
2531 static EnumPropertyItem radial_mode_items[] = {
2532 {WM_RADIALCONTROL_SIZE, "SIZE", 0, "Size", ""},
2533 {WM_RADIALCONTROL_STRENGTH, "STRENGTH", 0, "Strength", ""},
2534 {WM_RADIALCONTROL_ANGLE, "ANGLE", 0, "Angle", ""},
2535 {0, NULL, 0, NULL, NULL}};
2537 /* Should be set in custom invoke() */
2538 RNA_def_float(ot->srna, "initial_value", 0, 0, FLT_MAX, "Initial Value", "", 0, FLT_MAX);
2540 /* Set internally, should be used in custom exec() to get final value */
2541 RNA_def_float(ot->srna, "new_value", 0, 0, FLT_MAX, "New Value", "", 0, FLT_MAX);
2543 /* Should be set before calling operator */
2544 RNA_def_enum(ot->srna, "mode", radial_mode_items, 0, "Mode", "");
2547 RNA_def_int_vector(ot->srna, "initial_mouse", 2, NULL, INT_MIN, INT_MAX, "initial_mouse", "", INT_MIN, INT_MAX);
2550 /* ************************** timer for testing ***************** */
2552 /* uses no type defines, fully local testing function anyway... ;) */
2554 static int redraw_timer_exec(bContext *C, wmOperator *op)
2556 ARegion *ar= CTX_wm_region(C);
2557 double stime= PIL_check_seconds_timer();
2558 int type = RNA_int_get(op->ptr, "type");
2559 int iter = RNA_int_get(op->ptr, "iterations");
2566 for(a=0; a<iter; a++) {
2568 ED_region_do_draw(C, ar);
2571 wmWindow *win= CTX_wm_window(C);
2573 ED_region_tag_redraw(ar);
2576 CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
2579 wmWindow *win= CTX_wm_window(C);
2582 ScrArea *sa_back= CTX_wm_area(C);
2583 ARegion *ar_back= CTX_wm_region(C);
2585 for(sa= CTX_wm_screen(C)->areabase.first; sa; sa= sa->next) {
2587 CTX_wm_area_set(C, sa);
2589 for(ar_iter= sa->regionbase.first; ar_iter; ar_iter= ar_iter->next) {
2590 if(ar_iter->swinid) {
2591 CTX_wm_region_set(C, ar_iter);
2592 ED_region_do_draw(C, ar_iter);
2597 CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
2599 CTX_wm_area_set(C, sa_back);
2600 CTX_wm_region_set(C, ar_back);
2603 wmWindow *win= CTX_wm_window(C);
2606 for(sa= CTX_wm_screen(C)->areabase.first; sa; sa= sa->next)
2607 ED_area_tag_redraw(sa);
2610 CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
2613 Scene *scene= CTX_data_scene(C);
2615 if(a & 1) scene->r.cfra--;
2616 else scene->r.cfra++;
2617 scene_update_for_newframe(scene, scene->lay);
2625 time= ((PIL_check_seconds_timer()-stime)*1000);
2627 if(type==0) infostr= "Draw Region";
2628 if(type==1) infostr= "Draw Region and Swap";
2629 if(type==2) infostr= "Draw Window";
2630 if(type==3) infostr= "Draw Window and Swap";
2631 if(type==4) infostr= "Animation Steps";
2632 if(type==5) infostr= "Undo/Redo";
2636 BKE_reportf(op->reports, RPT_INFO, "%d x %s: %.2f ms, average: %.4f", iter, infostr, time, time/iter);
2638 return OPERATOR_FINISHED;
2641 static void WM_OT_redraw_timer(wmOperatorType *ot)
2643 static EnumPropertyItem prop_type_items[] = {
2644 {0, "DRAW", 0, "Draw Region", ""},
2645 {1, "DRAW_SWAP", 0, "Draw Region + Swap", ""},
2646 {2, "DRAW_WIN", 0, "Draw Window", ""},
2647 {3, "DRAW_WIN_SWAP", 0, "Draw Window + Swap", ""},
2648 {4, "ANIM_STEP", 0, "Anim Step", ""},
2649 {5, "UNDO", 0, "Undo/Redo", ""},
2650 {0, NULL, 0, NULL, NULL}};
2652 ot->name= "Redraw Timer";
2653 ot->idname= "WM_OT_redraw_timer";
2654 ot->description="Simple redraw timer to test the speed of updating the interface.";
2656 ot->invoke= WM_menu_invoke;
2657 ot->exec= redraw_timer_exec;
2658 ot->poll= WM_operator_winactive;
2660 ot->prop= RNA_def_enum(ot->srna, "type", prop_type_items, 0, "Type", "");
2661 RNA_def_int(ot->srna, "iterations", 10, 1,INT_MAX, "Iterations", "Number of times to redraw", 1,1000);
2665 /* ************************** memory statistics for testing ***************** */
2667 static int memory_statistics_exec(bContext *C, wmOperator *op)
2669 MEM_printmemlist_stats();
2670 return OPERATOR_FINISHED;
2673 static void WM_OT_memory_statistics(wmOperatorType *ot)
2675 ot->name= "Memory Statistics";
2676 ot->idname= "WM_OT_memory_statistics";
2677 ot->description= "Print memory statistics to the console.";
2679 ot->exec= memory_statistics_exec;
2682 /* ******************************************************* */
2684 /* called on initialize WM_exit() */
2685 void wm_operatortype_free(void)
2689 for(ot= global_ops.first; ot; ot= ot->next) {
2691 wm_operatortype_free_macro(ot);
2693 if(ot->ext.srna) /* python operator, allocs own string */
2694 MEM_freeN(ot->idname);
2697 BLI_freelistN(&global_ops);
2700 /* called on initialize WM_init() */
2701 void wm_operatortype_init(void)
2703 WM_operatortype_append(WM_OT_window_duplicate);
2704 WM_operatortype_append(WM_OT_read_homefile);
2705 WM_operatortype_append(WM_OT_save_homefile);
2706 WM_operatortype_append(WM_OT_window_fullscreen_toggle);
2707 WM_operatortype_append(WM_OT_exit_blender);
2708 WM_operatortype_append(WM_OT_open_mainfile);
2709 WM_operatortype_append(WM_OT_link_append);
2710 WM_operatortype_append(WM_OT_recover_last_session);
2711 WM_operatortype_append(WM_OT_recover_auto_save);
2712 WM_operatortype_append(WM_OT_save_as_mainfile);
2713 WM_operatortype_append(WM_OT_save_mainfile);
2714 WM_operatortype_append(WM_OT_redraw_timer);
2715 WM_operatortype_append(WM_OT_memory_statistics);
2716 WM_operatortype_append(WM_OT_debug_menu);
2717 WM_operatortype_append(WM_OT_splash);
2718 WM_operatortype_append(WM_OT_search_menu);
2719 WM_operatortype_append(WM_OT_call_menu);
2722 /* XXX: move these */
2723 WM_operatortype_append(WM_OT_collada_export);
2724 WM_operatortype_append(WM_OT_collada_import);
2729 /* called in transform_ops.c, on each regeneration of keymaps */
2730 static void gesture_circle_modal_keymap(wmKeyConfig *keyconf)
2732 static EnumPropertyItem modal_items[] = {
2733 {GESTURE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
2734 {GESTURE_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
2735 {GESTURE_MODAL_CIRCLE_ADD, "ADD", 0, "Add", ""},
2736 {GESTURE_MODAL_CIRCLE_SUB, "SUBTRACT", 0, "Subtract", ""},
2738 {GESTURE_MODAL_SELECT, "SELECT", 0, "Select", ""},
2739 {GESTURE_MODAL_DESELECT,"DESELECT", 0, "DeSelect", ""},
2740 {GESTURE_MODAL_NOP,"NOP", 0, "No Operation", ""},
2743 {0, NULL, 0, NULL, NULL}};
2745 wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "View3D Gesture Circle");
2747 /* this function is called for each spacetype, only needs to add map once */
2750 keymap= WM_modalkeymap_add(keyconf, "View3D Gesture Circle", modal_items);
2752 /* items for modal map */
2753 WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, GESTURE_MODAL_CANCEL);
2754 WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_ANY, KM_ANY, 0, GESTURE_MODAL_CANCEL);
2756 WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, GESTURE_MODAL_CONFIRM);
2757 WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, 0, 0, GESTURE_MODAL_CONFIRM);
2759 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_SELECT);
2761 #if 0 // Durien guys like this :S
2762 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_SHIFT, 0, GESTURE_MODAL_DESELECT);
2763 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_SHIFT, 0, GESTURE_MODAL_NOP);
2765 WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_DESELECT); // defailt 2.4x
2766 WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, 0, 0, GESTURE_MODAL_NOP); // defailt 2.4x
2769 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, 0, 0, GESTURE_MODAL_NOP);
2771 WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_CIRCLE_SUB);
2772 WM_modalkeymap_add_item(keymap, PADMINUS, KM_PRESS, 0, 0, GESTURE_MODAL_CIRCLE_SUB);
2773 WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_CIRCLE_ADD);
2774 WM_modalkeymap_add_item(keymap, PADPLUSKEY, KM_PRESS, 0, 0, GESTURE_MODAL_CIRCLE_ADD);
2776 /* assign map to operators */
2777 WM_modalkeymap_assign(keymap, "VIEW3D_OT_select_circle");
2778 WM_modalkeymap_assign(keymap, "UV_OT_circle_select");
2782 /* called in transform_ops.c, on each regeneration of keymaps */
2783 static void gesture_border_modal_keymap(wmKeyConfig *keyconf)
2785 static EnumPropertyItem modal_items[] = {
2786 {GESTURE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
2787 {GESTURE_MODAL_SELECT, "SELECT", 0, "Select", ""},
2788 {GESTURE_MODAL_DESELECT,"DESELECT", 0, "DeSelect", ""},
2789 {GESTURE_MODAL_BORDER_BEGIN, "BEGIN", 0, "Begin", ""},
2790 {0, NULL, 0, NULL, NULL}};
2792 wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "Gesture Border");
2794 /* this function is called for each spacetype, only needs to add map once */
2797 keymap= WM_modalkeymap_add(keyconf, "Gesture Border", modal_items);
2799 /* items for modal map */
2800 WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, GESTURE_MODAL_CANCEL);
2801 WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_ANY, KM_ANY, 0, GESTURE_MODAL_CANCEL);
2803 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_BORDER_BEGIN);
2804 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, 0, 0, GESTURE_MODAL_SELECT);
2806 #if 0 // Durian guys like this
2807 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_SHIFT, 0, GESTURE_MODAL_BORDER_BEGIN);
2808 WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_SHIFT, 0, GESTURE_MODAL_DESELECT);
2810 WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_PRESS, 0, 0, GESTURE_MODAL_BORDER_BEGIN);
2811 WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, 0, 0, GESTURE_MODAL_DESELECT);
2814 /* assign map to operators */
2815 WM_modalkeymap_assign(keymap, "ACTION_OT_select_border");
2816 WM_modalkeymap_assign(keymap, "ANIM_OT_channels_select_border");
2817 WM_modalkeymap_assign(keymap, "ANIM_OT_previewrange_set");
2818 WM_modalkeymap_assign(keymap, "CONSOLE_OT_select_border");
2819 WM_modalkeymap_assign(keymap, "FILE_OT_select_border");
2820 WM_modalkeymap_assign(keymap, "GRAPH_OT_select_border");
2821 WM_modalkeymap_assign(keymap, "MARKER_OT_select_border");
2822 WM_modalkeymap_assign(keymap, "NLA_OT_select_border");
2823 WM_modalkeymap_assign(keymap, "NODE_OT_select_border");
2824 // WM_modalkeymap_assign(keymap, "SCREEN_OT_border_select"); // template
2825 WM_modalkeymap_assign(keymap, "SEQUENCER_OT_select_border");
2826 WM_modalkeymap_assign(keymap, "UV_OT_select_border");
2827 WM_modalkeymap_assign(keymap, "VIEW2D_OT_zoom_border");
2828 WM_modalkeymap_assign(keymap, "VIEW3D_OT_clip_border");
2829 WM_modalkeymap_assign(keymap, "VIEW3D_OT_render_border");
2830 WM_modalkeymap_assign(keymap, "VIEW3D_OT_select_border");
2831 WM_modalkeymap_assign(keymap, "VIEW3D_OT_zoom_border"); // XXX TODO: zoom border should perhaps map rightmouse to zoom out instead of in+cancel
2834 /* default keymap for windows and screens, only call once per WM */
2835 void wm_window_keymap(wmKeyConfig *keyconf)
2837 wmKeyMap *keymap= WM_keymap_find(keyconf, "Window", 0, 0);
2840 /* note, this doesn't replace existing keymap items */
2841 WM_keymap_verify_item(keymap, "WM_OT_window_duplicate", WKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
2843 WM_keymap_add_item(keymap, "WM_OT_read_homefile", NKEY, KM_PRESS, KM_OSKEY, 0);
2844 WM_keymap_add_menu(keymap, "INFO_MT_file_open_recent", OKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0);
2845 WM_keymap_add_item(keymap, "WM_OT_open_mainfile", OKEY, KM_PRESS, KM_OSKEY, 0);
2846 WM_keymap_add_item(keymap, "WM_OT_save_mainfile", SKEY, KM_PRESS, KM_OSKEY, 0);
2847 WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", SKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0);
2848 WM_keymap_add_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_OSKEY, 0);
2850 WM_keymap_add_item(keymap, "WM_OT_read_homefile", NKEY, KM_PRESS, KM_CTRL, 0);
2851 WM_keymap_add_item(keymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0);
2852 WM_keymap_add_menu(keymap, "INFO_MT_file_open_recent", OKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
2853 WM_keymap_add_item(keymap, "WM_OT_open_mainfile", OKEY, KM_PRESS, KM_CTRL, 0);
2854 WM_keymap_add_item(keymap, "WM_OT_open_mainfile", F1KEY, KM_PRESS, 0, 0);
2855 WM_keymap_add_item(keymap, "WM_OT_link_append", OKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
2856 kmi= WM_keymap_add_item(keymap, "WM_OT_link_append", F1KEY, KM_PRESS, KM_SHIFT, 0);
2857 RNA_boolean_set(kmi->ptr, "link", FALSE);
2859 WM_keymap_add_item(keymap, "WM_OT_save_mainfile", SKEY, KM_PRESS, KM_CTRL, 0);
2860 WM_keymap_add_item(keymap, "WM_OT_save_mainfile", WKEY, KM_PRESS, KM_CTRL, 0);
2861 WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", SKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
2862 WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", F2KEY, KM_PRESS, 0, 0);
2864 WM_keymap_verify_item(keymap, "WM_OT_window_fullscreen_toggle", F11KEY, KM_PRESS, KM_ALT, 0);
2865 WM_keymap_add_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0);
2868 WM_keymap_verify_item(keymap, "WM_OT_redraw_timer", TKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
2869 WM_keymap_verify_item(keymap, "WM_OT_debug_menu", DKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
2870 WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0);
2872 /* Space switching */
2875 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F2KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was DXF export */
2876 RNA_string_set(kmi->ptr, "path", "area.type");
2877 RNA_string_set(kmi->ptr, "value", "LOGIC_EDITOR");
2879 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F3KEY, KM_PRESS, KM_SHIFT, 0);
2880 RNA_string_set(kmi->ptr, "path", "area.type");
2881 RNA_string_set(kmi->ptr, "value", "NODE_EDITOR");
2883 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F4KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was data browser */
2884 RNA_string_set(kmi->ptr, "path", "area.type");
2885 RNA_string_set(kmi->ptr, "value", "CONSOLE");
2887 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F5KEY, KM_PRESS, KM_SHIFT, 0);
2888 RNA_string_set(kmi->ptr, "path", "area.type");
2889 RNA_string_set(kmi->ptr, "value", "VIEW_3D");
2891 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F6KEY, KM_PRESS, KM_SHIFT, 0);
2892 RNA_string_set(kmi->ptr, "path", "area.type");
2893 RNA_string_set(kmi->ptr, "value", "GRAPH_EDITOR");
2895 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F7KEY, KM_PRESS, KM_SHIFT, 0);
2896 RNA_string_set(kmi->ptr, "path", "area.type");
2897 RNA_string_set(kmi->ptr, "value", "PROPERTIES");
2899 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F8KEY, KM_PRESS, KM_SHIFT, 0);
2900 RNA_string_set(kmi->ptr, "path", "area.type");
2901 RNA_string_set(kmi->ptr, "value", "SEQUENCE_EDITOR");
2903 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F9KEY, KM_PRESS, KM_SHIFT, 0);
2904 RNA_string_set(kmi->ptr, "path", "area.type");
2905 RNA_string_set(kmi->ptr, "value", "OUTLINER");
2907 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F10KEY, KM_PRESS, KM_SHIFT, 0);
2908 RNA_string_set(kmi->ptr, "path", "area.type");
2909 RNA_string_set(kmi->ptr, "value", "IMAGE_EDITOR");
2911 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F11KEY, KM_PRESS, KM_SHIFT, 0);
2912 RNA_string_set(kmi->ptr, "path", "area.type");
2913 RNA_string_set(kmi->ptr, "value", "TEXT_EDITOR");
2915 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F12KEY, KM_PRESS, KM_SHIFT, 0);
2916 RNA_string_set(kmi->ptr, "path", "area.type");
2917 RNA_string_set(kmi->ptr, "value", "DOPESHEET_EDITOR");
2919 gesture_circle_modal_keymap(keyconf);
2920 gesture_border_modal_keymap(keyconf);
2923 /* Generic itemf's for operators that take library args */
2924 static EnumPropertyItem *rna_id_itemf(bContext *C, PointerRNA *ptr, int *free, ID *id)
2926 EnumPropertyItem *item= NULL, item_tmp;
2930 memset(&item_tmp, 0, sizeof(item_tmp));
2932 for( ; id; id= id->next) {
2933 item_tmp.identifier= item_tmp.name= id->name+2;
2934 item_tmp.value= i++;
2935 RNA_enum_item_add(&item, &totitem, &item_tmp);
2938 RNA_enum_item_end(&item, &totitem);
2945 EnumPropertyItem *RNA_group_itemf(bContext *C, PointerRNA *ptr, int *free)
2947 return rna_id_itemf(C, ptr, free, (ID *)CTX_data_main(C)->group.first);
2949 EnumPropertyItem *RNA_scene_itemf(bContext *C, PointerRNA *ptr, int *free)
2951 return rna_id_itemf(C, ptr, free, (ID *)CTX_data_main(C)->scene.first);