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