From f08a8c5b156a5a26c5f7428b77e803edef09cdab Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 20 Jan 2012 22:32:47 +0000 Subject: modify number button copy/paste to work as if you enter the button, select text, type into another button the same value. This means you can copy/paste units and python expressions. --- source/blender/editors/interface/interface.c | 19 +++++++++++++------ source/blender/editors/interface/interface_handlers.c | 14 ++++++-------- source/blender/editors/interface/interface_intern.h | 1 + 3 files changed, 20 insertions(+), 14 deletions(-) (limited to 'source/blender/editors/interface') diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 7ff69277843..492d5482dd9 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -1693,10 +1693,15 @@ static int ui_set_but_string_eval_num_unit(bContext *C, uiBut *but, const char * return (BPY_button_exec(C, str_unit_convert, value, TRUE) != -1); } -static int ui_set_but_string_eval_num(bContext *C, uiBut *but, const char *str, double *value) +#endif /* WITH_PYTHON */ + + +int ui_set_but_string_eval_num(bContext *C, uiBut *but, const char *str, double *value) { int ok= FALSE; +#ifdef WITH_PYTHON + if(str[0] != '\0') { int is_unit_but= ui_is_but_unit(but); /* only enable verbose if we won't run again with units */ @@ -1718,10 +1723,16 @@ static int ui_set_but_string_eval_num(bContext *C, uiBut *but, const char *str, } } +#else /* WITH_PYTHON */ + + value= atof(str); + ok = TRUE; + +#endif /* WITH_PYTHON */ + return ok; } -#endif // WITH_PYTHON int ui_set_but_string(bContext *C, uiBut *but, const char *str) { @@ -1788,13 +1799,9 @@ int ui_set_but_string(bContext *C, uiBut *but, const char *str) /* number editing */ double value; -#ifdef WITH_PYTHON if(ui_set_but_string_eval_num(C, but, str, &value) == FALSE) { return 0; } -#else - value= atof(str); -#endif // WITH_PYTHON if(!ui_is_but_float(but)) value= (int)floor(value + 0.5); if(but->type==NUMABS) value= fabs(value); diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 3a19bb2a90c..08847a602b9 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1115,8 +1115,7 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data, { static ColorBand but_copypaste_coba = {0}; char buf[UI_MAX_DRAW_STR+1]= {0}; - double val; - + if(mode=='v' && but->lock) return; @@ -1140,17 +1139,16 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data, if(but->poin==NULL && but->rnapoin.data==NULL); else if(mode=='c') { - if(ui_is_but_float(but)) - BLI_snprintf(buf, sizeof(buf), "%f", ui_get_but_val(but)); - else - BLI_snprintf(buf, sizeof(buf), "%d", (int)ui_get_but_val(but)); - + ui_get_but_string(but, buf, sizeof(buf)); WM_clipboard_text_set(buf, 0); } else { - if (sscanf(buf, " %lf ", &val) == 1) { + double val; + + if (ui_set_but_string_eval_num(C, but, buf, &val)) { button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); data->value= val; + ui_set_but_string(C, but, buf); button_activate_state(C, but, BUTTON_STATE_EXIT); } } diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 7d53e7acbc2..2980b28d522 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -356,6 +356,7 @@ extern void ui_get_but_string(uiBut *but, char *str, size_t maxlen); extern void ui_convert_to_unit_alt_name(uiBut *but, char *str, size_t maxlen); extern int ui_set_but_string(struct bContext *C, uiBut *but, const char *str); extern int ui_get_but_string_max_length(uiBut *but); +extern int ui_set_but_string_eval_num(struct bContext *C, uiBut *but, const char *str, double *value); extern void ui_set_but_default(struct bContext *C, short all); -- cgit v1.2.3