2.5
authorTon Roosendaal <ton@blender.org>
Wed, 17 Dec 2008 15:38:40 +0000 (15:38 +0000)
committerTon Roosendaal <ton@blender.org>
Wed, 17 Dec 2008 15:38:40 +0000 (15:38 +0000)
- Made a nice generic 'OK confirm' implementation for operators.
  Just use in operator type definition this line:

  ot->invoke= WM_operator_confirm;

  It will autmatically use operator name for asking OK. It will
  also use properties (if set before).

  Note for Brecht: the test okee_operator() you coded could better not
  be used in operators themselves.

  In future we can also add menus that get automatically generated
  based on operator properties. Like 'add constraint' showing the
  constraint types.

- Added this confirm call for most of the keys you'd expect it for.
  (user settings, delete marker, rip area, split region, etc).

- Cleanup: moved ed_markers.c to the util/ directory, it doesnt belong
  in space_time. Also made separate function for the marker keymap
  definition.

- removed ancient redraw notifier from ghost event level (every key
  press gave full screen draw)

source/blender/editors/include/ED_markers.h
source/blender/editors/screen/screen_ops.c
source/blender/editors/space_time/time_ops.c
source/blender/editors/util/ed_markers.c [moved from source/blender/editors/space_time/ed_markers.c with 94% similarity]
source/blender/windowmanager/intern/wm_operators.c
source/blender/windowmanager/intern/wm_window.c

index cad985ce37c4fca4b35c68719c4d6a10c191bc78..49f805e4ddbe83ed971cfd0c8e6fcaddca2b9349 100644 (file)
@@ -34,13 +34,14 @@ enum {
        DRAW_MARKERS_LOCAL      = (1<<1)
 };
 
-
+struct wmWindowManager;
 
 void draw_markers_time(const bContext *C, int flag);
 
-/* register operators, called in ED_operatortypes_screen() */
+/* called in screen_ops.c:ED_operatortypes_screen() */
 void ED_marker_operatortypes(void); 
-
+/* called in screen_ops.c:ED_keymap_screen() */
+void ED_marker_keymap(struct wmWindowManager *wm);
 
 #endif /* ED_MARKERS_H */
 
index d16ad075bf3c27b6f3a8ee8c11dc1e9c8376fc73..2ad839997db806957607cb25a7a494a0a96ac909 100644 (file)
@@ -271,7 +271,7 @@ void ED_SCR_OT_area_rip(wmOperatorType *ot)
        ot->name= "Rip Area into New Window";
        ot->idname= "ED_SCR_OT_area_rip";
        
-       ot->invoke= NULL; //WM_operator_confirm;
+       ot->invoke= WM_operator_confirm;
        ot->exec= screen_area_rip_op;
        ot->poll= ED_operator_areaactive;
 }
@@ -1124,6 +1124,7 @@ void ED_SCR_OT_repeat_last(wmOperatorType *ot)
        ot->idname= "ED_SCR_OT_repeat_last";
        
        /* api callbacks */
+       ot->invoke= WM_operator_confirm;        
        ot->exec= repeat_last_exec;
        
        ot->poll= ED_operator_screenactive;
@@ -1161,6 +1162,7 @@ void ED_SCR_OT_region_split(wmOperatorType *ot)
        ot->idname= "ED_SCR_OT_region_split";
        
        /* api callbacks */
+       ot->invoke= WM_operator_confirm;
        ot->exec= region_split_exec;
        ot->poll= ED_operator_areaactive;
        
@@ -1196,6 +1198,7 @@ void ED_SCR_OT_region_flip(wmOperatorType *ot)
        ot->idname= "ED_SCR_OT_region_flip";
        
        /* api callbacks */
+       ot->invoke= WM_operator_confirm;
        ot->exec= region_flip_exec;
        
        ot->poll= ED_operator_areaactive;
@@ -1299,5 +1302,8 @@ void ED_keymap_screen(wmWindowManager *wm)
        RNA_enum_set(WM_keymap_add_item(keymap, "ED_SCR_OT_region_split", SKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "dir", 'v');
        WM_keymap_add_item(keymap, "ED_SCR_OT_region_flip", F5KEY, KM_PRESS, 0, 0);
        WM_keymap_verify_item(keymap, "ED_SCR_OT_repeat_last", F4KEY, KM_PRESS, 0, 0);
+       
+       /* screen level global keymaps */
+       ED_marker_keymap(wm);
 }
 
index c95e7fd7e9db6c8a366407eb699c4f74c9c29cb0..599594a3ec0d446e9707623391763b0465e77c9e 100644 (file)
@@ -217,22 +217,5 @@ void time_keymap(wmWindowManager *wm)
        
        WM_keymap_verify_item(keymap, "ED_TIME_OT_change_frame", LEFTMOUSE, KM_PRESS, 0, 0);
        WM_keymap_verify_item(keymap, "ED_TIME_OT_toggle_time", TKEY, KM_PRESS, 0, 0);
