diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-02-26 03:57:35 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-02-26 04:00:36 +0300 |
commit | b41bf7a1711f66c8f5b41d313315a644612ef165 (patch) | |
tree | e579590c7b936ecee509bda142f273ca31947d70 /source | |
parent | f3ec08d934bee17252fbed59ceb0d01f88072ede (diff) |
UI: Add 'Copy Python Command' to menu
This feature wasn't exposed anywhere in the interface.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 5 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_ops.c | 48 |
2 files changed, 53 insertions, 0 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index b8e3f6dc821..0ae505777a9 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -6866,6 +6866,11 @@ static bool ui_but_menu(bContext *C, uiBut *but) } } + if (but->optype) { + uiItemO(layout, NULL, + ICON_NONE, "UI_OT_copy_python_command_button"); + } + /* perhaps we should move this into (G.debug & G_DEBUG) - campbell */ if (ui_block_is_menu(but->block) == false) { uiItemFullO(layout, "UI_OT_editsource", NULL, ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0); diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index 346c0879a78..c707ac9eb52 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -151,6 +151,53 @@ static void UI_OT_copy_data_path_button(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER; } +static int copy_python_command_button_poll(bContext *C) +{ + uiBut *but = UI_context_active_but_get(C); + + if (but && (but->optype != NULL)) { + return 1; + } + + return 0; +} + +static int copy_python_command_button_exec(bContext *C, wmOperator *UNUSED(op)) +{ + uiBut *but = UI_context_active_but_get(C); + + if (but && (but->optype != NULL)) { + PointerRNA *opptr; + char *str; + opptr = UI_but_operator_ptr_get(but); /* allocated when needed, the button owns it */ + + str = WM_operator_pystring_ex(C, NULL, false, true, but->optype, opptr); + + WM_clipboard_text_set(str, 0); + + MEM_freeN(str); + + return OPERATOR_FINISHED; + } + + return OPERATOR_CANCELLED; +} + +static void UI_OT_copy_python_command_button(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Copy Python Command"; + ot->idname = "UI_OT_copy_python_command_button"; + ot->description = "Copy the Python command matching this button"; + + /* callbacks */ + ot->exec = copy_python_command_button_exec; + ot->poll = copy_python_command_button_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER; +} + /* Reset to Default Values Button Operator ------------------------ */ static int operator_button_property_finish(bContext *C, PointerRNA *ptr, PropertyRNA *prop) @@ -1044,6 +1091,7 @@ void ED_button_operatortypes(void) { WM_operatortype_append(UI_OT_reset_default_theme); WM_operatortype_append(UI_OT_copy_data_path_button); + WM_operatortype_append(UI_OT_copy_python_command_button); WM_operatortype_append(UI_OT_reset_default_button); WM_operatortype_append(UI_OT_unset_property_button); WM_operatortype_append(UI_OT_copy_to_selected_button); |