From 2cd6a89d07e031901291ab95b9a5d6cdeb372bbe Mon Sep 17 00:00:00 2001 From: christian brinkmann <> Date: Thu, 20 Oct 2016 00:27:14 +0200 Subject: Python API: add full_path parameter for bpy.ops.ui.copy_data_path_button. Also use the operator as part of the UI keymap now, to deduplicate code and let users configure a custom shortcut. Reviewed By: brecht Differential Revision: https://developer.blender.org/D2303 --- .../blender/editors/interface/interface_handlers.c | 35 +--------------------- source/blender/editors/interface/interface_ops.c | 34 ++++++++++++++++++--- 2 files changed, 31 insertions(+), 38 deletions(-) (limited to 'source') diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 369eba66f32..863f5e3852c 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -2218,32 +2218,6 @@ static void ui_but_drop(bContext *C, const wmEvent *event, uiBut *but, uiHandleB /* ******************* copy and paste ******************** */ -static void ui_but_copy_data_path(uiBut *but, const bool full_path) -{ - char *id_path; - - if (but->rnapoin.id.data == NULL) { - return; - } - - if (full_path) { - if (but->rnaprop) { - id_path = RNA_path_full_property_py_ex(&but->rnapoin, but->rnaprop, but->rnaindex, true); - } - else { - id_path = RNA_path_full_struct_py(&but->rnapoin); - } - } - else { - id_path = RNA_path_from_ID_to_property(&but->rnapoin, but->rnaprop); - } - - if (id_path) { - WM_clipboard_text_set(id_path, false); - MEM_freeN(id_path); - } -} - /* c = copy, v = paste */ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data, char mode) { @@ -6985,7 +6959,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * if ((data->state == BUTTON_STATE_HIGHLIGHT) || (event->type == EVT_DROP)) { /* handle copy-paste */ if (ELEM(event->type, CKEY, VKEY) && event->val == KM_PRESS && - IS_EVENT_MOD(event, ctrl, oskey)) + IS_EVENT_MOD(event, ctrl, oskey) && !event->shift && !event->alt) { /* Specific handling for listrows, we try to find their overlapping tex button. */ if (but->type == UI_BTYPE_LISTROW) { @@ -6995,13 +6969,6 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * data = but->active; } } - - /* special case, copy-data-path */ - if ((event->type == CKEY) && event->shift) { - ui_but_copy_data_path(but, event->alt != 0); - return WM_UI_HANDLER_BREAK; - } - ui_but_copy_paste(C, but, data, (event->type == CKEY) ? 'c' : 'v'); return WM_UI_HANDLER_BREAK; } diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index 7e516474bfd..40ebc946e79 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -113,19 +113,33 @@ static int copy_data_path_button_poll(bContext *C) return 0; } -static int copy_data_path_button_exec(bContext *C, wmOperator *UNUSED(op)) +static int copy_data_path_button_exec(bContext *C, wmOperator *op) { PointerRNA ptr; PropertyRNA *prop; char *path; int index; + const bool full_path = RNA_boolean_get(op->ptr, "full_path"); + /* try to create driver using property retrieved from UI */ UI_context_active_but_prop_get(C, &ptr, &prop, &index); - if (ptr.id.data && ptr.data && prop) { - path = RNA_path_from_ID_to_property(&ptr, prop); - + if (ptr.id.data != NULL) { + + if (full_path) { + + if (prop) { + path = RNA_path_full_property_py_ex(&ptr, prop, index, true); + } + else { + path = RNA_path_full_struct_py(&ptr); + } + } + else { + path = RNA_path_from_ID_to_property(&ptr, prop); + } + if (path) { WM_clipboard_text_set(path, false); MEM_freeN(path); @@ -138,6 +152,8 @@ static int copy_data_path_button_exec(bContext *C, wmOperator *UNUSED(op)) static void UI_OT_copy_data_path_button(wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name = "Copy Data Path"; ot->idname = "UI_OT_copy_data_path_button"; @@ -149,6 +165,10 @@ static void UI_OT_copy_data_path_button(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER; + + /* properties */ + prop = RNA_def_boolean(ot->srna, "full_path", false, "full_path", "Copy full data path"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } static int copy_python_command_button_poll(bContext *C) @@ -1115,6 +1135,7 @@ void ED_operatortypes_ui(void) void ED_keymap_ui(wmKeyConfig *keyconf) { wmKeyMap *keymap = WM_keymap_find(keyconf, "User Interface", 0, 0); + wmKeyMapItem *kmi; /* eyedroppers - notice they all have the same shortcut, but pass the event * through until a suitable eyedropper for the active button is found */ @@ -1122,6 +1143,11 @@ void ED_keymap_ui(wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "UI_OT_eyedropper_id", EKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "UI_OT_eyedropper_depth", EKEY, KM_PRESS, 0, 0); + /* Copy Data Path */ + WM_keymap_add_item(keymap, "UI_OT_copy_data_path_button", CKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0); + kmi = WM_keymap_add_item(keymap, "UI_OT_copy_data_path_button", CKEY, KM_PRESS, KM_CTRL | KM_SHIFT | KM_ALT, 0); + RNA_boolean_set(kmi->ptr, "full_path", true); + /* keyframes */ WM_keymap_add_item(keymap, "ANIM_OT_keyframe_insert_button", IKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "ANIM_OT_keyframe_delete_button", IKEY, KM_PRESS, KM_ALT, 0); -- cgit v1.2.3