-       
-       /* markers (XXX move to function?) */
-       keymap= WM_keymap_listbase(wm, "Markers", 0, 0);
-       WM_keymap_verify_item(keymap, "ED_MARKER_OT_add", MKEY, KM_PRESS, 0, 0);
-       WM_keymap_verify_item(keymap, "ED_MARKER_OT_move", EVT_TWEAK_R, KM_ANY, 0, 0);
-       WM_keymap_verify_item(keymap, "ED_MARKER_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
-       WM_keymap_verify_item(keymap, "ED_MARKER_OT_mouseselect", RIGHTMOUSE, KM_PRESS, 0, 0);
-       WM_keymap_verify_item(keymap, "ED_MARKER_OT_mouseselect_extend", RIGHTMOUSE, KM_PRESS, KM_SHIFT, 0);
-       WM_keymap_verify_item(keymap, "ED_MARKER_OT_border_select", BKEY, KM_PRESS, 0, 0);
-       WM_keymap_verify_item(keymap, "ED_MARKER_OT_select_all", AKEY, KM_PRESS, 0, 0);
-       WM_keymap_verify_item(keymap, "ED_MARKER_OT_delete", XKEY, KM_PRESS, 0, 0);
-       
-       WM_keymap_add_item(keymap, "ED_MARKER_OT_move", GKEY, KM_PRESS, 0, 0);
-                                                 
-       /* generates event, in end to make select work */
-       WM_keymap_verify_item(keymap, "WM_OT_tweak_gesture", RIGHTMOUSE, KM_PRESS, 0, 0);
-       
 }
 
similarity index 94%
rename from source/blender/editors/space_time/ed_markers.c
rename to source/blender/editors/util/ed_markers.c
index 0dc68fb4b275960ee3ac170b2914d0cbb8a5ba50..843a81e708635c81ba7a0381c530f0b9dd674e0c 100644 (file)
@@ -197,6 +197,7 @@ static int ed_marker_add(bContext *C, wmOperator *op)
        sprintf(marker->name, "Frame %d", frame); // XXX - temp code only
        BLI_addtail(markers, marker);
        
+       WM_event_add_notifier(C, WM_NOTE_MARKERS_CHANGED, 0, NULL);
        //BIF_undo_push("Add Marker");
        
        return OPERATOR_FINISHED;
@@ -824,6 +825,7 @@ static void ED_MARKER_OT_delete(wmOperatorType *ot)
        ot->idname= "ED_MARKER_OT_delete";
        
        /* api callbacks */
+       ot->invoke= WM_operator_confirm;
        ot->exec= ed_marker_delete_exec;
        ot->poll= ED_operator_areaactive;
        
@@ -831,7 +833,7 @@ static void ED_MARKER_OT_delete(wmOperatorType *ot)
 
 /* ************************** registration **********************************/
 
-/* called in ED_operatortypes_screen() */
+/* called in screen_ops.c:ED_operatortypes_screen() */
 void ED_marker_operatortypes(void)
 {
        WM_operatortype_append(ED_MARKER_OT_add);
@@ -844,4 +846,23 @@ void ED_marker_operatortypes(void)
        WM_operatortype_append(ED_MARKER_OT_delete);
 }
 
