Operator Execution Contexts Bugfix:

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.
This commit is contained in:
Joshua Leung 2010-02-07 23:39:44 +00:00
parent f99d06bc83
commit 2f72b91a54
14 changed files with 90 additions and 25 deletions

@ -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")

@ -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")

@ -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")

@ -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);

@ -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;
}

@ -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 *********************** */

@ -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 *********************** */

@ -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 *********************** */

@ -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.");
}

@ -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 *********************** */

@ -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}};

@ -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
};

@ -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);
}

@ -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);