2.5
authorTon Roosendaal <ton@blender.org>
Fri, 26 Dec 2008 12:21:06 +0000 (12:21 +0000)
committerTon Roosendaal <ton@blender.org>
Fri, 26 Dec 2008 12:21:06 +0000 (12:21 +0000)
Operator calls: extended WM_operator_name_call() with options whether to
call the exec() (operate immediate) or invoke() (check user input) entry.

This will allow python to use it more efficiently, but also solves the
dreaded pulldown case that showed another menu for confirmation.

New names to learn: :)
WM_OP_EXEC_DEFAULT
WM_OP_INVOKE_DEFAULT

on todo still: allow hotkey definitions to do same.

source/blender/editors/interface/interface_regions.c
source/blender/editors/space_time/time_header.c
source/blender/editors/space_view3d/view3d_header.c
source/blender/python/intern/bpy_operator.c
source/blender/windowmanager/WM_types.h
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_keymap.c

index fe7e236a841c2c28811a97ed602cc08a54c34bbb..dca77b94a147a885e1a43c48bf91c71630fda25d 100644 (file)
@@ -1685,7 +1685,7 @@ static void operator_cb(bContext *C, void *arg, int retval)
        const char *opname= arg;
 
        if(opname && retval > 0)
-               WM_operator_name_call(C, opname, WM_OP_DEFAULT, NULL);
+               WM_operator_name_call(C, opname, WM_OP_EXEC_DEFAULT, NULL);
 }
 
 static void vconfirm(bContext *C, char *opname, char *title, char *itemfmt, va_list ap)
