From b41bf7a1711f66c8f5b41d313315a644612ef165 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 26 Feb 2016 11:57:35 +1100 Subject: UI: Add 'Copy Python Command' to menu This feature wasn't exposed anywhere in the interface. --- source/blender/editors/interface/interface_ops.c | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'source/blender/editors/interface/interface_ops.c') 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); -- cgit v1.2.3