Operator Execution Contexts Bugfix:
authorJoshua Leung <aligorith@gmail.com>
Sun, 7 Feb 2010 23:39:44 +0000 (23:39 +0000)
committerJoshua Leung <aligorith@gmail.com>
Sun, 7 Feb 2010 23:39:44 +0000 (23:39 +0000)
This commit adds a few more execution contexts for operators, given the increasing tendency for some special regiontypes to exist within areas that must have their own set of special operators.

Examples of these include the "channel" operators in the Animation Editors (i.e. those in the 'Channels' menu), and the "Fit to Preview Window" operator for the Sequencer.

Previously, operators such as these would not function when clicked on from the menus, and they would not show the hotkeys they were mapped to.

Also, fixed a few operator definitions in the Animation Editors which were missing ot->prop defines. This meant that some hotkeys (mainly selection) were shown incorrectly in the menus.

14 files changed:
release/scripts/ui/space_dopesheet.py
release/scripts/ui/space_graph.py
release/scripts/ui/space_sequencer.py
source/blender/blenkernel/BKE_screen.h
source/blender/blenkernel/intern/screen.c
source/blender/editors/animation/anim_channels_edit.c
source/blender/editors/space_action/action_edit.c
source/blender/editors/space_action/action_select.c
source/blender/editors/space_graph/graph_edit.c
source/blender/editors/space_graph/graph_select.c
source/blender/makesrna/intern/rna_ui.c
source/blender/windowmanager/WM_types.h
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_keymap.c

index 2bd0300c465949678659fbdabc00f3c1ebf27271..f0ddc3b4651cfb3e64bb9cb6ca65d2766df63885 100644 (file)
@@ -130,6 +130,8 @@ class DOPESHEET_MT_channel(bpy.types.Menu):
     def draw(self, context):
         layout = self.layout
 
+        layout.operator_context = 'INVOKE_REGION_CHANNELS'
+
         layout.column()
         layout.operator("anim.channels_setting_toggle")
         layout.operator("anim.channels_setting_enable")
index 511ab06d0dad56191d9ece3a5223e07bb7a619aa..3ee85672f2895092f14f7681129cfd1be7d63498 100644 (file)
@@ -133,6 +133,8 @@ class GRAPH_MT_channel(bpy.types.Menu):
     def draw(self, context):
         layout = self.layout
 
+        layout.operator_context = 'INVOKE_REGION_CHANNELS'
+
         layout.column()
         layout.operator("anim.channels_setting_toggle")
         layout.operator("anim.channels_setting_enable")
index 9a63903300e9f296acd1262f47fe883753471077..d1b7affc1be964aaa98651314ed6d18a0df41b57 100644 (file)
@@ -123,7 +123,9 @@ class SEQUENCER_MT_view(bpy.types.Menu):
         if (st.view_type == 'SEQUENCER') or (st.view_type == 'SEQUENCER_PREVIEW'):
             layout.operator("sequencer.view_all", text='View all Sequences')
         if (st.view_type == 'PREVIEW') or (st.view_type == 'SEQUENCER_PREVIEW'):
+            layout.operator_context = 'INVOKE_REGION_PREVIEW'
             layout.operator("sequencer.view_all_preview", text='Fit preview in window')
+            layout.operator_context = 'INVOKE_DEFAULT'
         layout.operator("sequencer.view_selected")
 
         layout.prop(st, "draw_frames")
index 3a0cbd9d8721450e9ef8e8ab649848fd4ac4b30c..ebf4f09ffd4718aa642f19353402d4bc612c1be9 100644 (file)
@@ -234,6 +234,8 @@ struct ARegion *BKE_area_region_copy(struct SpaceType *st, struct ARegion *ar);
 void   BKE_area_region_free(struct SpaceType *st, struct ARegion *ar);
 void   BKE_screen_area_free(struct ScrArea *sa);
 
+struct ARegion *BKE_area_find_region_type(struct ScrArea *sa, int type);
+
 /* screen */
 void free_screen(struct bScreen *sc); 
 unsigned int BKE_screen_visible_layers(struct bScreen *screen, struct Scene *scene);
index 0dc6bf359f6a7d14bac6e671b4325a4591e81c4d..b8ac8d99128970b58b02708228cf73d1b4bec219 100644 (file)
@@ -336,3 +336,19 @@ unsigned int BKE_screen_visible_layers(bScreen *screen, Scene *scene)
        return layer;
 }
 
