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.
This commit is contained in:
2012-01-20 22:32:47 +00:00
parent 3f1584c758
commit f08a8c5b15
3 changed files with 20 additions and 14 deletions

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -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);