+/* called in screen_ops.c:ED_keymap_screen() */
+void ED_marker_keymap(wmWindowManager *wm)
+{
+       ListBase *keymap= WM_keymap_listbase(wm, "Markers", 0, 0);
+       
+       WM_keymap_verify_item(keymap, "ED_MARKER_OT_add", MKEY, KM_PRESS, 0, 0);
+       WM_keymap_verify_item(keymap, "ED_MARKER_OT_move", EVT_TWEAK_R, KM_ANY, 0, 0);
+       WM_keymap_verify_item(keymap, "ED_MARKER_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
+       WM_keymap_verify_item(keymap, "ED_MARKER_OT_mouseselect", RIGHTMOUSE, KM_PRESS, 0, 0);
+       WM_keymap_verify_item(keymap, "ED_MARKER_OT_mouseselect_extend", RIGHTMOUSE, KM_PRESS, KM_SHIFT, 0);
+       WM_keymap_verify_item(keymap, "ED_MARKER_OT_border_select", BKEY, KM_PRESS, 0, 0);
+       WM_keymap_verify_item(keymap, "ED_MARKER_OT_select_all", AKEY, KM_PRESS, 0, 0);
+       WM_keymap_verify_item(keymap, "ED_MARKER_OT_delete", XKEY, KM_PRESS, 0, 0);
        
+       WM_keymap_add_item(keymap, "ED_MARKER_OT_move", GKEY, KM_PRESS, 0, 0);
+       
+       /* generates event, in end to make select work */
+       WM_keymap_verify_item(keymap, "WM_OT_tweak_gesture", RIGHTMOUSE, KM_PRESS, 0, 0);
+       
+}
index e87451c2a8e4ca8d937803e803a559e4ba6cd354..897b7b23a0efdfafb472144aba7ce578ee97017b 100644 (file)
@@ -47,6 +47,7 @@
 #include "RNA_define.h"
 
 #include "UI_interface.h"
+#include "UI_resources.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -88,13 +89,24 @@ void WM_operatortype_append(void (*opfunc)(wmOperatorType*))
 
 /* ************ default op callbacks, exported *********** */
 
+static void operator_callback(bContext *C, void *arg, int retval)
+{
+       wmOperator *op= arg;
+       
+       if(retval > 0)
+               op->type->exec(C, op);
+}
+
 int WM_operator_confirm(bContext *C, wmOperator *op, wmEvent *event)
 {
-//     if(okee(op->type->name)) {
-//             return op->type->exec(C, op);
-//     }
-       return 0;
+       char buf[512];
+       
+       sprintf(buf, "OK? %%i%d%%t|%s", ICON_HELP, op->type->name);
+       pupmenu(C, buf, event->x, event->y, operator_callback, op);
+       
+       return 1;
 }
+
 int WM_operator_winactive(bContext *C)
 {
        if(C->window==NULL) return 0;
@@ -108,7 +120,7 @@ static void WM_OT_window_duplicate(wmOperatorType *ot)
        ot->name= "Duplicate Window";
        ot->idname= "WM_OT_window_duplicate";
        
-       ot->invoke= NULL; //WM_operator_confirm;
+       ot->invoke= WM_operator_confirm;
        ot->exec= wm_window_duplicate_op;
        ot->poll= WM_operator_winactive;
 }
@@ -118,7 +130,7 @@ static void WM_OT_save_homefile(wmOperatorType *ot)
        ot->name= "Save User Settings";
        ot->idname= "WM_OT_save_homefile";
        
-       ot->invoke= NULL; //WM_operator_confirm;
+       ot->invoke= WM_operator_confirm;
        ot->exec= WM_write_homefile;
        ot->poll= WM_operator_winactive;
        
@@ -130,7 +142,7 @@ static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
     ot->name= "Toggle Fullscreen";
     ot->idname= "WM_OT_window_fullscreen_toggle";
 
-    ot->invoke= NULL;
+    ot->invoke= WM_operator_confirm;
     ot->exec= wm_window_fullscreen_toggle_op;
     ot->poll= WM_operator_winactive;
 }
@@ -140,27 +152,11 @@ static void WM_OT_exit_blender(wmOperatorType *ot)
        ot->name= "Exit Blender";
        ot->idname= "WM_OT_exit_blender";
 
-       ot->invoke= NULL; /* do confirm stuff */
+       ot->invoke= WM_operator_confirm;
        ot->exec= wm_exit_blender_op;
        ot->poll= WM_operator_winactive;
 }
 
-static int exit_okee_blender_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       okee_operator(C, "WM_OT_exit_blender", "Quit Blender");
-
-       return OPERATOR_FINISHED;
-}
-
-static void WM_OT_exit_okee_blender(wmOperatorType *ot)
-{
-       ot->name= "Exit Blender";
-       ot->idname= "WM_OT_exit_okee_blender";
-
-       ot->invoke= exit_okee_blender_invoke;
-       ot->poll= WM_operator_winactive;
-}
-
 /* ************ window gesture operator-callback definitions ************** */
 /*
  * These are default callbacks for use in operators requiring gesture input
@@ -366,7 +362,6 @@ void wm_operatortype_init(void)
        WM_operatortype_append(WM_OT_save_homefile);
        WM_operatortype_append(WM_OT_window_fullscreen_toggle);
        WM_operatortype_append(WM_OT_exit_blender);
-       WM_operatortype_append(WM_OT_exit_okee_blender);
        WM_operatortype_append(WM_OT_tweak_gesture);
 }
 
@@ -379,6 +374,6 @@ void wm_window_keymap(wmWindowManager *wm)
        WM_keymap_verify_item(keymap, "WM_OT_window_duplicate", AKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
        WM_keymap_verify_item(keymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0);
        WM_keymap_verify_item(keymap, "WM_OT_window_fullscreen_toggle", FKEY, KM_PRESS, 0, 0);
-       WM_keymap_verify_item(keymap, "WM_OT_exit_okee_blender", QKEY, KM_PRESS, KM_CTRL, 0);
+       WM_keymap_verify_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0);
 }
 
index 6f723d02f306ecf932b538e72f8077edf590f9ab..84c003c8a00225ad91894a8e77d3093374d7d2d3 100644 (file)
@@ -474,8 +474,6 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private)
                                break;
                        }
                        default:
-                               if(type==GHOST_kEventKeyDown) // XXX debug
-                                       WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
                                wm_event_add_ghostevent(win, type, data);
                                break;
                }