diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-10-06 17:04:31 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-10-06 17:04:31 +0400 |
commit | dd8e2897ba19daac5191a341add9955e00798262 (patch) | |
tree | da30b474f92eb4c88887a061c31e19d7bb726151 /source/blender/editors | |
parent | 2011ba50c84d61eff998812944354d444bd00041 (diff) |
new operator - bpy.ops.wm.call_menu(name="SOME_MT_menu")
This calls a registered menu as a popup so we can reuse header menus , currently used for Node editor and Sequencer add menu (Shift+A), can be used for toolbox too.
Diffstat (limited to 'source/blender/editors')
5 files changed, 46 insertions, 13 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 7fea4b10ed9..35598db9e02 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -256,6 +256,7 @@ void uiPupMenuSaveOver(struct bContext *C, struct wmOperator *op, char *filename void uiPupMenuNotice(struct bContext *C, char *str, ...); void uiPupMenuError(struct bContext *C, char *str, ...); void uiPupMenuReports(struct bContext *C, struct ReportList *reports); +void uiPupMenuInvoke(struct bContext *C, const char *idname, int spacetype); /* popup registered menu */ /* Popup Blocks * diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 11dfc44906a..b15be940eef 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -1202,24 +1202,21 @@ static void ui_item_menu(uiLayout *layout, char *name, int icon, uiMenuCreateFun void uiItemM(uiLayout *layout, bContext *C, char *name, int icon, char *menuname) { - ARegion *ar= CTX_wm_region(C); MenuType *mt; - if(!menuname) - return; + mt= BKE_spacemenu_find(menuname, CTX_wm_area(C)->spacetype); - for(mt=ar->type->menutypes.first; mt; mt=mt->next) { - if(strcmp(menuname, mt->idname) == 0) { - if(!name) - name= mt->label; - if(layout->root->type == UI_LAYOUT_MENU && !icon) - icon= ICON_BLANK1; - ui_item_menu(layout, name, icon, ui_item_menutype_func, mt, NULL); - return; - } + if(mt==NULL) { + printf("uiItemM: not found %s\n", menuname); + return; } - printf("uiItemM: not found %s\n", menuname); + if(!name) + name= mt->label; + if(layout->root->type == UI_LAYOUT_MENU && !icon) + icon= ICON_BLANK1; + + ui_item_menu(layout, name, icon, ui_item_menutype_func, mt, NULL); } /* label item */ diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 0f04333c6c5..dae4a54c233 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -2481,6 +2481,34 @@ void uiPupMenuReports(bContext *C, ReportList *reports) BLI_dynstr_free(ds); } +void uiPupMenuInvoke(bContext *C, const char *idname, int spacetype) +{ + uiPopupMenu *pup; + uiLayout *layout; + MenuType *mt= BKE_spacemenu_find(idname, spacetype); + + if(mt==NULL) { + printf("uiPupMenuInvoke: named menu \"%s\" not found\n", idname); + return; + } + + if(mt->poll && mt->poll(C, mt)==0) + return; + + pup= uiPupMenuBegin(C, mt->label, 0); + layout= uiPupMenuLayout(pup); + + Menu menu; + + menu.layout= layout; + menu.type= mt; + + mt->draw(C, &menu); + + uiPupMenuEnd(C, pup); +} + + /*************************** Popup Block API **************************/ void uiPupBlockO(bContext *C, uiBlockCreateFunc func, void *arg, char *opname, int opcontext) diff --git a/source/blender/editors/space_node/node_ops.c b/source/blender/editors/space_node/node_ops.c index f47e9aa2a6f..880cc489838 100644 --- a/source/blender/editors/space_node/node_ops.c +++ b/source/blender/editors/space_node/node_ops.c @@ -70,6 +70,7 @@ void node_operatortypes(void) void node_keymap(struct wmWindowManager *wm) { wmKeyMap *keymap= WM_keymap_find(wm, "Node", SPACE_NODE, 0); + wmKeymapItem *kmi; /* mouse select in nodes used to be both keys, it's UI elements... */ RNA_enum_set(WM_keymap_add_item(keymap, "NODE_OT_select", ACTIONMOUSE, KM_PRESS, 0, 0)->ptr, "select_type", NODE_SELECT_MOUSE); @@ -97,5 +98,8 @@ void node_keymap(struct wmWindowManager *wm) WM_keymap_add_item(keymap, "NODE_OT_group_ungroup", GKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "NODE_OT_group_edit", TABKEY, KM_PRESS, 0, 0); + kmi= WM_keymap_add_item(keymap, "WM_OT_call_menu", AKEY, KM_PRESS, KM_SHIFT, 0); + RNA_string_set(kmi->ptr, "name", "NODE_MT_add"); + transform_keymap_for_space(wm, keymap, SPACE_NODE); } diff --git a/source/blender/editors/space_sequencer/sequencer_ops.c b/source/blender/editors/space_sequencer/sequencer_ops.c index ac125c10b2d..1541b32f566 100644 --- a/source/blender/editors/space_sequencer/sequencer_ops.c +++ b/source/blender/editors/space_sequencer/sequencer_ops.c @@ -177,6 +177,9 @@ void sequencer_keymap(wmWindowManager *wm) WM_keymap_add_item(keymap, "SEQUENCER_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "SEQUENCER_OT_select_border", BKEY, KM_PRESS, 0, 0); + + kmi= WM_keymap_add_item(keymap, "WM_OT_call_menu", AKEY, KM_PRESS, KM_SHIFT, 0); + RNA_string_set(kmi->ptr, "name", "SEQUENCER_MT_add"); WM_keymap_verify_item(keymap, "ANIM_OT_change_frame", LEFTMOUSE, KM_PRESS, 0, 0); |