author | Claus Gittinger <cg@exept.de> |
Fri, 04 Sep 2015 11:34:43 +0200 | |
changeset 6909 | e3e7a1e51bc7 |
parent 6887 | b10262d21ed1 |
child 6919 | 61df9e689fca |
permissions | -rw-r--r-- |
5 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
72 | 3 |
All Rights Reserved |
5 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
3263 | 12 |
"{ Package: 'stx:libview' }" |
13 |
||
6767 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
0 | 16 |
Dictionary subclass:#ResourcePack |
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
17 |
instanceVariableNames:'packsClassName packsFileName fileReadFailed superPack projectPack' |
5826
c4ed474970c1
forPackage:resourceFileName:cached:
Claus Gittinger <cg@exept.de>
parents:
5781
diff
changeset
|
18 |
classVariableNames:'Packs FailedToLoadPacks DebugModifications' |
308
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
19 |
poolDictionaries:'' |
3484 | 20 |
category:'Interface-Internationalization' |
0 | 21 |
! |
22 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
23 |
!ResourcePack class methodsFor:'documentation'! |
46 | 24 |
|
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
72 | 28 |
All Rights Reserved |
5 | 29 |
|
46 | 30 |
This software is furnished under a license and may be used |
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
5 | 38 |
|
46 | 39 |
documentation |
40 |
" |
|
1942 | 41 |
This class supports easy customization of smalltalk code (i.e. internationalization |
42 |
and viewStyle adaption). |
|
145 | 43 |
ResourcePacks are class specific, meaning that every subclass of View |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
44 |
and ApplicationModel has an instance of ResourcePack (instVar called 'resources') |
1942 | 45 |
which is created when the first instance of the view/app is created, |
46 |
and cached in a class-instVar (so the file is only read once). |
|
54 | 47 |
|
50 | 48 |
The resourcePack consists of a mapping from strings to values, which are |
49 |
then used in labels, buttons, menus etc. |
|
50 |
The resourcePack initializes itself from a file found in 'resources/<className>.rs', |
|
51 |
where 'className' is built by the usual abbreviation mechanism (see abbrev-files). |
|
1942 | 52 |
|
50 | 53 |
Conditional mappings are possible, by including lines as: |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
54 |
#if <expression> |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
55 |
#endif |
50 | 56 |
in the resourcefile. Example: |
57 |
file 'foo.rs': |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
58 |
#if Language == #de |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
59 |
'abort' 'Abbruch' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
60 |
#endif |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
61 |
#if Language == #fr |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
62 |
'abort' 'canceller' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
63 |
#endif |
145 | 64 |
|
65 |
the corresponding resource-strings are accessed (from methods within the class) |
|
66 |
using: |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
67 |
resources string:'abort' |
145 | 68 |
|
54 | 69 |
returning the mapped string (i.e. 'Abbruch' if the global Language is set |
3422 | 70 |
to #de).. |
145 | 71 |
|
1942 | 72 |
If no corresponding entry is found in the resources, the key is returned; |
73 |
alternatively, use: |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
74 |
resources string:'foo' default:'bar' |
1942 | 75 |
which returns 'bar', if no resource definition for 'foo' is found. |
76 |
||
54 | 77 |
Translations can also include arguments, such as: |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
78 |
resources string:'really delete %1' with:fileName |
145 | 79 |
|
80 |
This scheme has the advantage, that you can write your programs using your |
|
81 |
native language strings. Later, when new languages are to be supported, |
|
82 |
simply create a resource file for the class and add translations for |
|
83 |
all those strings. (find the keys by looking at users of resource or senders |
|
1942 | 84 |
of 'string:*'). |
85 |
Notice, that the grammar of different languages may imply a reordering, |
|
6909 | 86 |
so the above string becomes the german 'wollen Sie %1 wirklich löschen'; |
1942 | 87 |
so using percent-placeholders is much better than simple concatenations of |
88 |
arguments to the question. |
|
145 | 89 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
90 |
More languages can be added later without any change in the code, or recompilation |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
91 |
or the like. Even by people without access to the source code (i.e. which only have the |
5653 | 92 |
applications binary). |
145 | 93 |
|
94 |
Also, unsupported languages' strings are simply left unchanged - if you |
|
95 |
write your application in (say) english, and only plan to use it in english, |
|
5653 | 96 |
no additional work is required (i.e you don't even need a resource file then). |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
97 |
Strings for unknown languages will come in english |
145 | 98 |
(which is better than nothing or empty button labels ;-) |
99 |
||
5653 | 100 |
Notice, that you can also translate engish to english, by providing an en.rs file. |
101 |
This is sometimes useful to fix typing errors or bad syntax in the english, |
|
102 |
as sometimes made by the programmer, without a need to recompile or to also adjust other |
|
103 |
language translations. |
|
104 |
||
105 |
Finally, this scheme is also compatible to a pure enum-key based translation mechanism, |
|
106 |
as typically used in the C-world. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
107 |
Simple use keys as argument, and provide translations for all languages (incl. english). |
5653 | 108 |
For example: |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
109 |
Button label:(resources string:#BTN_FOO_LABEL) |
5653 | 110 |
|
111 |
||
145 | 112 |
Summary: |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
113 |
in subclasses of View and ApplicationModel, instead of writing: |
145 | 114 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
115 |
... |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
116 |
b := Button label:'press me' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
117 |
... |
145 | 118 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
119 |
always write: |
612 | 120 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
121 |
... |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
122 |
b := Button label:(resources string:'press me') |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
123 |
... |
145 | 124 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
125 |
if your class is not a subclass of one of the above, AND you need |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
126 |
resource translations, you won't inherit the resources variable |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
127 |
(which is automatically initialized). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
128 |
In this case, you have to ask the ResourcePack class explicitely for |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
129 |
a corresponding package: |
5483 | 130 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
131 |
ResourcePack for:aClassName |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
132 |
or (even better): |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
133 |
ResourcePack forPackage:aPackageID |
145 | 134 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
135 |
as an example, see how the Date class gets the national names of |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
136 |
week & monthnames. |
145 | 137 |
|
5483 | 138 |
Debugging: |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
139 |
in the past, it happened that strings as returned by me were modified by someone else |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
140 |
(replaceAll:with:) and then lead to invalid presentation in the future. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
141 |
To detect any bad guy which writes into one of my returned strings, set the DebugModifications |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
142 |
classVar to true. Then I will return ImmutableStrings which trap on writes. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
143 |
|
612 | 144 |
[author:] |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
145 |
Claus Gittinger |
145 | 146 |
" |
147 |
! |
|
148 |
||
149 |
examples |
|
150 |
" |
|
151 |
normally, resources are found in files named after their classes sourcefile |
|
152 |
For example, the FileBrowsers resources are found in 'FBrowser.rs'. |
|
153 |
For the examples below, we process resources from a constant string; |
|
3762 | 154 |
this is NOT representative. |
155 |
[exBegin] |
|
156 |
|stream res| |
|
145 | 157 |
|
3762 | 158 |
stream := ReadStream on:' |
145 | 159 |
foo ''the translation for foo'' |
3422 | 160 |
#if Language == #de |
145 | 161 |
bar ''die deutsche uebersetzung von bar'' |
162 |
baz ''baz hat den Wert %1'' |
|
163 |
#endif |
|
3422 | 164 |
#if Language == #fr |
145 | 165 |
bar ''bar en francaise'' |
166 |
baz ''%1, c''''est baz'' |
|
167 |
#endif |
|
168 |
||
169 |
'. |
|
170 |
||
3762 | 171 |
res := ResourcePack new readFromResourceStream:stream in:nil. |
145 | 172 |
|
3762 | 173 |
Transcript showCR:'baz is translated to: ' , (res string:'baz' with:'1234'). |
174 |
Transcript showCR:'bar is translated to: ' , (res string:'bar'). |
|
175 |
Transcript showCR:'foo is translated to: ' , (res string:'foo'). |
|
176 |
Transcript showCR:'fooBar is translated to: ' , (res string:'fooBar'). |
|
177 |
[exEnd] |
|
145 | 178 |
set the Language to french: |
3762 | 179 |
[exBegin] |
180 |
Language := #fr |
|
181 |
[exEnd] |
|
145 | 182 |
and repeat the above. |
620 | 183 |
back to english: |
3762 | 184 |
[exBegin] |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
185 |
Language := #en |
3762 | 186 |
[exEnd] |
620 | 187 |
back to german: |
3762 | 188 |
[exBegin] |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
189 |
Language := #de |
3762 | 190 |
[exEnd] |
46 | 191 |
" |
192 |
! ! |
|
5 | 193 |
|
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
194 |
!ResourcePack class methodsFor:'initialization'! |
0 | 195 |
|
72 | 196 |
flushCachedResourcePacks |
24 | 197 |
"forget all cached resources - needed after a style change" |
198 |
||
199 |
Packs := nil. |
|
200 |
self initialize |
|
201 |
||
4093 | 202 |
" |
203 |
ResourcePack flushCachedResourcePacks |
|
204 |
" |
|
244 | 205 |
! |
206 |
||
207 |
initialize |
|
208 |
Packs isNil ifTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
209 |
Packs := WeakArray new:100. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
210 |
FailedToLoadPacks := Set new. |
244 | 211 |
]. |
212 |
||
4093 | 213 |
" |
214 |
ResourcePack initialize |
|
215 |
" |
|
4623 | 216 |
|
5826
c4ed474970c1
forPackage:resourceFileName:cached:
Claus Gittinger <cg@exept.de>
parents:
5781
diff
changeset
|
217 |
"Modified: / 28-09-2011 / 15:53:21 / cg" |
244 | 218 |
! ! |
219 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
220 |
!ResourcePack class methodsFor:'instance creation'! |
244 | 221 |
|
222 |
for:aClass |
|
223 |
"get the full resource definitions for aClass (i.e. with super packs). |
|
224 |
Also leave the resulting pack in the cache for faster access next time." |
|
225 |
||
4619 | 226 |
^ self for:aClass cached:false |
4030 | 227 |
|
228 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
229 |
ResourcePack for:TextView |
4030 | 230 |
ResourcePack for:CodeView |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
231 |
ResourcePack for:Workspace |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
232 |
ResourcePack for:View |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
233 |
ResourcePack for:ErrorLogger |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
234 |
ResourcePack for:NewLauncher |
6799 | 235 |
ResourcePack for:SmallSense::SettingsAppl |
4030 | 236 |
Workspace classResources |
237 |
" |
|
4619 | 238 |
|
239 |
"Modified: / 18-09-2006 / 19:02:57 / cg" |
|
4030 | 240 |
! |
241 |
||
242 |
for:aClass cached:cached |
|
243 |
"get the full resource definitions for aClass (i.e. with super packs). |
|
244 |
Also leave the resulting pack in the cache for faster access next time." |
|
245 |
||
3980
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
246 |
|nm pack rsrcDir baseName| |
244 | 247 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
248 |
nm := aClass resourcePackName. |
4030 | 249 |
cached ifTrue:[ |
6909 | 250 |
pack := self searchCacheFor:nm. |
251 |
pack notNil ifTrue:[^ pack]. |
|
4030 | 252 |
]. |
244 | 253 |
|
3049
d5f2b3f66e37
load resources from package directory, if present
Claus Gittinger <cg@exept.de>
parents:
3047
diff
changeset
|
254 |
baseName := (Smalltalk fileNameForClass:nm) , '.rs'. |
3980
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
255 |
rsrcDir := aClass resourceDirectory. |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
256 |
|
4148 | 257 |
"/ CHECK this |
258 |
"/ (rsrcDir notNil and:[rsrcDir suffix = 'rs']) ifTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
259 |
"/ baseName := (Smalltalk fileNameForClass: rsrcDir tail asFilename withoutSuffix pathName),'.rs'. |
4148 | 260 |
"/ rsrcDir := rsrcDir head asFilename. |
261 |
"/ ]. |
|
262 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
263 |
rsrcDir notNil ifTrue:[ |
6909 | 264 |
pack := self new. |
265 |
rsrcDir exists ifTrue:[ |
|
266 |
(rsrcDir construct:baseName) exists ifTrue:[ |
|
267 |
pack := self fromFile:baseName directory:(rsrcDir name) cached:cached. |
|
268 |
]. |
|
269 |
] |
|
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
270 |
] ifFalse:[ |
6909 | 271 |
pack := self fromFile:baseName directory:'resources' cached:cached. |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
272 |
]. |
4619 | 273 |
aClass superclass notNil ifTrue:[ |
6909 | 274 |
pack superPack:(self for:(aClass superclass)). |
244 | 275 |
]. |
4093 | 276 |
pack packsClassOrFileName:nm. |
4030 | 277 |
cached ifTrue:[ |
6909 | 278 |
self addToCache:pack. |
4030 | 279 |
]. |
6909 | 280 |
pack projectPack:(self forPackage:(aClass resourcePackage) cached:cached). |
244 | 281 |
^ pack |
282 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
283 |
" |
4656 | 284 |
ResourcePack forPackage:'bosch:dapasx' cached:true |
285 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
286 |
ResourcePack for:TextView |
244 | 287 |
ResourcePack for:CodeView |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
288 |
ResourcePack for:Workspace |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
289 |
ResourcePack for:View |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
290 |
ResourcePack for:ErrorLogger |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
291 |
ResourcePack for:NewLauncher |
244 | 292 |
Workspace classResources |
293 |
" |
|
4617 | 294 |
|
5642
494cea2296dc
comment/format in: #for:cached:
Claus Gittinger <cg@exept.de>
parents:
5603
diff
changeset
|
295 |
"Modified: / 01-11-2010 / 09:09:43 / cg" |
244 | 296 |
! |
297 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
298 |
forPackage:package |
4078 | 299 |
"get the full resource definitions given a package id (such as stx:libbasic'). |
300 |
Also leave the resulting pack in the cache for faster access next time." |
|
301 |
||
302 |
^ self forPackage:package cached:true |
|
303 |
||
304 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
305 |
ResourcePack forPackage:'stx:libbasic' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
306 |
ResourcePack forPackage:'stx:libtool' |
4078 | 307 |
" |
4618 | 308 |
|
309 |
"Modified: / 18-09-2006 / 18:45:31 / cg" |
|
4078 | 310 |
! |
311 |
||
312 |
forPackage:package cached:cached |
|
313 |
"get the full resource definitions given a package id (such as stx:libbasic'). |
|
314 |
Also optionally leave the resulting pack in the cache for faster access next time." |
|
315 |
||
4673 | 316 |
^ self forPackage:package resourceFileName:'resources.rs' cached:cached |
317 |
||
318 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
319 |
ResourcePack forPackage:'stx:libbasic' cached:false |
4673 | 320 |
" |
321 |
||
322 |
"Modified: / 19-10-2006 / 23:18:28 / cg" |
|
323 |
! |
|
324 |
||
325 |
forPackage:package resourceFileName:resourceFileName cached:cached |
|
326 |
"get the full resource definitions given a package id (such as stx:libbasic'). |
|
5826
c4ed474970c1
forPackage:resourceFileName:cached:
Claus Gittinger <cg@exept.de>
parents:
5781
diff
changeset
|
327 |
Also optionally leave the resulting pack in the cache for faster access next time. |
c4ed474970c1
forPackage:resourceFileName:cached:
Claus Gittinger <cg@exept.de>
parents:
5781
diff
changeset
|
328 |
Remember failed packs, to avoid retrying reading the file again and again" |
4673 | 329 |
|
4428 | 330 |
|fullName pack rsrcDir file| |
4078 | 331 |
|
4673 | 332 |
fullName := package , '/resources/',resourceFileName. |
4078 | 333 |
|
334 |
cached ifTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
335 |
pack := self searchCacheFor:fullName. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
336 |
pack notNil ifTrue:[^ pack]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
337 |
(FailedToLoadPacks includes:fullName) ifTrue:[^ nil]. |
4078 | 338 |
]. |
339 |
||
340 |
rsrcDir := Smalltalk projectDirectoryForPackage:package. |
|
4428 | 341 |
rsrcDir isNil ifTrue:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
342 |
file := Smalltalk getResourceFileName:resourceFileName forPackage:package. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
343 |
file isNil ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
344 |
FailedToLoadPacks add:fullName. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
345 |
^ nil |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
346 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
347 |
rsrcDir := file asFilename directory. |
4428 | 348 |
] ifFalse:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
349 |
rsrcDir := rsrcDir asFilename construct:'resources'. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
350 |
rsrcDir exists ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
351 |
FailedToLoadPacks add:fullName. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
352 |
^ nil |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
353 |
]. |
4428 | 354 |
]. |
4078 | 355 |
|
4673 | 356 |
pack := self fromFile:resourceFileName directory:rsrcDir cached:cached. |
4093 | 357 |
pack packsClassOrFileName:fullName. |
4078 | 358 |
^ pack |
359 |
||
360 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
361 |
ResourcePack forPackage:'stx:libbasic' resourceFileName:'resources.rs' cached:false |
4078 | 362 |
" |
4656 | 363 |
|
5826
c4ed474970c1
forPackage:resourceFileName:cached:
Claus Gittinger <cg@exept.de>
parents:
5781
diff
changeset
|
364 |
"Modified: / 28-09-2011 / 15:55:30 / cg" |
4078 | 365 |
! |
366 |
||
244 | 367 |
fromFile:aFileName |
4611 | 368 |
"get the resource definitions from a file in the default directory." |
244 | 369 |
|
370 |
^ self fromFile:aFileName directory:'resources' |
|
371 |
||
372 |
" |
|
373 |
ResourcePack fromFile:'SBrowser.rs' |
|
374 |
ResourcePack fromFile:'FBrowser.rs' |
|
375 |
ResourcePack fromFile:'Smalltalk.rs' |
|
3678 | 376 |
ResourcePack fromFile:'Smalltalk.rs' asFilename |
3983 | 377 |
ResourcePack fromFile:'../../libtool/resources/AboutBox_ru.rs' asFilename |
244 | 378 |
" |
379 |
! |
|
380 |
||
381 |
fromFile:aFileName directory:dirName |
|
4611 | 382 |
"get the resource definitions from a file in a directory." |
383 |
||
384 |
^ self fromFile:aFileName directory:dirName cached:false |
|
385 |
! |
|
386 |
||
387 |
fromFile:aFileName directory:dirName cached:cached |
|
244 | 388 |
"get the resource definitions from a file in a directory. |
389 |
Uncached low-level entry." |
|
390 |
||
391 |
|newPack| |
|
392 |
||
393 |
newPack := self new. |
|
394 |
newPack readFromFile:aFileName directory:dirName. |
|
4611 | 395 |
cached ifTrue:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
396 |
self addToCache:newPack. |
4611 | 397 |
]. |
244 | 398 |
^ newPack |
0 | 399 |
! ! |
400 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
401 |
!ResourcePack class methodsFor:'private'! |
54 | 402 |
|
403 |
addToCache:aPack |
|
404 |
|idx| |
|
0 | 405 |
|
4084 | 406 |
Packs isNil ifTrue:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
407 |
self initialize. |
4084 | 408 |
]. |
409 |
||
54 | 410 |
idx := Packs identityIndexOf:nil. |
411 |
idx == 0 ifTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
412 |
idx := Packs findFirst:[:slot | slot class == SmallInteger]. |
1078
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
413 |
]. |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
414 |
idx == 0 ifTrue:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
415 |
" |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
416 |
throw away oldest |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
417 |
" |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
418 |
idx := Packs size. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
419 |
Packs replaceFrom:1 to:idx-1 with:Packs startingAt:2. |
54 | 420 |
]. |
5357 | 421 |
aPack at:'__language__' put:(UserPreferences current language,'_',UserPreferences current languageTerritory). |
4619 | 422 |
Packs at:idx put:aPack. |
423 |
||
424 |
"Modified: / 18-09-2006 / 19:12:12 / cg" |
|
54 | 425 |
! |
0 | 426 |
|
4093 | 427 |
searchCacheFor:aClassOrFileName |
4619 | 428 |
|sz "{ Class: SmallInteger }" lang| |
0 | 429 |
|
24 | 430 |
Packs isNil ifTrue:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
431 |
self initialize. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
432 |
^ nil |
0 | 433 |
]. |
54 | 434 |
|
5357 | 435 |
lang := (UserPreferences current language,'_',UserPreferences current languageTerritory). |
4619 | 436 |
|
54 | 437 |
sz := Packs size. |
438 |
1 to:sz do:[:idx | |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
439 |
|aPack| |
54 | 440 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
441 |
aPack := Packs at:idx. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
442 |
(aPack notNil and:[aPack class ~~ SmallInteger]) ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
443 |
(aPack at:'__language__' ifAbsent:nil) = lang ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
444 |
aClassOrFileName = aPack packsClassOrFileName ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
445 |
" |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
446 |
bring to front for LRU |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
447 |
" |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
448 |
idx ~~ 1 ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
449 |
Packs replaceFrom:2 to:idx with:Packs startingAt:1. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
450 |
Packs at:1 put:aPack. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
451 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
452 |
^ aPack |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
453 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
454 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
455 |
] |
0 | 456 |
]. |
54 | 457 |
^ nil |
123 | 458 |
|
459 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
460 |
ResourcePack searchCacheFor:'TextView' |
123 | 461 |
" |
4619 | 462 |
|
463 |
"Modified: / 18-09-2006 / 19:13:13 / cg" |
|
54 | 464 |
! ! |
465 |
||
4509 | 466 |
!ResourcePack class methodsFor:'utilities'! |
467 |
||
468 |
extractEncodingFromLine:lineString |
|
469 |
|rest encoding| |
|
470 |
||
471 |
(lineString startsWith:'encoding') ifFalse:[^ nil]. |
|
472 |
||
473 |
rest := lineString copyFrom:9. |
|
474 |
rest := rest withoutSeparators. |
|
475 |
(rest startsWith:'#') ifTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
476 |
rest := rest copyFrom:2. |
4509 | 477 |
]. |
478 |
(rest startsWith:'''') ifTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
479 |
rest := rest copyFrom:2. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
480 |
(rest endsWith:'''') ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
481 |
rest := rest copyButLast:1. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
482 |
]. |
4509 | 483 |
]. |
484 |
encoding := rest asSymbol. |
|
485 |
^ encoding. |
|
486 |
! |
|
487 |
||
488 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack |
|
489 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
|
490 |
||
4510 | 491 |
self |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
492 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
493 |
keepUselessTranslations:false. |
4510 | 494 |
! |
495 |
||
496 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack keepUselessTranslations:keepUselessTranslations |
|
497 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
|
498 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
499 |
|name lineStream idx rest macroName value |
4670 | 500 |
conditional hasError decoder oldValue ignoreTranslation indirect| |
4509 | 501 |
|
6250 | 502 |
"/ Transcript showCR:lineString. |
4531 | 503 |
encodingSymbolOrEncoder notNil ifTrue:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
504 |
encodingSymbolOrEncoder isSymbol ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
505 |
decoder := CharacterEncoder encoderFor:encodingSymbolOrEncoder ifAbsent:nil. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
506 |
decoder isNil ifTrue:[ decoder := CharacterEncoder nullEncoderInstance ]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
507 |
] ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
508 |
decoder := encodingSymbolOrEncoder |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
509 |
]. |
4531 | 510 |
]. |
511 |
||
512 |
decoder notNil ifTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
513 |
lineStream := (decoder decodeString:lineString) readStream. |
4531 | 514 |
] ifFalse:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
515 |
lineStream := lineString readStream. |
4531 | 516 |
]. |
4509 | 517 |
lineStream signalAtEnd:false. |
518 |
lineStream skipSeparators. |
|
5080 | 519 |
|
4509 | 520 |
lineStream peek == $# ifTrue:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
521 |
name := Array |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
522 |
readFrom:lineStream |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
523 |
onError:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
524 |
printError value:('invalid line <' , lineString , '>'). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
525 |
nil |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
526 |
]. |
4509 | 527 |
] ifFalse:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
528 |
lineStream peek == $' ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
529 |
name := String |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
530 |
readSmalltalkStringFrom:lineStream |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
531 |
onError:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
532 |
printError value:('invalid line <' , lineString , '>'). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
533 |
nil |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
534 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
535 |
] ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
536 |
name := lineStream upToSeparator. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
537 |
]. |
4509 | 538 |
]. |
539 |
||
4510 | 540 |
name isNil ifTrue:[^ self ]. |
541 |
||
542 |
ignoreTranslation := false. |
|
543 |
hasError := false. |
|
4509 | 544 |
|
4510 | 545 |
lineStream skipSeparators. |
6113 | 546 |
idx := lineStream position + 1 + 1. |
4510 | 547 |
|
548 |
lineStream peek == $< ifTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
549 |
" |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
550 |
skip <type> if present |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
551 |
" |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
552 |
lineStream skipThrough:$>. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
553 |
lineStream skipSeparators. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
554 |
idx := lineStream position + 2. |
4510 | 555 |
]. |
4509 | 556 |
|
4670 | 557 |
conditional := indirect := false. |
4510 | 558 |
lineStream peek == $? ifTrue:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
559 |
conditional := true. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
560 |
lineStream next. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
561 |
lineStream skipSeparators. |
4670 | 562 |
]. |
563 |
||
564 |
lineStream peek == $@ ifTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
565 |
indirect := true. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
566 |
lineStream next. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
567 |
lineStream skipSeparators. |
4510 | 568 |
]. |
4509 | 569 |
|
4510 | 570 |
lineStream peek == $= ifTrue:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
571 |
lineStream next. |
4510 | 572 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
573 |
macroName := lineStream nextAlphaNumericWord. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
574 |
[lineStream peek == $.] whileTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
575 |
lineStream next. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
576 |
lineStream peek notNil ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
577 |
macroName := macroName , '.' , (lineStream nextAlphaNumericWord) |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
578 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
579 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
580 |
rest := lineStream upToEnd. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
581 |
value := aResourcePack at:macroName ifAbsent:nil. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
582 |
(value isNil) ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
583 |
hasError := true. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
584 |
printError value:('bad (nil-valued) macro: ' , macroName). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
585 |
]. |
4678
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
586 |
"/ value isBlock ifTrue:[ |
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
587 |
"/ value := value value |
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
588 |
"/ ]. |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
589 |
rest isBlank ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
590 |
value := Compiler evaluate:('self ' , rest) |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
591 |
receiver:value |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
592 |
notifying:nil |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
593 |
compile:false. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
594 |
(value == #Error) ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
595 |
hasError := true. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
596 |
printError value:('error in: "self ' , rest , '"'). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
597 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
598 |
"/ 'self ' print. rest print. ' -> ' print. value printCR. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
599 |
] |
4510 | 600 |
] ifFalse:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
601 |
lineStream peek == $' ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
602 |
value := String |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
603 |
readSmalltalkStringFrom:lineStream |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
604 |
onError:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
605 |
printError value:('invalid line <' , lineString , '>'). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
606 |
nil |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
607 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
608 |
"/ ' -> ' print. value printCR. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
609 |
] ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
610 |
rest := lineStream upToEnd. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
611 |
[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
612 |
value := Compiler evaluate:rest compile:"true" false. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
613 |
] on:Error do:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
614 |
printError value:('invalid line <' , rest , '>'). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
615 |
"/ value := rest |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
616 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
617 |
"/ rest print. ' -> ' print. value printCR. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
618 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
619 |
(value == #Error) ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
620 |
hasError := true. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
621 |
printError value:('error in: "' , rest , '"'). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
622 |
] ifFalse:[ |
4531 | 623 |
"/ value isString ifTrue:[ |
624 |
"/ decoder notNil ifTrue:[ |
|
625 |
"/ value := decoder decodeString:value |
|
626 |
"/ ] |
|
627 |
"/ ] |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
628 |
] |
4510 | 629 |
]. |
630 |
||
5430
128e9b37fd8a
comment/format in: #processResourceLine:encoding:file:printErrorWith:for:
sr
parents:
5370
diff
changeset
|
631 |
"/ Transcript show:name; show:' -> '; showCR:value. |
128e9b37fd8a
comment/format in: #processResourceLine:encoding:file:printErrorWith:for:
sr
parents:
5370
diff
changeset
|
632 |
|
4510 | 633 |
hasError ifFalse:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
634 |
(conditional not |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
635 |
or:[(aResourcePack includesKey:name) not]) ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
636 |
name = value ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
637 |
keepUselessTranslations ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
638 |
printError value:('useless resource: "' , name , '"'). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
639 |
ignoreTranslation := true |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
640 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
641 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
642 |
ignoreTranslation ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
643 |
oldValue := aResourcePack at:name ifAbsent:nil. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
644 |
oldValue notNil ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
645 |
oldValue ~= value ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
646 |
printError value:('conflicting resource: "' , name , '"'). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
647 |
printError value:('oldValue: ' , oldValue printString). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
648 |
printError value:('newValue: ' , value printString). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
649 |
] ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
650 |
printError value:('duplicate resource: "' , name , '"'). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
651 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
652 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
653 |
indirect ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
654 |
value := aResourcePack string:value. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
655 |
]. |
5431 | 656 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
657 |
DebugModifications == true ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
658 |
"/ for debugging only !! (not all primitive code is ready for immutableStrings) |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
659 |
value class == String ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
660 |
value := value asImmutableString. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
661 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
662 |
]. |
5431 | 663 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
664 |
aResourcePack at:name put:value. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
665 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
666 |
] |
4509 | 667 |
] |
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
668 |
|
6250 | 669 |
"Modified: / 06-02-2014 / 15:33:03 / cg" |
6661 | 670 |
! |
671 |
||
672 |
resourceFileEntryFor:keyString to:nationalString |
|
673 |
"generate a line for a translation file, which defines a translation |
|
674 |
from keyString to nationalString. |
|
675 |
Naivly, this could be a simple line containing the two storeStrings |
|
676 |
separated by a space. However, it is better to first cut of any leading |
|
677 |
and trailing spaces and special characters, such as ':*.,' etc." |
|
678 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
679 |
^ (self resourceFileStringFor:keyString),' ',(self resourceFileStringFor:nationalString) |
6661 | 680 |
! |
681 |
||
682 |
resourceFileStringFor:aString |
|
683 |
"generate a key or value entry for a translation file, for aString. |
|
684 |
Naivly, this could be a simple the storeString. |
|
685 |
However, it is better to first cut of any leading |
|
686 |
and trailing spaces and special characters, sch as ':*.,' etc." |
|
687 |
||
688 |
^ (self shortenedKeyFor:aString) storeString |
|
689 |
||
690 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
691 |
self resourceFileStringFor:' foo: ' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
692 |
self resourceFileStringFor:' foo bar: ' |
6661 | 693 |
" |
694 |
! |
|
695 |
||
696 |
shortenedKeyFor:aKey |
|
697 |
"if |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
698 |
aKey is '(...)', then return '...' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
699 |
if aKey is '[...]', then return '...' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
700 |
if aKey is '{...}', then return '...' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
701 |
if aKey starts or ends with any of '\:=.,?!! ', then return aKey without it |
6661 | 702 |
|
703 |
This means, that only a single translation is required to provide local translations for |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
704 |
things like |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
705 |
'search' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
706 |
'search:' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
707 |
'search...' |
6661 | 708 |
" |
709 |
||
710 |
|idx idx1 idx2 first last keySize| |
|
711 |
||
712 |
first := aKey first. |
|
713 |
last := aKey last. |
|
714 |
keySize := aKey size. |
|
715 |
||
716 |
((first == $( and:[last == $) ]) |
|
717 |
or:[ (first == $[ and:[last == $] ]) |
|
718 |
or:[ (first == ${ and:[last == $} ]) ]]) ifTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
719 |
^ self shortenedKeyFor:(aKey copyFrom:2 to:keySize-1). |
6661 | 720 |
]. |
721 |
||
722 |
idx1 := aKey findFirst:[:ch | ch isSeparator not]. |
|
723 |
idx2 := aKey findLast:[:ch | ch isSeparator not] ifNone:keySize. |
|
724 |
(idx1 > 1 or:[idx2 < keySize]) ifTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
725 |
^ self shortenedKeyFor:(aKey copyFrom:idx1 to:idx2) |
6661 | 726 |
]. |
727 |
||
728 |
idx1 := aKey findFirst:[:ch | ('*:=.?!!,-><\' includes:ch) not]. |
|
729 |
idx2 := aKey findLast:[:ch | ('*:=.?!!,-><\' includes:ch) not] ifNone:keySize. |
|
730 |
(idx1 > 1 or:[idx2 < keySize]) ifTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
731 |
^ self shortenedKeyFor:(aKey copyFrom:idx1 to:idx2) |
6661 | 732 |
]. |
733 |
||
734 |
"/ change duplicated &'s to single |
|
735 |
(idx := aKey indexOf:$&) ~~ 0 ifTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
736 |
(aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
737 |
^ self shortenedKeyFor:(aKey copyTo:idx-1),(aKey copyFrom:idx+1). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
738 |
]. |
6661 | 739 |
]. |
740 |
^ aKey. |
|
741 |
||
742 |
" |
|
743 |
'abcde' findFirst:[:ch | 'bcd' includes:ch] |
|
744 |
'abcde' indexOfAny:'bcd' |
|
745 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
746 |
self shortenedKeyFor:'abc' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
747 |
self shortenedKeyFor:' abc ' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
748 |
self shortenedKeyFor:'(abc)' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
749 |
self shortenedKeyFor:'abc...' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
750 |
self shortenedKeyFor:'(abc...)' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
751 |
self shortenedKeyFor:'abc:*' |
6661 | 752 |
" |
4509 | 753 |
! ! |
754 |
||
0 | 755 |
!ResourcePack methodsFor:'accessing'! |
756 |
||
244 | 757 |
array:anArray |
758 |
"translate a collection of strings" |
|
0 | 759 |
|
244 | 760 |
^ anArray collect:[:r | self at:r default:r] |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
761 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
762 |
" |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
763 |
Launcher classResources array:#('file' 'classes') |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
764 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
765 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
766 |
"Modified: / 29.1.1998 / 22:44:22 / cg" |
0 | 767 |
! |
768 |
||
2 | 769 |
at:aKey |
123 | 770 |
"translate a string" |
771 |
||
72 | 772 |
^ self at:aKey ifAbsent:aKey |
0 | 773 |
! |
774 |
||
775 |
at:aKey default:default |
|
123 | 776 |
"translate a string" |
777 |
||
72 | 778 |
^ self at:aKey ifAbsent:default |
0 | 779 |
! |
780 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
781 |
at:aKey ifAbsent:defaultValue |
4617 | 782 |
"translate a string; search here, in my projects pack and in my superpack(s)" |
783 |
||
784 |
|val pack projectPack alreadySearched| |
|
785 |
||
786 |
aKey isNil ifTrue:[ ^ defaultValue value ]. |
|
787 |
||
788 |
val := self localAt:aKey. |
|
789 |
val notNil ifTrue:[^ val]. |
|
790 |
||
791 |
(projectPack := self projectPack) notNil ifTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
792 |
val := projectPack localAt:aKey. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
793 |
val notNil ifTrue:[^ val]. |
4617 | 794 |
]. |
795 |
alreadySearched := Set new. |
|
796 |
projectPack notNil ifTrue:[ alreadySearched add:projectPack ]. |
|
797 |
||
798 |
pack := self superPack. |
|
799 |
[ pack notNil ] whileTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
800 |
val := pack localAt:aKey. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
801 |
val notNil ifTrue:[^ val]. |
4617 | 802 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
803 |
(projectPack := pack projectPack) notNil ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
804 |
(alreadySearched includes:projectPack) ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
805 |
val := projectPack localAt:aKey. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
806 |
val notNil ifTrue:[^ val]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
807 |
alreadySearched add:projectPack. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
808 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
809 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
810 |
pack := pack superPack |
4617 | 811 |
]. |
812 |
||
4618 | 813 |
alreadySearched copy do:[:projectPack | |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
814 |
|p| |
4618 | 815 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
816 |
p := projectPack superPack. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
817 |
[p notNil and:[(alreadySearched includes:p) not]] whileTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
818 |
val := p localAt:aKey. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
819 |
val notNil ifTrue:[^ val]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
820 |
alreadySearched add:p. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
821 |
p := p superPack. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
822 |
]. |
4618 | 823 |
]. |
824 |
||
4617 | 825 |
^ defaultValue value |
826 |
||
4618 | 827 |
"Modified: / 18-09-2006 / 18:50:52 / cg" |
4617 | 828 |
! |
829 |
||
830 |
localAt:aKey |
|
4035 | 831 |
"translate a string. |
832 |
Some special 'intelligence' has been added: |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
833 |
if no value for aKey is found, |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
834 |
lookup aKey with first character caseChanged and change the results first characters case. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
835 |
or aKey is '(...)', then lookup ... wrap () around the result. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
836 |
or aKey is '[...]', then lookup ... wrap [] around the result. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
837 |
or aKey is '{...}', then lookup ... wrap {} around the result. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
838 |
or aKey starts with a '\', then lookup aKey without '\' and prepend '\' to the result. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
839 |
or aKey ends with a '\', then lookup aKey without '\' and append '\' to the result. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
840 |
or aKey ends with a ':', then lookup aKey without ':' and append ':' to the result. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
841 |
or aKey ends with a '=', then lookup aKey without '=' and append '=' to the result. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
842 |
or aKey ends with a '.', then lookup aKey without '.' and append '.' to the result. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
843 |
or aKey ends with a ',', then lookup aKey without ',' and append ',' to the result. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
844 |
or aKey ends with a '?', then lookup aKey without '?' and append '?' to the result. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
845 |
or aKey ends with a '!!', then lookup aKey without '!!' and append '!!' to the result. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
846 |
or aKey ends with a ' ', then lookup aKey without ' ' and append ' ' to the result. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
847 |
or aKey ends with a ' ...', then lookup aKey without ' ...' and append '...' to the result. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
848 |
or aKey ends with a '...', then lookup aKey without '...' and append '...' to the result. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
849 |
or aKey includes '&', then lookup aKey without '&'. |
4035 | 850 |
|
851 |
This means, that only a single translation is required to provide local translations for |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
852 |
things like |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
853 |
'search' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
854 |
'search:' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
855 |
'search...' |
4035 | 856 |
" |
123 | 857 |
|
5573 | 858 |
|val alternativeKey usedKey idx first last| |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
859 |
|
4617 | 860 |
val := super at:aKey ifAbsent:nil. |
4678
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
861 |
val notNil ifTrue:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
862 |
^ val value |
4678
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
863 |
]. |
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
864 |
|
4848 | 865 |
(aKey isString and:[aKey notEmpty]) ifTrue:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
866 |
first := aKey first. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
867 |
last := aKey last. |
5573 | 868 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
869 |
"/ try with case-first swapped... |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
870 |
first isLetter ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
871 |
alternativeKey := first isUppercase |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
872 |
ifTrue:[aKey asLowercaseFirst] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
873 |
ifFalse:[aKey asUppercaseFirst]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
874 |
val := super at:alternativeKey ifAbsent:nil. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
875 |
val notNil ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
876 |
first isUppercase ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
877 |
^ val asUppercaseFirst |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
878 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
879 |
^ val asLowercaseFirst. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
880 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
881 |
]. |
4617 | 882 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
883 |
((first == $( and:[last == $) ]) |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
884 |
or:[ (first == $[ and:[last == $] ]) |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
885 |
or:[ (first == ${ and:[last == $} ]) ]]) ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
886 |
usedKey := aKey copyFrom:2 to:aKey size-1. |
5593 | 887 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
888 |
val := self localAt:usedKey. "/ recursion |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
889 |
val notNil ifTrue:[^ first asString,val,last asString]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
890 |
]. |
5593 | 891 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
892 |
last == $. ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
893 |
(aKey endsWith:' ...') ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
894 |
usedKey := aKey copyButLast:4. |
5573 | 895 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
896 |
val := self localAt:usedKey. "/ recursion |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
897 |
val notNil ifTrue:[^ val , ' ...']. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
898 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
899 |
(aKey endsWith:'...') ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
900 |
usedKey := aKey copyButLast:3. |
5573 | 901 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
902 |
val := self localAt:usedKey. "/ recursion |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
903 |
val notNil ifTrue:[^ val , '...']. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
904 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
905 |
]. |
5573 | 906 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
907 |
first isSeparator ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
908 |
usedKey := aKey withoutLeadingSeparators. |
4634 | 909 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
910 |
val := self localAt:usedKey. "/ recursion |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
911 |
val notNil ifTrue:[^ (aKey copyTo:(aKey size - usedKey size)), val]. "/ prepend the stripped separators |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
912 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
913 |
last isSeparator ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
914 |
usedKey := aKey withoutTrailingSeparators. |
4634 | 915 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
916 |
val := self localAt:usedKey. "/ recursion |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
917 |
val notNil ifTrue:[^ val, (aKey copyFrom:usedKey size + 1)]. "/ append the stripped separators |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
918 |
]. |
4634 | 919 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
920 |
('*:=.?!!,-><\' includes:last) ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
921 |
aKey size >= 2 ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
922 |
usedKey := aKey copyButLast:1. |
4617 | 923 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
924 |
val := self localAt:usedKey. "/ recursion |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
925 |
val notNil ifTrue:[^ val copyWith:last]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
926 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
927 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
928 |
('*:=.?!!-><\' includes:first) ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
929 |
aKey size >= 2 ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
930 |
usedKey := aKey copyFrom:2. |
4634 | 931 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
932 |
val := self localAt:usedKey. "/ recursion |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
933 |
val notNil ifTrue:[^ first asString , val]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
934 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
935 |
]. |
4028 | 936 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
937 |
(first == $( and:[last == $)]) ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
938 |
usedKey := aKey copyFrom:2 to:(aKey size - 1). |
4028 | 939 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
940 |
val := self localAt:usedKey. "/ recursion |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
941 |
val notNil ifTrue:[^ '(' , val , ')']. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
942 |
]. |
4017 | 943 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
944 |
(idx := aKey indexOf:$&) ~~ 0 ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
945 |
(aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
946 |
usedKey := (aKey copyTo:idx-1) , (aKey copyFrom:idx+1). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
947 |
val := self localAt:usedKey. "/ recursion |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
948 |
val notNil ifTrue:[^ val]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
949 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
950 |
]. |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
951 |
]. |
4617 | 952 |
^ nil. |
4580 | 953 |
|
4617 | 954 |
"Created: / 18-09-2006 / 17:33:27 / cg" |
4796 | 955 |
"Modified: / 21-08-2007 / 21:18:12 / cg" |
5593 | 956 |
"Modified: / 05-08-2010 / 16:52:32 / sr" |
2 | 957 |
! |
958 |
||
959 |
name:aKey default:default |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
960 |
"translate a string. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
961 |
Obsolete - use #string:default:" |
123 | 962 |
|
4844 | 963 |
<resource: #obsolete> |
964 |
||
72 | 965 |
^ self at:aKey ifAbsent:default |
2 | 966 |
! |
967 |
||
0 | 968 |
string:s |
3097 | 969 |
"translate (retrieve) a string - if not present, return s" |
123 | 970 |
|
72 | 971 |
^ self at:s ifAbsent:s |
3097 | 972 |
|
973 |
" |
|
974 |
NewLauncher classResources |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
975 |
string:'LICENCEFILE' |
3097 | 976 |
" |
0 | 977 |
! |
978 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
979 |
string:s default:defaultString |
3097 | 980 |
"translate (retrieve) a string - if not present, return defaultString" |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
981 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
982 |
^ self at:s ifAbsent:defaultString |
3097 | 983 |
|
984 |
" |
|
985 |
NewLauncher classResources |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
986 |
string:'fooBar' default:'Hello world' |
3097 | 987 |
" |
988 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
989 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
990 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
991 |
string:s default:defaultString with:arg |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
992 |
"translate and expand arg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
993 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
994 |
^ self string:s default:defaultString withArgs:(Array with:arg) |
3097 | 995 |
|
996 |
" |
|
997 |
NewLauncher classResources |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
998 |
string:'%1 fooBar' default:'Hello %1' with:'foo' |
3097 | 999 |
" |
1000 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1001 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1002 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1003 |
string:s default:defaultString with:arg1 with:arg2 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1004 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1005 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1006 |
^ self string:s default:defaultString withArgs:(Array with:arg1 with:arg2) |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1007 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1008 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1009 |
string:s default:defaultString with:arg1 with:arg2 with:arg3 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1010 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1011 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1012 |
^ self string:s default:defaultString withArgs:(Array with:arg1 with:arg2 with:arg3) |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1013 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1014 |
"Created: 9.12.1995 / 19:08:50 / cg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1015 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1016 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1017 |
string:s default:defaultString with:arg1 with:arg2 with:arg3 with:arg4 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1018 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1019 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1020 |
^ self string:s default:defaultString withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1021 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1022 |
"Created: 9.9.1996 / 18:52:14 / cg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1023 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1024 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1025 |
string:s default:defaultString withArgs:argArray |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1026 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1027 |
|
5070 | 1028 |
|template| |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1029 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1030 |
template := self at:s ifAbsent:defaultString. |
5070 | 1031 |
^ template expandPlaceholdersWith:argArray. |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1032 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1033 |
|
0 | 1034 |
string:s with:arg |
123 | 1035 |
"translate and expand arg" |
1036 |
||
0 | 1037 |
^ self string:s withArgs:(Array with:arg) |
1038 |
! |
|
1039 |
||
1040 |
string:s with:arg1 with:arg2 |
|
123 | 1041 |
"translate and expand args" |
1042 |
||
0 | 1043 |
^ self string:s withArgs:(Array with:arg1 with:arg2) |
1044 |
! |
|
1045 |
||
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1046 |
string:s with:arg1 with:arg2 with:arg3 |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1047 |
"translate and expand args" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1048 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1049 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3) |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1050 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1051 |
"Created: 9.12.1995 / 19:08:50 / cg" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1052 |
! |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1053 |
|
1042 | 1054 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 |
1055 |
"translate and expand args" |
|
1056 |
||
1057 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
1058 |
||
1059 |
"Created: 9.9.1996 / 18:52:14 / cg" |
|
1060 |
! |
|
1061 |
||
3184 | 1062 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
1063 |
"translate and expand args" |
|
1064 |
||
1065 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
1066 |
||
1067 |
! |
|
1068 |
||
5652 | 1069 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
1070 |
"translate and expand args" |
|
1071 |
||
1072 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6) |
|
1073 |
||
1074 |
"Created: / 13-11-2010 / 11:35:00 / cg" |
|
1075 |
! |
|
1076 |
||
1077 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7 |
|
1078 |
"translate and expand args" |
|
1079 |
||
1080 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7) |
|
1081 |
||
1082 |
"Created: / 13-11-2010 / 11:35:07 / cg" |
|
1083 |
! |
|
1084 |
||
0 | 1085 |
string:s withArgs:argArray |
4932
b19b928b0026
Allow (and insert) Texts as arguments in #string:with:
Stefan Vogel <sv@exept.de>
parents:
4848
diff
changeset
|
1086 |
"translate and expand args - allow text as arguments" |
123 | 1087 |
|
5069 | 1088 |
|template| |
0 | 1089 |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1090 |
template := self at:s ifAbsent:s. |
5069 | 1091 |
^ template expandPlaceholdersWith:argArray. |
4932
b19b928b0026
Allow (and insert) Texts as arguments in #string:with:
Stefan Vogel <sv@exept.de>
parents:
4848
diff
changeset
|
1092 |
|
5069 | 1093 |
|
1094 |
||
1095 |
||
1096 |
||
1097 |
||
1098 |
||
1099 |
||
3823 | 1100 |
! |
1101 |
||
4402 | 1102 |
stringWithCRs:s |
1103 |
"translate (retrieve) a string - if not present, return s" |
|
1104 |
||
1105 |
^ (self string:s) withCRs |
|
1106 |
||
1107 |
" |
|
1108 |
NewLauncher classResources |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1109 |
stringWithCRs:'LICENCEFILE' |
4402 | 1110 |
" |
1111 |
! |
|
1112 |
||
3823 | 1113 |
stringWithCRs:s with:arg |
1114 |
"translate, replace \'s with CRs and finally expand arg. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1115 |
CR-replacement is donw before args are inserted |
3823 | 1116 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1117 |
||
1118 |
^ self stringWithCRs:s withArgs:(Array with:arg) |
|
1119 |
||
1120 |
"Modified: / 21.3.2003 / 14:22:09 / cg" |
|
1121 |
! |
|
1122 |
||
1123 |
stringWithCRs:s with:arg1 with:arg2 |
|
1124 |
"translate, replace \'s with CRs and finally expand args. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1125 |
CR-replacement is donw before args are inserted |
3823 | 1126 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1127 |
||
1128 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2) |
|
1129 |
||
1130 |
"Modified: / 21.3.2003 / 14:22:06 / cg" |
|
1131 |
! |
|
1132 |
||
1133 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 |
|
1134 |
"translate, replace \'s with CRs and finally expand args. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1135 |
CR-replacement is donw before args are inserted |
3823 | 1136 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1137 |
||
1138 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3) |
|
1139 |
||
1140 |
"Created: 9.12.1995 / 19:08:50 / cg" |
|
1141 |
! |
|
1142 |
||
1143 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 |
|
1144 |
"translate, replace \'s with CRs and finally expand args. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1145 |
CR-replacement is donw before args are inserted |
3823 | 1146 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1147 |
||
1148 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
1149 |
||
1150 |
"Modified: / 21.3.2003 / 14:21:48 / cg" |
|
1151 |
! |
|
1152 |
||
1153 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
1154 |
"translate, replace \'s with CRs and finally expand args. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1155 |
CR-replacement is donw before args are inserted |
3823 | 1156 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1157 |
||
1158 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
1159 |
||
1160 |
"Modified: / 21.3.2003 / 14:21:55 / cg" |
|
1161 |
! |
|
1162 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1163 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
5652 | 1164 |
"translate, replace \'s with CRs and finally expand args. |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1165 |
CR-replacement is donw before args are inserted |
5652 | 1166 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1167 |
||
1168 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6) |
|
1169 |
||
1170 |
"Created: / 13-11-2010 / 11:35:30 / cg" |
|
1171 |
! |
|
1172 |
||
1173 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7 |
|
1174 |
"translate, replace \'s with CRs and finally expand args. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1175 |
CR-replacement is donw before args are inserted |
5652 | 1176 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1177 |
||
1178 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7) |
|
1179 |
||
1180 |
"Created: / 13-11-2010 / 11:35:20 / cg" |
|
1181 |
! |
|
1182 |
||
3823 | 1183 |
stringWithCRs:s withArgs:argArray |
1184 |
"translate, replace \'s with CRs and finally expand args. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1185 |
CR-replacement is done before args are inserted |
3823 | 1186 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1187 |
||
5070 | 1188 |
|template| |
3823 | 1189 |
|
1190 |
template := self at:s ifAbsent:s. |
|
5070 | 1191 |
^ template withCRs expandPlaceholdersWith:argArray. |
6174 | 1192 |
! |
1193 |
||
1194 |
whichPackIncludesKey:aKey |
|
1195 |
"for debugging: return the pack (alogn the super-pack chain), which |
|
1196 |
has a translation for a string" |
|
1197 |
||
1198 |
|val pack projectPack alreadySearched| |
|
1199 |
||
1200 |
aKey isNil ifTrue:[ ^ nil ]. |
|
1201 |
||
1202 |
val := self localAt:aKey. |
|
1203 |
val notNil ifTrue:[^ self]. |
|
1204 |
||
1205 |
(projectPack := self projectPack) notNil ifTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1206 |
val := projectPack localAt:aKey. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1207 |
val notNil ifTrue:[^ projectPack]. |
6174 | 1208 |
]. |
1209 |
alreadySearched := Set new. |
|
1210 |
projectPack notNil ifTrue:[ alreadySearched add:projectPack ]. |
|
1211 |
||
1212 |
pack := self superPack. |
|
1213 |
[ pack notNil ] whileTrue:[ |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1214 |
val := pack localAt:aKey. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1215 |
val notNil ifTrue:[^ pack]. |
6174 | 1216 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1217 |
(projectPack := pack projectPack) notNil ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1218 |
(alreadySearched includes:projectPack) ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1219 |
val := projectPack localAt:aKey. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1220 |
val notNil ifTrue:[^ projectPack]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1221 |
alreadySearched add:projectPack. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1222 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1223 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1224 |
pack := pack superPack |
6174 | 1225 |
]. |
1226 |
||
1227 |
alreadySearched copy do:[:projectPack | |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1228 |
|p| |
6174 | 1229 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1230 |
p := projectPack superPack. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1231 |
[p notNil and:[(alreadySearched includes:p) not]] whileTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1232 |
val := p localAt:aKey. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1233 |
val notNil ifTrue:[^ p]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1234 |
alreadySearched add:p. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1235 |
p := p superPack. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1236 |
]. |
6174 | 1237 |
]. |
1238 |
||
1239 |
^ nil |
|
0 | 1240 |
! ! |
1241 |
||
3317 | 1242 |
!ResourcePack methodsFor:'accessing-internals'! |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1243 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1244 |
name:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1245 |
"translate a string" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1246 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1247 |
^ self at:aKey ifAbsent:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1248 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1249 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1250 |
packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1251 |
^ packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1252 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1253 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1254 |
packsClassName:aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1255 |
packsClassName := aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1256 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1257 |
|
4093 | 1258 |
packsClassOrFileName |
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1259 |
"old: should no longer be used to access the filename; see packsFileName" |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1260 |
|
4093 | 1261 |
^ packsClassName |
1262 |
! |
|
1263 |
||
1264 |
packsClassOrFileName:aString |
|
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1265 |
"old: should no longer be used to access the filename; see packsFileName" |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1266 |
|
4093 | 1267 |
packsClassName := aString |
1268 |
! |
|
1269 |
||
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1270 |
packsFileName |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1271 |
^ packsFileName |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1272 |
! |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1273 |
|
4617 | 1274 |
projectPack |
1275 |
^ projectPack |
|
1276 |
||
1277 |
"Created: / 18-09-2006 / 17:38:07 / cg" |
|
1278 |
! |
|
1279 |
||
4085 | 1280 |
projectPack:anotherResourcePack |
1281 |
projectPack := anotherResourcePack |
|
1282 |
||
1283 |
"Created: / 29.1.1998 / 22:43:09 / cg" |
|
1284 |
! |
|
1285 |
||
4617 | 1286 |
superPack |
1287 |
^ superPack |
|
1288 |
||
1289 |
"Created: / 18-09-2006 / 17:38:12 / cg" |
|
1290 |
! |
|
1291 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1292 |
superPack:anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1293 |
superPack := anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1294 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1295 |
"Created: / 29.1.1998 / 22:43:09 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1296 |
! ! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1297 |
|
0 | 1298 |
!ResourcePack methodsFor:'file reading'! |
1299 |
||
684 | 1300 |
fileReadFailed |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1301 |
"return true, if the pack does not really contain |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1302 |
valid translations, since the fileRead failed. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1303 |
However, all inherited translations are still available |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1304 |
through the receiver" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1305 |
|
687 | 1306 |
^ fileReadFailed ~~ false |
684 | 1307 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1308 |
"Created: / 14.5.1996 / 10:19:26 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1309 |
"Modified: / 29.1.1998 / 22:46:38 / cg" |
684 | 1310 |
! |
1311 |
||
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1312 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1313 |
"asked to read definitions for a non-existing file. |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1314 |
Here, this is legal and ignored (typically using inherited resources). |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1315 |
However, subclasses (such as styleSheet) may flag it as an error." |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1316 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1317 |
^ nil |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1318 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1319 |
"Created: 6.9.1997 / 11:38:53 / cg" |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1320 |
! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1321 |
|
4332 | 1322 |
processLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError |
145 | 1323 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
1324 |
||
4509 | 1325 |
self class |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1326 |
processResourceLine:lineString |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1327 |
encoding:encodingSymbolOrEncoder |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1328 |
file:fileName |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1329 |
printErrorWith:printError |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1330 |
for:self |
144 | 1331 |
! |
1332 |
||
244 | 1333 |
readFromFile:fileName directory:dirName |
1334 |
"read definitions from a file in a directory" |
|
1335 |
||
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1336 |
|triedFilename inStream ok| |
244 | 1337 |
|
686 | 1338 |
fileReadFailed := false. |
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1339 |
"/ need to catch errors here, as the handler might itself need resources. |
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1340 |
"/ (happens when da.rs is not present in libbasic/resources.rs) |
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1341 |
ExternalStream openErrorSignal handle:[:ex | |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1342 |
Transcript showCR:'ResourcePack: failed to open file: ',fileName asString,' in ',dirName asString. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1343 |
inStream := nil. |
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1344 |
] do:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1345 |
dirName = 'resources' ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1346 |
inStream := Smalltalk resourceFileStreamFor:fileName |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1347 |
] ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1348 |
inStream := Smalltalk systemFileStreamFor: |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1349 |
(dirName isNil |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1350 |
ifTrue:[fileName] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1351 |
ifFalse:[dirName asFilename construct:fileName]). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1352 |
]. |
244 | 1353 |
]. |
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1354 |
|
244 | 1355 |
inStream isNil ifTrue:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1356 |
" |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1357 |
an empty pack |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1358 |
" |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1359 |
^ self nonexistingFileRead |
244 | 1360 |
]. |
2996 | 1361 |
|
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1362 |
triedFilename := inStream pathName. |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1363 |
[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1364 |
ok := self readFromResourceStream:inStream in:(triedFilename asFilename directoryName). |
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1365 |
] ensure:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1366 |
inStream close. |
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1367 |
]. |
686 | 1368 |
|
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1369 |
ok ifTrue:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1370 |
packsFileName := triedFilename |
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1371 |
] ifFalse:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1372 |
fileReadFailed := true. |
684 | 1373 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1374 |
('ResourcePack [warning]: "' , triedFilename , '" contains error(s) - data may be incomplete.') errorPrintCR. |
244 | 1375 |
]. |
1376 |
||
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1377 |
"Modified: / 20-08-2011 / 17:10:02 / cg" |
244 | 1378 |
! |
1379 |
||
72 | 1380 |
readFromResourceStream:inStream in:dirName |
4848 | 1381 |
"read definitions from a stream. The dirName argument is required to |
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1382 |
specify where #include files are searched for. |
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1383 |
Return true, if the style sheet could be read without errors, false otherwise." |
145 | 1384 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1385 |
|lineString l lineNumber rest value ifLevel skipping first ok encoding decoder pack errorHandler |
4947 | 1386 |
printError fileName pushedSkipValues| |
4058 | 1387 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1388 |
fileName := (inStream isFileStream |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1389 |
ifTrue:[inStream pathName asFilename baseName] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1390 |
ifFalse:['---']). |
4058 | 1391 |
|
1392 |
printError := [:message | |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1393 |
'ResourcePack [warning]: ' errorPrint. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1394 |
message errorPrint. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1395 |
' in file:' errorPrint. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1396 |
fileName errorPrint. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1397 |
' line: ' errorPrint. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1398 |
lineNumber errorPrintCR |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1399 |
]. |
4058 | 1400 |
|
1401 |
printError := [:message | ]. |
|
462
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1402 |
|
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1403 |
encoding := nil. |
0 | 1404 |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1405 |
ok := true. |
0 | 1406 |
ifLevel := 0. |
1407 |
skipping := false. |
|
4058 | 1408 |
lineNumber := 0. |
4947 | 1409 |
pushedSkipValues := OrderedCollection new. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1410 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1411 |
errorHandler := [:ex | |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1412 |
|con| |
4947 | 1413 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1414 |
Transcript showCR:('ResourcePack [warning]: ''' , ex description , '''') "errorPrintCR". |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1415 |
Transcript showCR:('ResourcePack [info]: file: ' , inStream pathName printString , ' line: ' , lineNumber printString , ': ''' , lineString , '''') "errorPrintCR". |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1416 |
con := ex suspendedContext. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1417 |
Transcript showCR:('ResourcePack [info]: in: ' , con fullPrintString) "errorPrintCR". |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1418 |
con := con sender. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1419 |
Transcript showCR:('ResourcePack [info]: : ' , con fullPrintString) "errorPrintCR". |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1420 |
con := con sender. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1421 |
Transcript showCR:('ResourcePack [info]: : ' , con fullPrintString) "errorPrintCR". |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1422 |
value := nil. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1423 |
ok := false. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1424 |
]. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1425 |
|
0 | 1426 |
[inStream atEnd] whileFalse:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1427 |
lineString := inStream nextLine. lineNumber := lineNumber + 1. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1428 |
[lineString notNil and:[lineString endsWith:$\]] whileTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1429 |
lineString := lineString copyButLast:1. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1430 |
l := inStream nextLine. lineNumber := lineNumber + 1. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1431 |
l notNil ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1432 |
lineString := lineString , l. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1433 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1434 |
]. |
177 | 1435 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1436 |
(lineString size > 0) ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1437 |
first := lineString at:1. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1438 |
"/ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1439 |
"/ for your convenience: treat both ';' AND '"/' as comment-line |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1440 |
"/ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1441 |
((first == $;) or:[lineString startsWith:'"/']) ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1442 |
((first == $#) and:[(lineString startsWith:'#(') not]) ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1443 |
"/ a directive |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1444 |
lineString := (lineString copyFrom:2) withoutSpaces. |
72 | 1445 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1446 |
(lineString startsWith:'if') ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1447 |
pushedSkipValues add:skipping. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1448 |
skipping ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1449 |
rest := lineString copyFrom:3. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1450 |
Error, UserInformation |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1451 |
handle:errorHandler |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1452 |
do:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1453 |
value := Compiler evaluate:rest compile:false. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1454 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1455 |
(value == #Error) ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1456 |
printError value:('error in resource:' , lineString). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1457 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1458 |
(value == false) ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1459 |
skipping := true |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1460 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1461 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1462 |
ifLevel := ifLevel + 1 |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1463 |
] ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1464 |
(lineString startsWith:'endif') ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1465 |
ifLevel == 0 ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1466 |
printError value:('if/endif nesting error'). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1467 |
] ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1468 |
ifLevel := ifLevel - 1. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1469 |
skipping := pushedSkipValues removeLast. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1470 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1471 |
] ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1472 |
(lineString startsWith:'else') ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1473 |
(pushedSkipValues includes:true) ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1474 |
skipping := skipping not |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1475 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1476 |
] ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1477 |
skipping ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1478 |
(lineString startsWith:'superpack') ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1479 |
rest := lineString copyFrom:('superpack' size + 1). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1480 |
value := Compiler evaluate:rest compile:false. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1481 |
(value isKindOf:ResourcePack) ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1482 |
superPack := value |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1483 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1484 |
] ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1485 |
(lineString startsWith:'include') ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1486 |
(lineString startsWith:'includeResourcesFor') ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1487 |
"/ include those resources ... |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1488 |
rest := lineString copyFrom:('includeResourcesFor' size + 1). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1489 |
value := Compiler evaluate:rest compile:false. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1490 |
value isBehavior ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1491 |
pack := self class for:value. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1492 |
pack notNil ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1493 |
self addAll:pack. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1494 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1495 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1496 |
] ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1497 |
rest := lineString copyFrom:('include' size + 1). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1498 |
value := Compiler evaluate:rest compile:false. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1499 |
value isString ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1500 |
printError value:('bad include filename: ' , value printString, ' "',lineString,'"'). |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1501 |
] ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1502 |
self readFromFile:value directory:dirName |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1503 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1504 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1505 |
] ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1506 |
(lineString startsWith:'encoding') ifTrue:[ |
4848 | 1507 |
"/decoder notNil ifTrue:[self halt:'oops - encoding change in file']. |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1508 |
encoding := self class extractEncodingFromLine:lineString. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1509 |
decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1510 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1511 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1512 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1513 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1514 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1515 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1516 |
]. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1517 |
] ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1518 |
skipping ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1519 |
Error, UserInformation |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1520 |
handle:errorHandler |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1521 |
do:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1522 |
(lineString at:1) == $!! ifTrue:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1523 |
"/ evaluate the rest |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1524 |
Compiler evaluate:(lineString copyFrom:2) |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1525 |
receiver:self |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1526 |
notifying:nil |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1527 |
compile:false. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1528 |
] ifFalse:[ |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1529 |
"/ process as resource |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1530 |
self |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1531 |
processLine:lineString |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1532 |
encoding:decoder |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1533 |
file:(inStream isFileStream |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1534 |
ifTrue:[inStream pathName] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1535 |
ifFalse:['---']) |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1536 |
printErrorWith:printError |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1537 |
]] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1538 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1539 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1540 |
] |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1541 |
] |
0 | 1542 |
]. |
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1543 |
^ ok |
177 | 1544 |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
1545 |
"Modified: / 31-08-1995 / 02:33:45 / claus" |
4619 | 1546 |
"Modified: / 18-09-2006 / 20:35:37 / cg" |
0 | 1547 |
! ! |
1548 |
||
4093 | 1549 |
!ResourcePack methodsFor:'printing & storing'! |
1550 |
||
5603
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1551 |
displayOn:aGCOrStream |
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1552 |
|
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1553 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1554 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
6545 | 1555 |
(aGCOrStream isStream) ifTrue:[ |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1556 |
aGCOrStream nextPutAll:'ResourcePack for: '. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1557 |
packsClassName printOn:aGCOrStream. |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1558 |
^ self. |
5603
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1559 |
]. |
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1560 |
|
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1561 |
^ super displayOn:aGCOrStream |
4093 | 1562 |
! ! |
1563 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
1564 |
!ResourcePack class methodsFor:'documentation'! |
251 | 1565 |
|
1566 |
version |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1567 |
^ '$Header$' |
5357 | 1568 |
! |
1569 |
||
1570 |
version_CVS |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1571 |
^ '$Header$' |
251 | 1572 |
! ! |
3769 | 1573 |
|
6051
f01078ce8c2c
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
5951
diff
changeset
|
1574 |
|
0 | 1575 |
ResourcePack initialize! |