[Bf-blender-cvs] [b41bf7a] master: UI: Add 'Copy Python Command' to menu
Campbell Barton
noreply at git.blender.org
Fri Feb 26 02:08:28 CET 2016
Commit: b41bf7a1711f66c8f5b41d313315a644612ef165
Author: Campbell Barton
Date: Fri Feb 26 11:57:35 2016 +1100
Branches: master
https://developer.blender.org/rBb41bf7a1711f66c8f5b41d313315a644612ef165
UI: Add 'Copy Python Command' to menu
This feature wasn't exposed anywhere in the interface.
===================================================================
M source/blender/editors/interface/interface_handlers.c
M source/blender/editors/interface/interface_ops.c
===================================================================
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index b8e3f6d..0ae5057 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 346c087..c707ac9 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);
More information about the Bf-blender-cvs
mailing list