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