TypeConverter.st
changeset 2623 cadc459b3c53
parent 2620 7bd45a3ea825
child 2737 0c83579be3d3
--- a/TypeConverter.st	Tue Mar 31 23:57:34 2009 +0200
+++ b/TypeConverter.st	Wed Apr 29 21:58:04 2009 +0200
@@ -712,6 +712,13 @@
         updateBlock: [:m :a :p | true]
 !
 
+integer
+    "setup the converter to convert from a string to an integer
+     and vice versa. Invalid integers are converted to nil."
+
+    self integerToText
+!
+
 integerToHexTextMinValue:minVal maxValue:maxVal format:formatStringOrNil
     "setup the converter to convert from a string to a number
      and vice versa, but clamping the number into the range."
@@ -719,6 +726,35 @@
     ^ self integerToTextMinValue:minVal maxValue:maxVal radix:16 format:formatStringOrNil
 !
 
+integerToText
+    "setup the converter to convert from a string to a integer
+     and vice versa."
+
+    self
+        getBlock:[:model |
+                |numericValue|
+
+                (numericValue := model value) isInteger ifFalse:[
+                    String new
+                ] ifTrue:[
+                    numericValue printString
+                ]]
+
+        putBlock:
+                [:model :string |
+
+                |value|
+
+                string isEmptyOrNil ifTrue:[
+                    value := 0
+                ] ifFalse:[
+                    value := Integer readFromString: string onError:[0]
+                ].
+                model value:value]
+
+        updateBlock: [:m :a :p | true]
+!
+
 integerToTextMinValue:minVal maxValue:maxVal format:formatStringOrNil
     "setup the converter to convert from a string to a number
      and vice versa, but clamping the number into the range."
@@ -1721,5 +1757,5 @@
 !TypeConverter class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.60 2009-03-26 13:59:44 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/TypeConverter.st,v 1.61 2009-04-29 19:58:04 cg Exp $'
 ! !