+/* ***************** Utilities ********************** */
+
+/* Find a region of the specified type from the given area */
+ARegion *BKE_area_find_region_type(ScrArea *sa, int type)
+{
+       if (sa) {
+               ARegion *ar;
+               
+               for (ar=sa->regionbase.first; ar; ar= ar->next) {
+                       if (ar->regiontype == type)
+                               return ar;
+               }
+       }
+       return NULL;
+}
+
index f756c5b3158640025e37b1ed4f0a92271c975af8..a1ad79b065893952fed03d5a34319dcc91092a9d 100644 (file)
@@ -1385,7 +1385,7 @@ void ANIM_OT_channels_expand (wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
-       RNA_def_boolean(ot->srna, "all", 1, "All", "Expand all channels (not just selected ones)");
+       ot->prop= RNA_def_boolean(ot->srna, "all", 1, "All", "Expand all channels (not just selected ones)");
 }
 
 /* ********************** Collapse Channels Operator *********************** */
@@ -1427,7 +1427,7 @@ void ANIM_OT_channels_collapse (wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
-       RNA_def_boolean(ot->srna, "all", 1, "All", "Collapse all channels (not just selected ones)");
+       ot->prop= RNA_def_boolean(ot->srna, "all", 1, "All", "Collapse all channels (not just selected ones)");
 }
 
 /* ********************** Select All Operator *********************** */
@@ -1467,7 +1467,7 @@ void ANIM_OT_channels_select_all_toggle (wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
-       RNA_def_boolean(ot->srna, "invert", 0, "Invert", "");
+       ot->prop= RNA_def_boolean(ot->srna, "invert", 0, "Invert", "");
 }
 
 /* ******************** Borderselect Operator *********************** */
index 22f5989f3aa2ef2e26a5ff7ec9eb944d9371df5f..d91f2788ecdaf0fa7f18395d696e66ae1ca98f6f 100644 (file)
@@ -733,7 +733,7 @@ void ACTION_OT_clean (wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* properties */
-       RNA_def_float(ot->srna, "threshold", 0.001f, 0.0f, FLT_MAX, "Threshold", "", 0.0f, 1000.0f);
+       ot->prop= RNA_def_float(ot->srna, "threshold", 0.001f, 0.0f, FLT_MAX, "Threshold", "", 0.0f, 1000.0f);
 }
 
 /* ******************** Sample Keyframes Operator *********************** */
index 1939057b654f501471e5fc04e84b8fa3f6cc0ce0..c22533f9d45042d0bab631939a85a200c7c6dc7b 100644 (file)
@@ -196,7 +196,7 @@ void ACTION_OT_select_all_toggle (wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
-       RNA_def_boolean(ot->srna, "invert", 0, "Invert", "");
+       ot->prop= RNA_def_boolean(ot->srna, "invert", 0, "Invert", "");
 }
 
 /* ******************** Border Select Operator **************************** */
@@ -362,7 +362,7 @@ void ACTION_OT_select_border(wmOperatorType *ot)
        /* rna */
        WM_operator_properties_gesture_border(ot, FALSE);
        
-       RNA_def_boolean(ot->srna, "axis_range", 0, "Axis Range", "");
+       ot->prop= RNA_def_boolean(ot->srna, "axis_range", 0, "Axis Range", "");
 }
 
 /* ******************** Column Select Operator **************************** */
@@ -571,7 +571,7 @@ void ACTION_OT_select_column (wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
-       RNA_def_enum(ot->srna, "mode", prop_column_select_types, 0, "Mode", "");
+       ot->prop= RNA_def_enum(ot->srna, "mode", prop_column_select_types, 0, "Mode", "");
 }
 
 /* ******************** Select More/Less Operators *********************** */
index dca2b2f3b982ae12a6cae55c76a7bc3e778404b1..40e035759d15dd652702ba6ab2436b3c6f29e0a5 100644 (file)
@@ -924,7 +924,7 @@ void GRAPH_OT_clean (wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* properties */
-       RNA_def_float(ot->srna, "threshold", 0.001f, 0.0f, FLT_MAX, "Threshold", "", 0.0f, 1000.0f);
+       ot->prop= RNA_def_float(ot->srna, "threshold", 0.001f, 0.0f, FLT_MAX, "Threshold", "", 0.0f, 1000.0f);
 }
 
 /* ******************** Bake F-Curve Operator *********************** */
@@ -2013,7 +2013,7 @@ void GRAPH_OT_fmodifier_add (wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* id-props */
-       RNA_def_enum(ot->srna, "type", fmodifier_type_items, 0, "Type", "");
+       ot->prop= RNA_def_enum(ot->srna, "type", fmodifier_type_items, 0, "Type", "");
        RNA_def_boolean(ot->srna, "only_active", 1, "Only Active", "Only add F-Modifier to active F-Curve.");
 }
 
