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