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