index 872b688bea14e863ed66575c41774c7412b16727..d6ac14809858252f9b56d9dfae30055380001ed7 100644 (file)
@@ -199,7 +199,7 @@ void GRAPH_OT_select_all_toggle (wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/;
        
        /* props */
-       RNA_def_boolean(ot->srna, "invert", 0, "Invert", "");
+       ot->prop= RNA_def_boolean(ot->srna, "invert", 0, "Invert", "");
 }
 
 /* ******************** Border Select Operator **************************** */
@@ -361,7 +361,7 @@ void GRAPH_OT_select_border(wmOperatorType *ot)
        /* rna */
        WM_operator_properties_gesture_border(ot, FALSE);
        
-       RNA_def_boolean(ot->srna, "axis_range", 0, "Axis Range", "");
+       ot->prop= RNA_def_boolean(ot->srna, "axis_range", 0, "Axis Range", "");
 }
 
 /* ******************** Column Select Operator **************************** */
@@ -546,7 +546,7 @@ void GRAPH_OT_select_column (wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/;
        
        /* props */
-       RNA_def_enum(ot->srna, "mode", prop_column_select_types, 0, "Mode", "");
+       ot->prop= RNA_def_enum(ot->srna, "mode", prop_column_select_types, 0, "Mode", "");
 }
 
 /* ******************** Select More/Less Operators *********************** */
index 695eb76cb53f077520dbcca3463e592d2b039035..c5738b58614778de43493b277f910368831ed00a 100644 (file)
@@ -522,10 +522,14 @@ static void rna_def_ui_layout(BlenderRNA *brna)
        static EnumPropertyItem operator_context_items[] = {
                {WM_OP_INVOKE_DEFAULT, "INVOKE_DEFAULT", 0, "Invoke Default", ""},
                {WM_OP_INVOKE_REGION_WIN, "INVOKE_REGION_WIN", 0, "Invoke Region Window", ""},
+               {WM_OP_INVOKE_REGION_CHANNELS, "INVOKE_REGION_CHANNELS", 0, "Invoke Region Channels", ""},
+               {WM_OP_INVOKE_REGION_PREVIEW, "INVOKE_REGION_PREVIEW", 0, "Invoke Region Preview", ""},
                {WM_OP_INVOKE_AREA, "INVOKE_AREA", 0, "Invoke Area", ""},
                {WM_OP_INVOKE_SCREEN, "INVOKE_SCREEN", 0, "Invoke Screen", ""},
                {WM_OP_EXEC_DEFAULT, "EXEC_DEFAULT", 0, "Exec Default", ""},
                {WM_OP_EXEC_REGION_WIN, "EXEC_REGION_WIN", 0, "Exec Region Window", ""},
+               {WM_OP_EXEC_REGION_CHANNELS, "EXEC_REGION_CHANNELS", 0, "Exec Region Channels", ""},
+               {WM_OP_EXEC_REGION_PREVIEW, "EXEC_REGION_PREVIEW", 0, "Exec Region Preview", ""},
                {WM_OP_EXEC_AREA, "EXEC_AREA", 0, "Exec Area", ""},
                {WM_OP_EXEC_SCREEN, "EXEC_SCREEN", 0, "Exec Screen", ""},
                {0, NULL, 0, NULL, NULL}};
index 3efa2b85174f4fff6d0aaf4050ac30a8eb146b7a..7a08320cc19c60e8f10ec379b7b1329c1e288863 100644 (file)
@@ -58,11 +58,15 @@ enum {
        /* if there's invoke, call it, otherwise exec */
        WM_OP_INVOKE_DEFAULT,
        WM_OP_INVOKE_REGION_WIN,
+       WM_OP_INVOKE_REGION_CHANNELS,
+       WM_OP_INVOKE_REGION_PREVIEW,
        WM_OP_INVOKE_AREA,
        WM_OP_INVOKE_SCREEN,
        /* only call exec */
        WM_OP_EXEC_DEFAULT,
        WM_OP_EXEC_REGION_WIN,
+       WM_OP_EXEC_REGION_CHANNELS,
+       WM_OP_EXEC_REGION_PREVIEW,
        WM_OP_EXEC_AREA,
        WM_OP_EXEC_SCREEN
 };
