diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 14 | ||||
-rw-r--r-- | source/blender/editors/space_console/console_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_console/console_ops.c | 39 | ||||
-rw-r--r-- | source/blender/editors/space_console/space_console.c | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_operator.c | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 31 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.h | 2 |
7 files changed, 74 insertions, 17 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! diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index 2ffa9db4027..034440d77ac 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -95,7 +95,7 @@ static PyObject *pyop_call( PyObject * self, PyObject * args) RNA_pointer_create(NULL, ot->srna, NULL, &ptr); if(kw && PyDict_Size(kw)) - error_val= pyrna_pydict_to_props(&ptr, kw, "Converting py args to operator properties: "); + error_val= pyrna_pydict_to_props(&ptr, kw, 0, "Converting py args to operator properties: "); if (error_val==0) { diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 91e443dbc93..27bfb89b963 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -375,9 +375,9 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop) return ret; } -/* This function is only used by operators right now - * Its used for taking keyword args and filling in property values */ -int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, const char *error_prefix) +/* This function is used by operators and converting dicts into collections. + * Its takes keyword args and fills them with property values */ +int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const char *error_prefix) { int error_val = 0; int totkw; @@ -397,20 +397,21 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, const char *error_prefi break; } - item= PyDict_GetItemString(kw, arg_name); + item= PyDict_GetItemString(kw, arg_name); /* wont set an error */ if (item == NULL) { - PyErr_Format( PyExc_TypeError, "%.200s: keyword \"%.200s\" missing", error_prefix, arg_name ? arg_name : "<UNKNOWN>"); - error_val = -1; /* pyrna_py_to_prop sets the error */ - break; - } - - if (pyrna_py_to_prop(ptr, prop, NULL, item, error_prefix)) { - error_val= -1; - break; + if(all_args) { + PyErr_Format( PyExc_TypeError, "%.200s: keyword \"%.200s\" missing", error_prefix, arg_name ? arg_name : "<UNKNOWN>"); + error_val = -1; /* pyrna_py_to_prop sets the error */ + break; + } + } else { + if (pyrna_py_to_prop(ptr, prop, NULL, item, error_prefix)) { + error_val= -1; + break; + } + totkw--; } - - totkw--; } RNA_STRUCT_END; @@ -753,7 +754,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v else RNA_property_collection_add(ptr, prop, &itemptr); - if(pyrna_pydict_to_props(&itemptr, item, "Converting a python list to an RNA collection")==-1) { + if(pyrna_pydict_to_props(&itemptr, item, 1, "Converting a python list to an RNA collection")==-1) { Py_DECREF(item); return -1; } diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h index 76e4a13c167..9138fd511b0 100644 --- a/source/blender/python/intern/bpy_rna.h +++ b/source/blender/python/intern/bpy_rna.h @@ -70,7 +70,7 @@ PyObject *pyrna_prop_CreatePyObject( PointerRNA *ptr, PropertyRNA *prop ); /* operators also need this to set args */ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *value, const char *error_prefix); -int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, const char *error_prefix); +int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const char *error_prefix); PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop); /* functions for setting up new props - experemental */ |