[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43574] trunk/blender/source/blender/ editors/interface: modify number button copy/ paste to work as if you enter the button, select text, type into another button the same value.

Campbell Barton ideasman42 at gmail.com
Fri Jan 20 23:33:02 CET 2012


Revision: 43574
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43574
Author:   campbellbarton
Date:     2012-01-20 22:32:47 +0000 (Fri, 20 Jan 2012)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface.c
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/editors/interface/interface_intern.h

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2012-01-20 22:09:30 UTC (rev 43573)
+++ trunk/blender/source/blender/editors/interface/interface.c	2012-01-20 22:32:47 UTC (rev 43574)
@@ -1693,10 +1693,15 @@
 	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 @@
 		}
 	}
 
+#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 @@
 		/* 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);

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2012-01-20 22:09:30 UTC (rev 43573)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2012-01-20 22:32:47 UTC (rev 43574)
@@ -1115,8 +1115,7 @@
 {
 	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 @@
 		
 		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);
 			}
 		}

Modified: trunk/blender/source/blender/editors/interface/interface_intern.h
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_intern.h	2012-01-20 22:09:30 UTC (rev 43573)
+++ trunk/blender/source/blender/editors/interface/interface_intern.h	2012-01-20 22:32:47 UTC (rev 43574)
@@ -356,6 +356,7 @@
 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);
 



More information about the Bf-blender-cvs mailing list