author | sr |
Thu, 29 Oct 2009 14:52:02 +0100 | |
changeset 5431 | 02cd0985796a |
parent 5430 | 128e9b37fd8a |
child 5466 | a88d9cf361e2 |
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 |
||
5430
128e9b37fd8a
comment/format in: #processResourceLine:encoding:file:printErrorWith:for:
sr
parents:
5370
diff
changeset
|
593 |
"/ Transcript show:name; show:' -> '; showCR:value. |
128e9b37fd8a
comment/format in: #processResourceLine:encoding:file:printErrorWith:for:
sr
parents:
5370
diff
changeset
|
594 |
|
4510 | 595 |
hasError ifFalse:[ |
596 |
(conditional not |
|
597 |
or:[(aResourcePack includesKey:name) not]) ifTrue:[ |
|
598 |
name = value ifTrue:[ |
|
599 |
keepUselessTranslations ifFalse:[ |
|
4509 | 600 |
printError value:('useless resource: "' , name , '"'). |
4510 | 601 |
ignoreTranslation := true |
602 |
]. |
|
603 |
]. |
|
604 |
ignoreTranslation ifFalse:[ |
|
605 |
oldValue := aResourcePack at:name ifAbsent:nil. |
|
606 |
oldValue notNil ifTrue:[ |
|
607 |
oldValue ~= value ifTrue:[ |
|
608 |
printError value:('conflicting resource: "' , name , '"'). |
|
609 |
printError value:('oldValue: ' , oldValue printString). |
|
610 |
printError value:('newValue: ' , value printString). |
|
611 |
] ifFalse:[ |
|
612 |
printError value:('duplicate resource: "' , name , '"'). |
|
4509 | 613 |
]. |
4510 | 614 |
]. |
4670 | 615 |
indirect ifTrue:[ |
616 |
value := aResourcePack string:value. |
|
617 |
]. |
|
5431 | 618 |
value class == String ifTrue:[ |
619 |
||
620 |
value := value copy changeClassTo:ImmutableString. |
|
621 |
]. |
|
622 |
||
623 |
||
4510 | 624 |
aResourcePack at:name put:value. |
4509 | 625 |
] |
626 |
] |
|
627 |
] |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
628 |
|
4678
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
629 |
"Modified: / 09-11-2006 / 13:17:48 / cg" |
4509 | 630 |
! ! |
631 |
||
0 | 632 |
!ResourcePack methodsFor:'accessing'! |
633 |
||
244 | 634 |
array:anArray |
635 |
"translate a collection of strings" |
|
0 | 636 |
|
244 | 637 |
^ anArray collect:[:r | self at:r default:r] |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
638 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
639 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
640 |
Launcher classResources array:#('file' 'classes') |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
641 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
642 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
643 |
"Modified: / 29.1.1998 / 22:44:22 / cg" |
0 | 644 |
! |
645 |
||
2 | 646 |
at:aKey |
123 | 647 |
"translate a string" |
648 |
||
72 | 649 |
^ self at:aKey ifAbsent:aKey |
0 | 650 |
! |
651 |
||
652 |
at:aKey default:default |
|
123 | 653 |
"translate a string" |
654 |
||
72 | 655 |
^ self at:aKey ifAbsent:default |
0 | 656 |
! |
657 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
658 |
at:aKey ifAbsent:defaultValue |
4617 | 659 |
"translate a string; search here, in my projects pack and in my superpack(s)" |
660 |
||
661 |
|val pack projectPack alreadySearched| |
|
662 |
||
663 |
aKey isNil ifTrue:[ ^ defaultValue value ]. |
|
664 |
||
665 |
val := self localAt:aKey. |
|
666 |
val notNil ifTrue:[^ val]. |
|
667 |
||
668 |
(projectPack := self projectPack) notNil ifTrue:[ |
|
669 |
val := projectPack localAt:aKey. |
|
670 |
val notNil ifTrue:[^ val]. |
|
671 |
]. |
|
672 |
alreadySearched := Set new. |
|
673 |
projectPack notNil ifTrue:[ alreadySearched add:projectPack ]. |
|
674 |
||
675 |
pack := self superPack. |
|
676 |
[ pack notNil ] whileTrue:[ |
|
677 |
val := pack localAt:aKey. |
|
678 |
val notNil ifTrue:[^ val]. |
|
679 |
||
680 |
(projectPack := pack projectPack) notNil ifTrue:[ |
|
681 |
(alreadySearched includes:projectPack) ifFalse:[ |
|
682 |
val := projectPack localAt:aKey. |
|
683 |
val notNil ifTrue:[^ val]. |
|
684 |
alreadySearched add:projectPack. |
|
685 |
]. |
|
686 |
]. |
|
687 |
pack := pack superPack |
|
688 |
]. |
|
689 |
||
4618 | 690 |
alreadySearched copy do:[:projectPack | |
691 |
|p| |
|
692 |
||
693 |
p := projectPack superPack. |
|
694 |
[p notNil and:[(alreadySearched includes:p) not]] whileTrue:[ |
|
695 |
val := p localAt:aKey. |
|
696 |
val notNil ifTrue:[^ val]. |
|
697 |
alreadySearched add:p. |
|
698 |
p := p superPack. |
|
699 |
]. |
|
700 |
]. |
|
701 |
||
4617 | 702 |
^ defaultValue value |
703 |
||
4618 | 704 |
"Modified: / 18-09-2006 / 18:50:52 / cg" |
4617 | 705 |
! |
706 |
||
707 |
localAt:aKey |
|
4035 | 708 |
"translate a string. |
709 |
Some special 'intelligence' has been added: |
|
710 |
if no value for aKey is found, |
|
4036 | 711 |
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
|
712 |
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
|
713 |
or aKey ends with a '\', then lookup aKey without '\' and append '\' to the result. |
4036 | 714 |
or aKey ends with a ':', then lookup aKey without ':' and append ':' to the result. |
715 |
or aKey ends with a '=', then lookup aKey without '=' and append '=' to the result. |
|
4037 | 716 |
or aKey ends with a '.', then lookup aKey without '.' and append '.' to the result. |
4796 | 717 |
or aKey ends with a ',', then lookup aKey without ',' and append ',' to the result. |
4844 | 718 |
or aKey ends with a '?', then lookup aKey without '?' and append '?' to the result. |
719 |
or aKey ends with a '!!', then lookup aKey without '!!' and append '!!' to the result. |
|
4036 | 720 |
or aKey ends with a ' ', then lookup aKey without ' '. |
721 |
or aKey ends with a ' ...', then lookup aKey without ' ...' and append '...' to the result. |
|
722 |
or aKey ends with a '...', then lookup aKey without '...' and append '...' to the result. |
|
723 |
or aKey includes '&', then lookup aKey without '&'. |
|
4035 | 724 |
|
725 |
This means, that only a single translation is required to provide local translations for |
|
726 |
things like |
|
727 |
'search' |
|
728 |
'search:' |
|
729 |
'search...' |
|
730 |
" |
|
123 | 731 |
|
4017 | 732 |
|val alternativeKey rest usedKey idx| |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
733 |
|
4617 | 734 |
val := super at:aKey ifAbsent:nil. |
4678
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
735 |
val notNil ifTrue:[ |
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
736 |
^ val value |
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
737 |
]. |
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
738 |
|
4848 | 739 |
(aKey isString and:[aKey notEmpty]) ifTrue:[ |
4617 | 740 |
"/ try with case-first swapped... |
741 |
(aKey first isLetter) ifTrue:[ |
|
742 |
alternativeKey := aKey isUppercaseFirst |
|
743 |
ifTrue:[aKey asLowercaseFirst] |
|
744 |
ifFalse:[aKey asUppercaseFirst]. |
|
745 |
val := super at:alternativeKey ifAbsent:nil. |
|
746 |
val notNil ifTrue:[ |
|
747 |
aKey isUppercaseFirst ifTrue:[ |
|
748 |
^ val asUppercaseFirst |
|
3979
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
749 |
]. |
4617 | 750 |
^ val asLowercaseFirst. |
4028 | 751 |
]. |
4617 | 752 |
]. |
753 |
||
4634 | 754 |
(aKey endsWith:' ...') ifTrue:[ |
755 |
usedKey := aKey copyWithoutLast:4. |
|
756 |
||
757 |
val := self localAt:usedKey. "/ recursion |
|
758 |
val notNil ifTrue:[^ val , '...']. |
|
759 |
]. |
|
760 |
(aKey endsWith:'...') ifTrue:[ |
|
761 |
usedKey := aKey copyWithoutLast:3. |
|
762 |
||
763 |
val := self localAt:usedKey. "/ recursion |
|
764 |
val notNil ifTrue:[^ val , '...']. |
|
765 |
]. |
|
766 |
||
5369 | 767 |
(':=.?!!,-><' includes:aKey last) ifTrue:[ |
4634 | 768 |
aKey size > 2 ifTrue:[ |
769 |
rest := aKey last. |
|
770 |
usedKey := aKey copyWithoutLast:1. |
|
4617 | 771 |
|
4634 | 772 |
val := self localAt:usedKey. "/ recursion |
773 |
val notNil ifTrue:[^ val , rest]. |
|
774 |
]. |
|
775 |
]. |
|
5370 | 776 |
(':=.?!!->< ' includes:aKey first) ifTrue:[ |
4634 | 777 |
aKey size > 2 ifTrue:[ |
778 |
rest := aKey first. |
|
779 |
usedKey := aKey copyFrom:2. |
|
780 |
||
781 |
val := self localAt:usedKey. "/ recursion |
|
782 |
val notNil ifTrue:[^ rest asString , val]. |
|
783 |
]. |
|
4617 | 784 |
]. |
4028 | 785 |
|
4617 | 786 |
((aKey startsWith:'(') and:[(aKey endsWith:')')]) ifTrue:[ |
787 |
usedKey := aKey copyFrom:2 to:(aKey size - 1). |
|
4028 | 788 |
|
4634 | 789 |
val := self localAt:usedKey. "/ recursion |
4617 | 790 |
val notNil ifTrue:[^ '(' , val , ')']. |
791 |
]. |
|
4967
978b4be7c3b7
keay lookup - allow for initial and trailing '\'s
Claus Gittinger <cg@exept.de>
parents:
4963
diff
changeset
|
792 |
(aKey startsWith:'\') ifTrue:[ |
978b4be7c3b7
keay lookup - allow for initial and trailing '\'s
Claus Gittinger <cg@exept.de>
parents:
4963
diff
changeset
|
793 |
usedKey := aKey copyFrom:2. |
978b4be7c3b7
keay lookup - allow for initial and trailing '\'s
Claus Gittinger <cg@exept.de>
parents:
4963
diff
changeset
|
794 |
|
978b4be7c3b7
keay lookup - allow for initial and trailing '\'s
Claus Gittinger <cg@exept.de>
parents:
4963
diff
changeset
|
795 |
val := self localAt:usedKey. "/ recursion |
978b4be7c3b7
keay lookup - allow for initial and trailing '\'s
Claus Gittinger <cg@exept.de>
parents:
4963
diff
changeset
|
796 |
val notNil ifTrue:[^ '\' , val]. |
978b4be7c3b7
keay lookup - allow for initial and trailing '\'s
Claus Gittinger <cg@exept.de>
parents:
4963
diff
changeset
|
797 |
]. |
978b4be7c3b7
keay lookup - allow for initial and trailing '\'s
Claus Gittinger <cg@exept.de>
parents:
4963
diff
changeset
|
798 |
(aKey endsWith:'\') ifTrue:[ |
978b4be7c3b7
keay lookup - allow for initial and trailing '\'s
Claus Gittinger <cg@exept.de>
parents:
4963
diff
changeset
|
799 |
usedKey := aKey copyWithoutLast:1. |
978b4be7c3b7
keay lookup - allow for initial and trailing '\'s
Claus Gittinger <cg@exept.de>
parents:
4963
diff
changeset
|
800 |
|
978b4be7c3b7
keay lookup - allow for initial and trailing '\'s
Claus Gittinger <cg@exept.de>
parents:
4963
diff
changeset
|
801 |
val := self localAt:usedKey. "/ recursion |
978b4be7c3b7
keay lookup - allow for initial and trailing '\'s
Claus Gittinger <cg@exept.de>
parents:
4963
diff
changeset
|
802 |
val notNil ifTrue:[^ val,'\']. |
978b4be7c3b7
keay lookup - allow for initial and trailing '\'s
Claus Gittinger <cg@exept.de>
parents:
4963
diff
changeset
|
803 |
]. |
4617 | 804 |
(aKey endsWith:' ') ifTrue:[ |
805 |
usedKey := aKey withoutSeparators. |
|
806 |
||
4634 | 807 |
val := self localAt:usedKey. "/ recursion |
4617 | 808 |
val notNil ifTrue:[^ val]. |
809 |
]. |
|
4017 | 810 |
|
4617 | 811 |
(idx := aKey indexOf:$&) ~~ 0 ifTrue:[ |
812 |
(aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[ |
|
813 |
usedKey := (aKey copyTo:idx-1) , (aKey copyFrom:idx+1). |
|
4848 | 814 |
val := self localAt:usedKey. "/ recursion |
4028 | 815 |
val notNil ifTrue:[^ val]. |
816 |
]. |
|
3979
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
817 |
]. |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
818 |
]. |
4617 | 819 |
^ nil. |
4580 | 820 |
|
4617 | 821 |
"Created: / 18-09-2006 / 17:33:27 / cg" |
4796 | 822 |
"Modified: / 21-08-2007 / 21:18:12 / cg" |
2 | 823 |
! |
824 |
||
825 |
name:aKey default:default |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
826 |
"translate a string. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
827 |
Obsolete - use #string:default:" |
123 | 828 |
|
4844 | 829 |
<resource: #obsolete> |
830 |
||
72 | 831 |
^ self at:aKey ifAbsent:default |
2 | 832 |
! |
833 |
||
0 | 834 |
string:s |
3097 | 835 |
"translate (retrieve) a string - if not present, return s" |
123 | 836 |
|
72 | 837 |
^ self at:s ifAbsent:s |
3097 | 838 |
|
839 |
" |
|
840 |
NewLauncher classResources |
|
3762 | 841 |
string:'LICENCEFILE' |
3097 | 842 |
" |
0 | 843 |
! |
844 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
845 |
string:s default:defaultString |
3097 | 846 |
"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
|
847 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
848 |
^ self at:s ifAbsent:defaultString |
3097 | 849 |
|
850 |
" |
|
851 |
NewLauncher classResources |
|
3762 | 852 |
string:'fooBar' default:'Hello world' |
3097 | 853 |
" |
854 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
855 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
856 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
857 |
string:s default:defaultString with:arg |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
858 |
"translate and expand arg" |
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 |
^ self string:s default:defaultString withArgs:(Array with:arg) |
3097 | 861 |
|
862 |
" |
|
863 |
NewLauncher classResources |
|
3762 | 864 |
string:'%1 fooBar' default:'Hello %1' with:'foo' |
3097 | 865 |
" |
866 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
867 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
868 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
869 |
string:s default:defaultString with:arg1 with:arg2 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
870 |
"translate and expand args" |
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 |
^ 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
|
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 |
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) |
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.12.1995 / 19:08:50 / 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 with:arg1 with:arg2 with:arg3 with:arg4 |
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 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
886 |
^ 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
|
887 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
888 |
"Created: 9.9.1996 / 18:52:14 / cg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
889 |
! |
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 |
string:s default:defaultString withArgs:argArray |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
892 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
893 |
|
5070 | 894 |
|template| |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
895 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
896 |
template := self at:s ifAbsent:defaultString. |
5070 | 897 |
^ template expandPlaceholdersWith:argArray. |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
898 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
899 |
|
0 | 900 |
string:s with:arg |
123 | 901 |
"translate and expand arg" |
902 |
||
0 | 903 |
^ self string:s withArgs:(Array with:arg) |
904 |
! |
|
905 |
||
906 |
string:s with:arg1 with:arg2 |
|
123 | 907 |
"translate and expand args" |
908 |
||
0 | 909 |
^ self string:s withArgs:(Array with:arg1 with:arg2) |
910 |
! |
|
911 |
||
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
912 |
string:s with:arg1 with:arg2 with:arg3 |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
913 |
"translate and expand args" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
914 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
915 |
^ 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
|
916 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
917 |
"Created: 9.12.1995 / 19:08:50 / cg" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
918 |
! |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
919 |
|
1042 | 920 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 |
921 |
"translate and expand args" |
|
922 |
||
923 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
924 |
||
925 |
"Created: 9.9.1996 / 18:52:14 / cg" |
|
926 |
! |
|
927 |
||
3184 | 928 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
929 |
"translate and expand args" |
|
930 |
||
931 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
932 |
||
933 |
! |
|
934 |
||
0 | 935 |
string:s withArgs:argArray |
4932
b19b928b0026
Allow (and insert) Texts as arguments in #string:with:
Stefan Vogel <sv@exept.de>
parents:
4848
diff
changeset
|
936 |
"translate and expand args - allow text as arguments" |
123 | 937 |
|
5069 | 938 |
|template| |
0 | 939 |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
940 |
template := self at:s ifAbsent:s. |
5069 | 941 |
^ template expandPlaceholdersWith:argArray. |
4932
b19b928b0026
Allow (and insert) Texts as arguments in #string:with:
Stefan Vogel <sv@exept.de>
parents:
4848
diff
changeset
|
942 |
|
5069 | 943 |
|
944 |
||
945 |
||
946 |
||
947 |
||
948 |
||
949 |
||
3823 | 950 |
! |
951 |
||
4402 | 952 |
stringWithCRs:s |
953 |
"translate (retrieve) a string - if not present, return s" |
|
954 |
||
955 |
^ (self string:s) withCRs |
|
956 |
||
957 |
" |
|
958 |
NewLauncher classResources |
|
959 |
stringWithCRs:'LICENCEFILE' |
|
960 |
" |
|
961 |
! |
|
962 |
||
3823 | 963 |
stringWithCRs:s with:arg |
964 |
"translate, replace \'s with CRs and finally expand arg. |
|
965 |
CR-replacement is donw before args are inserted |
|
966 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
967 |
||
968 |
^ self stringWithCRs:s withArgs:(Array with:arg) |
|
969 |
||
970 |
"Modified: / 21.3.2003 / 14:22:09 / cg" |
|
971 |
! |
|
972 |
||
973 |
stringWithCRs:s with:arg1 with:arg2 |
|
974 |
"translate, replace \'s with CRs and finally expand args. |
|
975 |
CR-replacement is donw before args are inserted |
|
976 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
977 |
||
978 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2) |
|
979 |
||
980 |
"Modified: / 21.3.2003 / 14:22:06 / cg" |
|
981 |
! |
|
982 |
||
983 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 |
|
984 |
"translate, replace \'s with CRs and finally expand args. |
|
985 |
CR-replacement is donw before args are inserted |
|
986 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
987 |
||
988 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3) |
|
989 |
||
990 |
"Created: 9.12.1995 / 19:08:50 / cg" |
|
991 |
! |
|
992 |
||
993 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 |
|
994 |
"translate, replace \'s with CRs and finally expand args. |
|
995 |
CR-replacement is donw before args are inserted |
|
996 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
997 |
||
998 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
999 |
||
1000 |
"Modified: / 21.3.2003 / 14:21:48 / cg" |
|
1001 |
! |
|
1002 |
||
1003 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
1004 |
"translate, replace \'s with CRs and finally expand args. |
|
1005 |
CR-replacement is donw before args are inserted |
|
1006 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
1007 |
||
1008 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
1009 |
||
1010 |
"Modified: / 21.3.2003 / 14:21:55 / cg" |
|
1011 |
! |
|
1012 |
||
1013 |
stringWithCRs:s withArgs:argArray |
|
1014 |
"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
|
1015 |
CR-replacement is done before args are inserted |
3823 | 1016 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1017 |
||
5070 | 1018 |
|template| |
3823 | 1019 |
|
1020 |
template := self at:s ifAbsent:s. |
|
5070 | 1021 |
^ template withCRs expandPlaceholdersWith:argArray. |
0 | 1022 |
! ! |
1023 |
||
3317 | 1024 |
!ResourcePack methodsFor:'accessing-internals'! |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1025 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1026 |
name:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1027 |
"translate a string" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1028 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1029 |
^ self at:aKey ifAbsent:aKey |
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 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1032 |
packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1033 |
^ packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1034 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1035 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1036 |
packsClassName:aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1037 |
packsClassName := aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1038 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1039 |
|
4093 | 1040 |
packsClassOrFileName |
1041 |
^ packsClassName |
|
1042 |
! |
|
1043 |
||
1044 |
packsClassOrFileName:aString |
|
1045 |
packsClassName := aString |
|
1046 |
! |
|
1047 |
||
4617 | 1048 |
projectPack |
1049 |
^ projectPack |
|
1050 |
||
1051 |
"Created: / 18-09-2006 / 17:38:07 / cg" |
|
1052 |
! |
|
1053 |
||
4085 | 1054 |
projectPack:anotherResourcePack |
1055 |
projectPack := anotherResourcePack |
|
1056 |
||
1057 |
"Created: / 29.1.1998 / 22:43:09 / cg" |
|
1058 |
! |
|
1059 |
||
4617 | 1060 |
superPack |
1061 |
^ superPack |
|
1062 |
||
1063 |
"Created: / 18-09-2006 / 17:38:12 / cg" |
|
1064 |
! |
|
1065 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1066 |
superPack:anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1067 |
superPack := anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1068 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1069 |
"Created: / 29.1.1998 / 22:43:09 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1070 |
! ! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1071 |
|
0 | 1072 |
!ResourcePack methodsFor:'file reading'! |
1073 |
||
684 | 1074 |
fileReadFailed |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1075 |
"return true, if the pack does not really contain |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1076 |
valid translations, since the fileRead failed. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1077 |
However, all inherited translations are still available |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1078 |
through the receiver" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1079 |
|
687 | 1080 |
^ fileReadFailed ~~ false |
684 | 1081 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1082 |
"Created: / 14.5.1996 / 10:19:26 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1083 |
"Modified: / 29.1.1998 / 22:46:38 / cg" |
684 | 1084 |
! |
1085 |
||
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1086 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1087 |
"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
|
1088 |
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
|
1089 |
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
|
1090 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1091 |
^ nil |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1092 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1093 |
"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
|
1094 |
! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1095 |
|
4332 | 1096 |
processLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError |
145 | 1097 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
1098 |
||
4509 | 1099 |
self class |
1100 |
processResourceLine:lineString |
|
1101 |
encoding:encodingSymbolOrEncoder |
|
1102 |
file:fileName |
|
1103 |
printErrorWith:printError |
|
1104 |
for:self |
|
144 | 1105 |
! |
1106 |
||
244 | 1107 |
readFromFile:fileName directory:dirName |
1108 |
"read definitions from a file in a directory" |
|
1109 |
||
1110 |
|inStream ok| |
|
1111 |
||
686 | 1112 |
fileReadFailed := false. |
244 | 1113 |
dirName = 'resources' ifTrue:[ |
3769 | 1114 |
inStream := Smalltalk resourceFileStreamFor:fileName |
244 | 1115 |
] ifFalse:[ |
3769 | 1116 |
inStream := Smalltalk |
1117 |
systemFileStreamFor:(dirName |
|
1118 |
isNil ifTrue:[fileName] |
|
1119 |
ifFalse:[dirName asFilename construct:fileName]). |
|
244 | 1120 |
]. |
1121 |
inStream isNil ifTrue:[ |
|
3769 | 1122 |
" |
1123 |
an empty pack |
|
1124 |
" |
|
1125 |
^ self nonexistingFileRead |
|
244 | 1126 |
]. |
2996 | 1127 |
|
4093 | 1128 |
ok := self readFromResourceStream:inStream in:(inStream pathName asFilename directoryName). |
244 | 1129 |
inStream close. |
686 | 1130 |
|
244 | 1131 |
ok ifFalse:[ |
3769 | 1132 |
fileReadFailed := true. |
684 | 1133 |
|
3769 | 1134 |
('ResourcePack [warning]: ''' , inStream pathName , ''' contains error(s) - data may be incomplete.') errorPrintCR. |
244 | 1135 |
]. |
1136 |
||
4656 | 1137 |
"Modified: / 19-10-2006 / 22:46:48 / cg" |
244 | 1138 |
! |
1139 |
||
72 | 1140 |
readFromResourceStream:inStream in:dirName |
4848 | 1141 |
"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
|
1142 |
specify where #include files are searched for. |
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1143 |
Return true, if the style sheet could be read without errors, false otherwise." |
145 | 1144 |
|
4058 | 1145 |
|lineString l lineNumber rest value ifLevel skipping first ok encoding decoder pack errorHandler |
4947 | 1146 |
printError fileName pushedSkipValues| |
4058 | 1147 |
|
1148 |
fileName := (inStream isFileStream |
|
1149 |
ifTrue:[inStream pathName asFilename baseName] |
|
1150 |
ifFalse:['---']). |
|
1151 |
||
1152 |
printError := [:message | |
|
1153 |
'ResourcePack [warning]: ' errorPrint. |
|
1154 |
message errorPrint. |
|
1155 |
' in file:' errorPrint. |
|
1156 |
fileName errorPrint. |
|
1157 |
' line: ' errorPrint. |
|
1158 |
lineNumber errorPrintCR |
|
1159 |
]. |
|
1160 |
||
1161 |
printError := [:message | ]. |
|
462
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1162 |
|
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1163 |
encoding := nil. |
0 | 1164 |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1165 |
ok := true. |
0 | 1166 |
ifLevel := 0. |
1167 |
skipping := false. |
|
4058 | 1168 |
lineNumber := 0. |
4947 | 1169 |
pushedSkipValues := OrderedCollection new. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1170 |
|
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1171 |
errorHandler := [:ex | |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1172 |
|con| |
4947 | 1173 |
|
1174 |
Transcript showCR:('ResourcePack [warning]: ''' , ex description , '''') "errorPrintCR". |
|
1175 |
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
|
1176 |
con := ex suspendedContext. |
4947 | 1177 |
Transcript showCR:('ResourcePack [info]: in: ' , con fullPrintString) "errorPrintCR". |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1178 |
con := con sender. |
4947 | 1179 |
Transcript showCR:('ResourcePack [info]: : ' , con fullPrintString) "errorPrintCR". |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1180 |
con := con sender. |
4947 | 1181 |
Transcript showCR:('ResourcePack [info]: : ' , con fullPrintString) "errorPrintCR". |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1182 |
value := nil. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1183 |
ok := false. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1184 |
]. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1185 |
|
0 | 1186 |
[inStream atEnd] whileFalse:[ |
4058 | 1187 |
lineString := inStream nextLine. lineNumber := lineNumber + 1. |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1188 |
[lineString notNil and:[lineString endsWith:$\]] whileTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1189 |
lineString := lineString copyWithoutLast:1. |
4058 | 1190 |
l := inStream nextLine. lineNumber := lineNumber + 1. |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1191 |
l notNil ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1192 |
lineString := lineString , l. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1193 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1194 |
]. |
177 | 1195 |
|
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1196 |
(lineString size > 0) ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1197 |
first := lineString at:1. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1198 |
"/ |
4947 | 1199 |
"/ for your convenience: treat both ';' AND '"/' as comment-line |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1200 |
"/ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1201 |
((first == $;) or:[lineString startsWith:'"/']) ifFalse:[ |
4332 | 1202 |
((first == $#) and:[(lineString startsWith:'#(') not]) ifTrue:[ |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1203 |
"/ a directive |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1204 |
lineString := (lineString copyFrom:2) withoutSpaces. |
72 | 1205 |
|
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1206 |
(lineString startsWith:'if') ifTrue:[ |
4947 | 1207 |
pushedSkipValues add:skipping. |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1208 |
skipping ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1209 |
rest := lineString copyFrom:3. |
4835
1f64020798d9
changed #readFromResourceStream:in:
Stefan Vogel <sv@exept.de>
parents:
4796
diff
changeset
|
1210 |
Error, UserInformation |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1211 |
handle:errorHandler |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1212 |
do:[ |
4947 | 1213 |
value := Compiler evaluate:rest compile:false. |
4835
1f64020798d9
changed #readFromResourceStream:in:
Stefan Vogel <sv@exept.de>
parents:
4796
diff
changeset
|
1214 |
]. |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1215 |
(value == #Error) ifTrue:[ |
4058 | 1216 |
printError value:('error in resource:' , lineString). |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1217 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1218 |
(value == false) ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1219 |
skipping := true |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1220 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1221 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1222 |
ifLevel := ifLevel + 1 |
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:'endif') ifTrue:[ |
4950 | 1225 |
ifLevel == 0 ifTrue:[ |
1226 |
printError value:('if/endif nesting error'). |
|
1227 |
] ifFalse:[ |
|
1228 |
ifLevel := ifLevel - 1. |
|
1229 |
skipping := pushedSkipValues removeLast. |
|
1230 |
] |
|
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1231 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1232 |
(lineString startsWith:'else') ifTrue:[ |
4947 | 1233 |
(pushedSkipValues includes:true) ifFalse:[ |
1234 |
skipping := skipping not |
|
1235 |
] |
|
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1236 |
] ifFalse:[ |
4947 | 1237 |
skipping ifFalse:[ |
1238 |
(lineString startsWith:'superpack') ifTrue:[ |
|
1239 |
rest := lineString copyFrom:('superpack' size + 1). |
|
1240 |
value := Compiler evaluate:rest compile:false. |
|
1241 |
(value isKindOf:ResourcePack) ifTrue:[ |
|
1242 |
superPack := value |
|
1243 |
] |
|
1244 |
] ifFalse:[ |
|
4618 | 1245 |
(lineString startsWith:'include') ifTrue:[ |
1246 |
(lineString startsWith:'includeResourcesFor') ifTrue:[ |
|
1247 |
"/ include those resources ... |
|
1248 |
rest := lineString copyFrom:('includeResourcesFor' size + 1). |
|
1249 |
value := Compiler evaluate:rest compile:false. |
|
1250 |
value isBehavior ifTrue:[ |
|
1251 |
pack := self class for:value. |
|
1252 |
pack notNil ifTrue:[ |
|
1253 |
self addAll:pack. |
|
1254 |
] |
|
1255 |
] |
|
1256 |
] ifFalse:[ |
|
1257 |
rest := lineString copyFrom:('include' size + 1). |
|
1258 |
value := Compiler evaluate:rest compile:false. |
|
1259 |
value isString ifFalse:[ |
|
1260 |
printError value:('bad include filename: ' , value printString, ' "',lineString,'"'). |
|
1261 |
] ifTrue:[ |
|
1262 |
self readFromFile:value directory:dirName |
|
3817
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 |
] ifFalse:[ |
4618 | 1266 |
(lineString startsWith:'encoding') ifTrue:[ |
4848 | 1267 |
"/decoder notNil ifTrue:[self halt:'oops - encoding change in file']. |
4618 | 1268 |
encoding := self class extractEncodingFromLine:lineString. |
1269 |
decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil. |
|
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1270 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1271 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1272 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1273 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1274 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1275 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1276 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1277 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1278 |
skipping ifFalse:[ |
4835
1f64020798d9
changed #readFromResourceStream:in:
Stefan Vogel <sv@exept.de>
parents:
4796
diff
changeset
|
1279 |
Error, UserInformation |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1280 |
handle:errorHandler |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1281 |
do:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1282 |
(lineString at:1) == $!! ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1283 |
"/ evaluate the rest |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1284 |
Compiler evaluate:(lineString copyFrom:2) |
4332 | 1285 |
receiver:self |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1286 |
notifying:nil |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1287 |
compile:false. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1288 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1289 |
"/ process as resource |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1290 |
self |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1291 |
processLine:lineString |
4017 | 1292 |
encoding:decoder |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1293 |
file:(inStream isFileStream |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1294 |
ifTrue:[inStream pathName] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1295 |
ifFalse:['---']) |
4058 | 1296 |
printErrorWith:printError |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1297 |
]] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1298 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1299 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1300 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1301 |
] |
0 | 1302 |
]. |
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1303 |
^ ok |
177 | 1304 |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
1305 |
"Modified: / 31-08-1995 / 02:33:45 / claus" |
4619 | 1306 |
"Modified: / 18-09-2006 / 20:35:37 / cg" |
0 | 1307 |
! ! |
1308 |
||
4093 | 1309 |
!ResourcePack methodsFor:'printing & storing'! |
1310 |
||
1311 |
displayString |
|
1312 |
^ String |
|
1313 |
streamContents: |
|
1314 |
[:s | |
|
1315 |
s nextPutAll:'ResourcePack for: '. |
|
1316 |
packsClassName printOn:s |
|
1317 |
] |
|
1318 |
! ! |
|
1319 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
1320 |
!ResourcePack class methodsFor:'documentation'! |
251 | 1321 |
|
1322 |
version |
|
5431 | 1323 |
^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.140 2009-10-29 13:52:02 sr Exp $' |
5357 | 1324 |
! |
1325 |
||
1326 |
version_CVS |
|
5431 | 1327 |
^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.140 2009-10-29 13:52:02 sr Exp $' |
251 | 1328 |
! ! |
3769 | 1329 |
|
0 | 1330 |
ResourcePack initialize! |