index 7e7dfe7a968a7bd3615b6b0ad66d3eb33f0546bc..685e671c31aadf51c3ce9072808ac2d6399b68df 100644 (file)
@@ -48,6 +48,7 @@
 #include "BKE_main.h"
 #include "BKE_report.h"
 #include "BKE_scene.h"
+#include "BKE_screen.h"
 #include "BKE_utildefines.h"
 
 #include "ED_fileselect.h"
@@ -656,17 +657,37 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, int contex
                        
                        case WM_OP_EXEC_REGION_WIN:
                        case WM_OP_INVOKE_REGION_WIN: 
+                       case WM_OP_EXEC_REGION_CHANNELS:
+                       case WM_OP_INVOKE_REGION_CHANNELS:
+                       case WM_OP_EXEC_REGION_PREVIEW:
+                       case WM_OP_INVOKE_REGION_PREVIEW:
                        {
-                               /* forces operator to go to the region window, for header menus
-                                  but we stay in the same region if we are already in one */
+                               /* forces operator to go to the region window/channels/preview, for header menus
+                                * but we stay in the same region if we are already in one 
+                                */
                                ARegion *ar= CTX_wm_region(C);
                                ScrArea *area= CTX_wm_area(C);
+                               int type = RGN_TYPE_WINDOW;
                                
-                               if(!(ar && ar->regiontype == RGN_TYPE_WINDOW) && area) {
-                                       ARegion *ar1= area->regionbase.first;
-                                       for(; ar1; ar1= ar1->next)
-                                               if(ar1->regiontype==RGN_TYPE_WINDOW)
-                                                       break;
+                               switch (context) {
+                                       case WM_OP_EXEC_REGION_CHANNELS:
+                                       case WM_OP_INVOKE_REGION_CHANNELS:
+                                               type = RGN_TYPE_CHANNELS;
+                                       
+                                       case WM_OP_EXEC_REGION_PREVIEW:
+                                       case WM_OP_INVOKE_REGION_PREVIEW:
+                                               type = RGN_TYPE_PREVIEW;
+                                               break;
+                                       
+                                       case WM_OP_EXEC_REGION_WIN:
+                                       case WM_OP_INVOKE_REGION_WIN: 
+                                       default:
+                                               type = RGN_TYPE_WINDOW;
+                                               break;
+                               }
+                               
+                               if(!(ar && ar->regiontype == type) && area) {
+                                       ARegion *ar1= BKE_area_find_region_type(area, type);
                                        if(ar1)
                                                CTX_wm_region_set(C, ar1);
                                }
index 9b0f682352276302ad01513c8590865ea37670b1..e0d4cf13efd068a08dc63d3223616ec9d2a52c74 100644 (file)
@@ -43,6 +43,7 @@
 #include "BKE_idprop.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
+#include "BKE_screen.h"
 #include "BKE_utildefines.h"
 
 #include "RNA_access.h"
@@ -475,16 +476,27 @@ static wmKeyMapItem *wm_keymap_item_find_props(const bContext *C, const char *op
        if(found==NULL) {
                if(ELEM(opcontext, WM_OP_EXEC_REGION_WIN, WM_OP_INVOKE_REGION_WIN)) {
                        if(sa) {
-                               if(!(ar && ar->regiontype == RGN_TYPE_WINDOW)) {
-                                       for(ar= sa->regionbase.first; ar; ar= ar->next)
-                                               if(ar->regiontype==RGN_TYPE_WINDOW)
-                                                       break;
-                               }
-
+                               if (!(ar && ar->regiontype == RGN_TYPE_WINDOW))
+                                       ar= BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
+                               
                                if(ar)
                                        found= wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, hotkey, compare_props, keymap_r);
                        }
                }
+               else if(ELEM(opcontext, WM_OP_EXEC_REGION_CHANNELS, WM_OP_INVOKE_REGION_CHANNELS)) {
+                       if (!(ar && ar->regiontype == RGN_TYPE_CHANNELS))
+                                       ar= BKE_area_find_region_type(sa, RGN_TYPE_CHANNELS);
+                               
+                               if(ar)
+                                       found= wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, hotkey, compare_props, keymap_r);
+               }
+               else if(ELEM(opcontext, WM_OP_EXEC_REGION_PREVIEW, WM_OP_INVOKE_REGION_PREVIEW)) {
+                       if (!(ar && ar->regiontype == RGN_TYPE_PREVIEW))
+                                       ar= BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW);
+                               
+                               if(ar)
+                                       found= wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, hotkey, compare_props, keymap_r);
+               }
                else {
                        if(ar)
                                found= wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, hotkey, compare_props, keymap_r);