index 406ccf0b54cd3c3a973cc1df93d58bba40753c2d..04f01803c1c06924e929e35d574001a2be04f4a5 100644 (file)
@@ -302,18 +302,18 @@ static uiBlock *time_framemenu(bContext *C, uiMenuBlockHandle *handle, void *arg
        block= uiBeginBlock(C, handle->region, "time_framemenu", UI_EMBOSSP, UI_HELV);
        uiBlockSetButmFunc(block, do_time_framemenu, NULL);
 
-       uiDefIconTextButO(C, block, BUTM, "ED_MARKER_OT_add", WM_OP_REGION_WIN, ICON_BLANK1, "Add Marker",
+       uiDefIconTextButO(C, block, BUTM, "ED_MARKER_OT_add", WM_OP_EXEC_REGION_WIN, ICON_BLANK1, "Add Marker",
                                          0, yco-=2, menuwidth, 19, "");
-       uiDefIconTextButO(C, block, BUTM, "ED_MARKER_OT_duplicate", WM_OP_REGION_WIN, ICON_BLANK1, "Duplicate Marker",
+       uiDefIconTextButO(C, block, BUTM, "ED_MARKER_OT_duplicate", WM_OP_EXEC_REGION_WIN, ICON_BLANK1, "Duplicate Marker",
                                          0, yco-=20, menuwidth, 19, "");
-       uiDefIconTextButO(C, block, BUTM, "ED_MARKER_OT_delete", WM_OP_REGION_WIN, ICON_BLANK1, "Delete Marker",
+       uiDefIconTextButO(C, block, BUTM, "ED_MARKER_OT_delete", WM_OP_EXEC_REGION_WIN, ICON_BLANK1, "Delete Marker",
                                          0, yco-=20, menuwidth, 19, "");
        
        uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
        
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Name Marker|Ctrl M",
                                         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
-       uiDefIconTextButO(C, block, BUTM, "ED_MARKER_OT_move", WM_OP_REGION_WIN, ICON_BLANK1, "Grab/Move Marker",
+       uiDefIconTextButO(C, block, BUTM, "ED_MARKER_OT_move", WM_OP_INVOKE_REGION_WIN, ICON_BLANK1, "Grab/Move Marker",
                                          0, yco-=20, menuwidth, 19, "");
        
        uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
index 3cd2e464321f36558dc9696575ac787a8de9fa4d..35c686bc54ee5e760b66ff9f0ea787b01233a9e3 100644 (file)
@@ -461,7 +461,7 @@ static void do_view3d_view_alignviewmenu(bContext *C, void *arg, int event)
 // XXX         mainqenter(PADASTERKEY, 1);
                break;
        case 6: /* Center View and Cursor to Origin */
-               WM_operator_name_call(C, "VIEW3D_OT_viewcenter", WM_OP_REGION_WIN, NULL);
+               WM_operator_name_call(C, "VIEW3D_OT_viewcenter", WM_OP_EXEC_REGION_WIN, NULL);
                curs= give_cursor(scene, v3d);
                curs[0]=curs[1]=curs[2]= 0.0;
                break;
@@ -545,10 +545,10 @@ static void do_view3d_viewmenu(bContext *C, void *arg, int event)
                endlocalview(scene, sa);
                break;
        case 9: /* View All (Home) */
-               WM_operator_name_call(C, "VIEW3D_OT_viewhome", WM_OP_REGION_WIN, NULL);
+               WM_operator_name_call(C, "VIEW3D_OT_viewhome", WM_OP_EXEC_REGION_WIN, NULL);
                break;
        case 11: /* View Selected */
-               WM_operator_name_call(C, "VIEW3D_OT_viewcenter", WM_OP_REGION_WIN, NULL);
+               WM_operator_name_call(C, "VIEW3D_OT_viewcenter", WM_OP_EXEC_REGION_WIN, NULL);
                break;
        case 13: /* Play Back Animation */
                play_anim(0);
@@ -560,7 +560,7 @@ static void do_view3d_viewmenu(bContext *C, void *arg, int event)
                add_blockhandler(sa, VIEW3D_HANDLER_PROPERTIES, UI_PNL_UNSTOW);
                break;
        case 17: /* Set Clipping Border */
-               WM_operator_name_call(C, "VIEW3D_OT_clipping", WM_OP_REGION_WIN, NULL);
+               WM_operator_name_call(C, "VIEW3D_OT_clipping", WM_OP_INVOKE_REGION_WIN, NULL);
                break;
        case 18: /* render preview */
                toggle_blockhandler(sa, VIEW3D_HANDLER_PREVIEW, 0);
@@ -5325,7 +5325,7 @@ static void do_view3d_buttons(bContext *C, void *arg, int event)
 
        switch(event) {
        case B_HOME:
-               WM_operator_name_call(C, "VIEW3D_OT_viewhome", WM_OP_REGION_WIN, NULL);
+               WM_operator_name_call(C, "VIEW3D_OT_viewhome", WM_OP_EXEC_REGION_WIN, NULL);
                break;
        case B_SCENELOCK:
                if(v3d->scenelock) {
index b2cda26975145c6ae8143970757b04366009fded..966253f82a86831cbd31761aa19953901d03505b 100644 (file)
@@ -167,7 +167,7 @@ static PyObject * pyop_func_call(BPy_OperatorFunc * self, PyObject *args, PyObje
        }
 
        if (error_val==0) {
-               WM_operator_name_call(self->C, self->name, WM_OP_DEFAULT, properties);
+               WM_operator_name_call(self->C, self->name, WM_OP_EXEC_DEFAULT, properties);
        }
 
        if (properties) {
index 21d245b08c924717aeaea2e1c3415485311e5893..687a8a6628c91a867f4e97ecdf34987c1f7e3d48 100644 (file)
@@ -41,12 +41,16 @@ struct wmEvent;
 /* flag */
 #define OPTYPE_REGISTER                1
 
-/* context to call operator in for WM_operator_call */
+/* context to call operator in for WM_operator_name_call */
 enum {
-       WM_OP_DEFAULT,
-       WM_OP_REGION_WIN,
-       WM_OP_AREA,
-       WM_OP_SCREEN
+       WM_OP_INVOKE_DEFAULT,
+       WM_OP_INVOKE_REGION_WIN,
+       WM_OP_INVOKE_AREA,
+       WM_OP_INVOKE_SCREEN,
+       WM_OP_EXEC_DEFAULT,
+       WM_OP_EXEC_REGION_WIN,
+       WM_OP_EXEC_AREA,
+       WM_OP_EXEC_SCREEN
 };
 
 /* ************** wmEvent ************************ */
index b9bc38c5927d0d558c2439dba8910dee273c8c16..c10b2b2e28ca31ec2198e5b34d693e6b6b238fdf 100644 (file)
@@ -319,10 +319,12 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, I
                op->ptr= MEM_callocN(sizeof(PointerRNA), "wmOperatorPtrRNA");
                RNA_pointer_create(&RNA_WindowManager, &wm->id, ot->srna, &op->properties, op->ptr);
 
-               if(op->type->invoke)
+               if(op->type->invoke && event)
                        retval= (*op->type->invoke)(C, op, event);
                else if(op->type->exec)
                        retval= op->type->exec(C, op);
+               else
+                       printf("invalid operator call %s\n", ot->idname); /* debug, important to leave a while, should never happen */
 
                /* only for testing, can remove any time */
                WM_operator_print(op);
@@ -343,56 +345,72 @@ int WM_operator_name_call(bContext *C, const char *opstring, int context, IDProp
 {
        wmOperatorType *ot= WM_operatortype_find(opstring);
        wmWindow *window= CTX_wm_window(C);
+       wmEvent *event= window->eventstate;
+       
        int retval;
 
        /* dummie test */
        if(ot && C && window) {
-               if(context == WM_OP_REGION_WIN) {
-                       /* forces event to go to the region window, for header menus */
-                       ARegion *ar= CTX_wm_region(C);
-                       ScrArea *area= CTX_wm_area(C);
+               switch(context) {
                        
-                       if(area) {
-                               ARegion *ar1= area->regionbase.first;
-                               for(; ar1; ar1= ar1->next)
-                                       if(ar1->regiontype==RGN_TYPE_WINDOW)
-                                               break;
-                               if(ar1)
-                                       CTX_wm_region_set(C, ar1);
+                       case WM_OP_EXEC_REGION_WIN:
+                               event= NULL;    /* pass on without break */
+                       case WM_OP_INVOKE_REGION_WIN: 
+                       {
+                               /* forces operator to go to the region window, for header menus */
+                               ARegion *ar= CTX_wm_region(C);
+                               ScrArea *area= CTX_wm_area(C);
+                               
+                               if(area) {
+                                       ARegion *ar1= area->regionbase.first;
+                                       for(; ar1; ar1= ar1->next)
+                                               if(ar1->regiontype==RGN_TYPE_WINDOW)
+                                                       break;
+                                       if(ar1)
+                                               CTX_wm_region_set(C, ar1);
+                               }
+                               
+                               retval= wm_operator_invoke(C, ot, event, properties);
+                               
+                               /* set region back */
+                               CTX_wm_region_set(C, ar);
+                               
+                               return retval;
                        }
-                       
-                       retval= wm_operator_invoke(C, ot, window->eventstate, properties);
-                       
-                       /* set region back */
-                       CTX_wm_region_set(C, ar);
-                       
-                       return retval;
-               }
-               else if(context == WM_OP_AREA) {
-                       /* remove region from context */
-                       ARegion *ar= CTX_wm_region(C);
+                       case WM_OP_EXEC_AREA:
+                               event= NULL;    /* pass on without break */
+                       case WM_OP_INVOKE_AREA:
+                       {
+                                       /* remove region from context */
+                               ARegion *ar= CTX_wm_region(C);
 
-                       CTX_wm_region_set(C, NULL);
-                       retval= wm_operator_invoke(C, ot, window->eventstate, properties);
-                       CTX_wm_region_set(C, ar);
+                               CTX_wm_region_set(C, NULL);
+                               retval= wm_operator_invoke(C, ot, event, properties);
+                               CTX_wm_region_set(C, ar);
 
-                       return retval;
-               }
-               else if(context == WM_OP_SCREEN) {
-                       /* remove region + area from context */
-                       ARegion *ar= CTX_wm_region(C);
-                       ScrArea *area= CTX_wm_area(C);
+                               return retval;
+                       }
+                       case WM_OP_EXEC_SCREEN:
+                               event= NULL;    /* pass on without break */
+                       case WM_OP_INVOKE_SCREEN:
+                       {
+                               /* remove region + area from context */
+                               ARegion *ar= CTX_wm_region(C);
+                               ScrArea *area= CTX_wm_area(C);
 
-                       CTX_wm_region_set(C, NULL);
-                       CTX_wm_area_set(C, NULL);
-                       retval= wm_operator_invoke(C, ot, window->eventstate, properties);
-                       CTX_wm_region_set(C, ar);
-                       CTX_wm_area_set(C, area);
+                               CTX_wm_region_set(C, NULL);
+                               CTX_wm_area_set(C, NULL);
+                               retval= wm_operator_invoke(C, ot, window->eventstate, properties);
+                               CTX_wm_region_set(C, ar);
+                               CTX_wm_area_set(C, area);
 
-                       return retval;
+                               return retval;
+                       }
+                       case WM_OP_EXEC_DEFAULT:
+                               event= NULL;    /* pass on without break */
+                       case WM_OP_INVOKE_DEFAULT:
+                               return wm_operator_invoke(C, ot, event, properties);
                }
-               else
-                       return wm_operator_invoke(C, ot, window->eventstate, properties);
        }
        
        return 0;
index 22616a49af16ed398188f842c7c503a67bdb2875..eac51559269c24501581a6e4cf53e61e753cc837 100644 (file)
@@ -39,6 +39,7 @@
 #include "BKE_context.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
+#include "BKE_utildefines.h"
 
 #include "RNA_access.h"
 #include "RNA_types.h"
@@ -519,7 +520,7 @@ char *WM_key_event_operator_string(bContext *C, char *opname, int opcontext, cha
        ListBase *handlers= NULL;
 
        /* find right handler list based on specified context */
-       if(opcontext == WM_OP_REGION_WIN) {
+       if(ELEM(opcontext, WM_OP_EXEC_REGION_WIN, WM_OP_INVOKE_REGION_WIN)) {
                if(CTX_wm_area(C)) {
                        ARegion *ar= CTX_wm_area(C)->regionbase.first;
                        for(; ar; ar= ar->next)
@@ -530,11 +531,11 @@ char *WM_key_event_operator_string(bContext *C, char *opname, int opcontext, cha
                                handlers= &ar->handlers;
                }
        }
-       else if(opcontext == WM_OP_AREA) {
+       else if(ELEM(opcontext, WM_OP_EXEC_AREA, WM_OP_INVOKE_AREA)) {
                if(CTX_wm_area(C))
                        handlers= &CTX_wm_area(C)->handlers;
        }
-       else if(opcontext == WM_OP_SCREEN) {
+       else if(ELEM(opcontext, WM_OP_EXEC_SCREEN, WM_OP_INVOKE_SCREEN)) {
                if(CTX_wm_window(C))
                        handlers= &CTX_wm_window(C)->handlers;
        }