diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-07-30 05:52:00 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-07-30 05:52:00 +0400 |
commit | 39ea55fff1e0ce362bb5e9bc958b6d651293e30d (patch) | |
tree | c94e2c02e60428d7d4115538ece8a749016501ae /source/blender/editors | |
parent | 24a269a07c150d449363b455d4de89a88151d651 (diff) |
Operator Copy/Paste
you can copy operator strings from buttons or the reporting interface and run them in the console.
- Ctrl+C over an operator button copies its python string to the clipboard.
- Paste in the console (1 line only for now).
- operators run from python no longer require all arguments.
Diffstat (limited to 'source/blender/editors')
4 files changed, 56 insertions, 0 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index da2899dd3b2..30cfafb24f8 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -961,6 +961,20 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data, button_activate_state(C, but, BUTTON_STATE_EXIT); } } + /* operator button (any type) */ + else if (but->optype) { + if(mode=='c') { + PointerRNA *opptr; + char *str; + opptr= uiButGetOperatorPtrRNA(but); /* allocated when needed, the button owns it */ + + str= WM_operator_pystring(but->optype, opptr, 0); + + WM_clipboard_text_set(str, 0); + + MEM_freeN(str); + } + } } /* ************* in-button text selection/editing ************* */ diff --git a/source/blender/editors/space_console/console_intern.h b/source/blender/editors/space_console/console_intern.h index 62caad83144..6d002efcc8e 100644 --- a/source/blender/editors/space_console/console_intern.h +++ b/source/blender/editors/space_console/console_intern.h @@ -61,6 +61,7 @@ void CONSOLE_OT_scrollback_append(wmOperatorType *ot); void CONSOLE_OT_clear(wmOperatorType *ot); void CONSOLE_OT_history_cycle(wmOperatorType *ot); void CONSOLE_OT_copy(wmOperatorType *ot); +void CONSOLE_OT_paste(wmOperatorType *ot); void CONSOLE_OT_zoom(wmOperatorType *ot); diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c index 2637a4fb1a9..fa9055f2d8d 100644 --- a/source/blender/editors/space_console/console_ops.c +++ b/source/blender/editors/space_console/console_ops.c @@ -205,6 +205,11 @@ static int console_line_insert(ConsoleLine *ci, char *str) { int len = strlen(str); + if(len>0 && str[len-1]=='\n') {/* stop new lines being pasted at the end of lines */ + str[len-1]= '\0'; + len--; + } + if(len==0) return 0; @@ -621,6 +626,40 @@ void CONSOLE_OT_copy(wmOperatorType *ot) /* properties */ } +static int paste_exec(bContext *C, wmOperator *op) +{ + ConsoleLine *ci= console_history_verify(C); + + char *buf_str= WM_clipboard_text_get(0); + + if(buf_str==NULL) + return OPERATOR_CANCELLED; + + console_line_insert(ci, buf_str); /* TODO - Multiline copy?? */ + + MEM_freeN(buf_str); + + ED_area_tag_redraw(CTX_wm_area(C)); + + return OPERATOR_FINISHED; +} + +void CONSOLE_OT_paste(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Paste from Clipboard"; + ot->idname= "CONSOLE_OT_paste"; + + /* api callbacks */ + ot->poll= console_edit_poll; + ot->exec= paste_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER; + + /* properties */ +} + static int zoom_exec(bContext *C, wmOperator *op) { SpaceConsole *sc= CTX_wm_space_console(C); diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c index e406cc5a561..a763e7ce153 100644 --- a/source/blender/editors/space_console/space_console.c +++ b/source/blender/editors/space_console/space_console.c @@ -215,6 +215,7 @@ void console_operatortypes(void) WM_operatortype_append(CONSOLE_OT_clear); WM_operatortype_append(CONSOLE_OT_history_cycle); WM_operatortype_append(CONSOLE_OT_copy); + WM_operatortype_append(CONSOLE_OT_paste); WM_operatortype_append(CONSOLE_OT_zoom); @@ -295,6 +296,7 @@ void console_keymap(struct wmWindowManager *wm) WM_keymap_add_item(keymap, "CONSOLE_OT_report_copy", CKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "CONSOLE_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "CONSOLE_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0); RNA_string_set(WM_keymap_add_item(keymap, "CONSOLE_OT_insert", TABKEY, KM_PRESS, 0, 0)->ptr, "text", " "); /* fake tabs */ WM_keymap_add_item(keymap, "CONSOLE_OT_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); // last! |