*** empty log message ***
authorClaus Gittinger <cg@exept.de>
Thu, 05 Nov 2009 15:46:11 +0100
changeset 5483 f9d6b4bb9e85
parent 5482 d81219e58155
child 5484 957c27765fae
*** empty log message ***
ResourcePack.st
--- a/ResourcePack.st	Thu Nov 05 15:37:53 2009 +0100
+++ b/ResourcePack.st	Thu Nov 05 15:46:11 2009 +0100
@@ -13,7 +13,7 @@
 
 Dictionary subclass:#ResourcePack
 	instanceVariableNames:'packsClassName fileReadFailed superPack projectPack'
-	classVariableNames:'Packs'
+	classVariableNames:'Packs DebugModifications'
 	poolDictionaries:''
 	category:'Interface-Internationalization'
 !
@@ -49,31 +49,31 @@
     where 'className' is built by the usual abbreviation mechanism (see abbrev-files).
 
     Conditional mappings are possible, by including lines as:
-	#if <expression>
-	#endif
+        #if <expression>
+        #endif
     in the resourcefile. Example:
     file 'foo.rs':
-	#if Language == #de
-	'abort' 'Abbruch'
-	#endif
-	#if Language == #fr
-	'abort' 'canceller'
-	#endif
+        #if Language == #de
+        'abort' 'Abbruch'
+        #endif
+        #if Language == #fr
+        'abort' 'canceller'
+        #endif
 
     the corresponding resource-strings are accessed (from methods within the class)
     using:
-	resources string:'abort'
+        resources string:'abort'
 
     returning the mapped string (i.e. 'Abbruch' if the global Language is set
     to #de)..
 
     If no corresponding entry is found in the resources, the key is returned;
     alternatively, use:
-	resources string:'foo' default:'bar'
+        resources string:'foo' default:'bar'
     which returns 'bar', if no resource definition for 'foo' is found.
 
     Translations can also include arguments, such as:
-	resources string:'really delete %1' with:fileName
+        resources string:'really delete %1' with:fileName
 
     This scheme has the advantage, that you can write your programs using your
     native language strings. Later, when new languages are to be supported,
@@ -97,32 +97,38 @@
     (which is better than nothing or empty button labels ;-)
 
     Summary:
-	in subclasses of View and ApplicationModel,
-	instead of writing:
+        in subclasses of View and ApplicationModel,
+        instead of writing:
 
-		...
-		b := Button label:'press me'
-		...
+                ...
+                b := Button label:'press me'
+                ...
 
-	always write:
+        always write:
 
-		...
-		b := Button label:(resources string:'press me')
-		...
+                ...
+                b := Button label:(resources string:'press me')
+                ...
 
-	if your class is not a subclass of one of the above, AND you need
-	resource translations, you wont inherit the resources variable
-	(which is automatically initialized).
-	In this case, you have to ask the ResourcePack class explicitely for
-	a corresponding package:
+        if your class is not a subclass of one of the above, AND you need
+        resource translations, you wont inherit the resources variable
+        (which is automatically initialized).
+        In this case, you have to ask the ResourcePack class explicitely for
+        a corresponding package:
+
+                ResourcePack for:aClassName
 
-		ResourcePack for:aClassName
+        as an example, see how the Date class gets the national names of
+        week & monthnames.
 
-	as an example, see how the Date class gets the national names of
-	week & monthnames.
-
+    Debugging:
+        in the past, it happened that strings as returned by me were modified by someone else
+        (replaceAll:with:) and then lead to invalid presentation in the future.
+        To detect any bad guy which writes into one of my returned strings, set the DebugModifications
+        classVar to true. Then I will return ImmutableStrings which trap on writes.
+    
     [author:]
-	Claus Gittinger
+        Claus Gittinger
 "
 !
 
@@ -616,10 +622,12 @@
                     value := aResourcePack string:value.
                 ].
 
-                "/ for debugging only !! (not all primitive code is ready for immutableStrings)
-                "/ value class == String ifTrue:[
-                "/     value := value copy changeClassTo:ImmutableString.
-                "/ ].
+                DebugModifications == true ifTrue:[
+                    "/ for debugging only !! (not all primitive code is ready for immutableStrings)
+                    value class == String ifTrue:[
+                        value := value asImmutableString.
+                    ].
+                ].
 
                 aResourcePack at:name put:value.
             ]
@@ -1320,11 +1328,11 @@
 !ResourcePack class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.141 2009-11-05 13:13:28 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.142 2009-11-05 14:46:11 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.141 2009-11-05 13:13:28 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.142 2009-11-05 14:46:11 cg Exp $'
 ! !
 
 ResourcePack initialize!