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.
This commit is contained in:
@@ -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 ************* */
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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!
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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(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--;
|
||||
}
|
||||
|
||||
if (pyrna_py_to_prop(ptr, prop, NULL, item, error_prefix)) {
|
||||
error_val= -1;
|
||||
break;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user