author | Claus Gittinger <cg@exept.de> |
Wed, 20 Nov 2002 10:56:43 +0100 | |
changeset 3769 | 4b0f188d7f5c |
parent 3762 | 968432b99c48 |
child 3807 | ddb031431ff6 |
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 |
" |
|
0 | 12 |
|
3263 | 13 |
"{ Package: 'stx:libview' }" |
14 |
||
0 | 15 |
Dictionary subclass:#ResourcePack |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
16 |
instanceVariableNames:'superPack packsClassName fileReadFailed' |
308
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
17 |
classVariableNames:'Packs' |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
18 |
poolDictionaries:'' |
3484 | 19 |
category:'Interface-Internationalization' |
0 | 20 |
! |
21 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
22 |
!ResourcePack class methodsFor:'documentation'! |
46 | 23 |
|
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
72 | 27 |
All Rights Reserved |
5 | 28 |
|
46 | 29 |
This software is furnished under a license and may be used |
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
5 | 37 |
|
46 | 38 |
documentation |
39 |
" |
|
1942 | 40 |
This class supports easy customization of smalltalk code (i.e. internationalization |
41 |
and viewStyle adaption). |
|
145 | 42 |
ResourcePacks are class specific, meaning that every subclass of View |
1942 | 43 |
and ApplicationModel has an instance of ResourcePack (instVar called 'resources') |
44 |
which is created when the first instance of the view/app is created, |
|
45 |
and cached in a class-instVar (so the file is only read once). |
|
54 | 46 |
|
50 | 47 |
The resourcePack consists of a mapping from strings to values, which are |
48 |
then used in labels, buttons, menus etc. |
|
49 |
The resourcePack initializes itself from a file found in 'resources/<className>.rs', |
|
50 |
where 'className' is built by the usual abbreviation mechanism (see abbrev-files). |
|
1942 | 51 |
|
50 | 52 |
Conditional mappings are possible, by including lines as: |
3762 | 53 |
#if <expression> |
54 |
#endif |
|
50 | 55 |
in the resourcefile. Example: |
56 |
file 'foo.rs': |
|
3762 | 57 |
#if Language == #de |
58 |
'abort' 'Abbruch' |
|
59 |
#endif |
|
60 |
#if Language == #fr |
|
61 |
'abort' 'canceller' |
|
62 |
#endif |
|
145 | 63 |
|
64 |
the corresponding resource-strings are accessed (from methods within the class) |
|
65 |
using: |
|
3762 | 66 |
resources string:'abort' |
145 | 67 |
|
54 | 68 |
returning the mapped string (i.e. 'Abbruch' if the global Language is set |
3422 | 69 |
to #de).. |
145 | 70 |
|
1942 | 71 |
If no corresponding entry is found in the resources, the key is returned; |
72 |
alternatively, use: |
|
3762 | 73 |
resources string:'foo' default:'bar' |
1942 | 74 |
which returns 'bar', if no resource definition for 'foo' is found. |
75 |
||
54 | 76 |
Translations can also include arguments, such as: |
3762 | 77 |
resources string:'really delete %1' with:fileName |
145 | 78 |
|
79 |
This scheme has the advantage, that you can write your programs using your |
|
80 |
native language strings. Later, when new languages are to be supported, |
|
81 |
simply create a resource file for the class and add translations for |
|
82 |
all those strings. (find the keys by looking at users of resource or senders |
|
1942 | 83 |
of 'string:*'). |
84 |
Notice, that the grammar of different languages may imply a reordering, |
|
85 |
so the above string becomes the german 'wollen Sie %1 wirklich löschen'; |
|
86 |
so using percent-placeholders is much better than simple concatenations of |
|
87 |
arguments to the question. |
|
145 | 88 |
|
89 |
More languages can be added later without any change in the code, |
|
90 |
recompilation or the like. |
|
91 |
Even by people without access to the source code i.e. which only have the |
|
92 |
applications binary. |
|
93 |
||
94 |
Also, unsupported languages' strings are simply left unchanged - if you |
|
95 |
write your application in (say) english, and only plan to use it in english, |
|
96 |
no additional work is required (i.e you dont need a resource file then). |
|
97 |
Strings for unknown languages will come in english |
|
98 |
(which is better than nothing or empty button labels ;-) |
|
99 |
||
100 |
Summary: |
|
3762 | 101 |
in subclasses of View and ApplicationModel, |
102 |
instead of writing: |
|
145 | 103 |
|
3762 | 104 |
... |
105 |
b := Button label:'press me' |
|
106 |
... |
|
145 | 107 |
|
3762 | 108 |
always write: |
612 | 109 |
|
3762 | 110 |
... |
111 |
b := Button label:(resources string:'press me') |
|
112 |
... |
|
145 | 113 |
|
3762 | 114 |
if your class is not a subclass of one of the above, AND you need |
115 |
resource translations, you wont inherit the resources variable |
|
116 |
(which is automatically initialized). |
|
117 |
In this case, you have to ask the ResourcePack class explicitely for |
|
118 |
a corresponding package: |
|
145 | 119 |
|
3762 | 120 |
ResourcePack for:aClassName |
145 | 121 |
|
3762 | 122 |
as an example, see how the Date class gets the national names of |
123 |
week & monthnames. |
|
145 | 124 |
|
612 | 125 |
[author:] |
3762 | 126 |
Claus Gittinger |
145 | 127 |
" |
128 |
! |
|
129 |
||
130 |
examples |
|
131 |
" |
|
132 |
normally, resources are found in files named after their classes sourcefile |
|
133 |
For example, the FileBrowsers resources are found in 'FBrowser.rs'. |
|
134 |
For the examples below, we process resources from a constant string; |
|
3762 | 135 |
this is NOT representative. |
136 |
[exBegin] |
|
137 |
|stream res| |
|
145 | 138 |
|
3762 | 139 |
stream := ReadStream on:' |
145 | 140 |
foo ''the translation for foo'' |
3422 | 141 |
#if Language == #de |
145 | 142 |
bar ''die deutsche uebersetzung von bar'' |
143 |
baz ''baz hat den Wert %1'' |
|
144 |
#endif |
|
3422 | 145 |
#if Language == #fr |
145 | 146 |
bar ''bar en francaise'' |
147 |
baz ''%1, c''''est baz'' |
|
148 |
#endif |
|
149 |
||
150 |
'. |
|
151 |
||
3762 | 152 |
res := ResourcePack new readFromResourceStream:stream in:nil. |
145 | 153 |
|
3762 | 154 |
Transcript showCR:'baz is translated to: ' , (res string:'baz' with:'1234'). |
155 |
Transcript showCR:'bar is translated to: ' , (res string:'bar'). |
|
156 |
Transcript showCR:'foo is translated to: ' , (res string:'foo'). |
|
157 |
Transcript showCR:'fooBar is translated to: ' , (res string:'fooBar'). |
|
158 |
[exEnd] |
|
145 | 159 |
set the Language to french: |
3762 | 160 |
[exBegin] |
161 |
Language := #fr |
|
162 |
[exEnd] |
|
145 | 163 |
and repeat the above. |
620 | 164 |
back to english: |
3762 | 165 |
[exBegin] |
166 |
Language := #en |
|
167 |
[exEnd] |
|
620 | 168 |
back to german: |
3762 | 169 |
[exBegin] |
170 |
Language := #de |
|
171 |
[exEnd] |
|
46 | 172 |
" |
173 |
! ! |
|
5 | 174 |
|
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
175 |
!ResourcePack class methodsFor:'initialization'! |
0 | 176 |
|
72 | 177 |
flushCachedResourcePacks |
24 | 178 |
"forget all cached resources - needed after a style change" |
179 |
||
180 |
Packs := nil. |
|
181 |
self initialize |
|
182 |
||
72 | 183 |
"ResourcePack flushCachedResourcePacks" |
244 | 184 |
! |
185 |
||
186 |
initialize |
|
187 |
Packs isNil ifTrue:[ |
|
188 |
Packs := WeakArray new:30 |
|
189 |
]. |
|
190 |
||
191 |
"ResourcePack initialize" |
|
192 |
! ! |
|
193 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
194 |
!ResourcePack class methodsFor:'instance creation'! |
244 | 195 |
|
196 |
for:aClass |
|
197 |
"get the full resource definitions for aClass (i.e. with super packs). |
|
198 |
Also leave the resulting pack in the cache for faster access next time." |
|
199 |
||
3049
d5f2b3f66e37
load resources from package directory, if present
Claus Gittinger <cg@exept.de>
parents:
3047
diff
changeset
|
200 |
|nm pack superPack pkg prj prjDir baseName path| |
244 | 201 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
202 |
nm := aClass resourcePackName. |
244 | 203 |
pack := self searchCacheFor:nm. |
204 |
pack notNil ifTrue:[^ pack]. |
|
205 |
||
3049
d5f2b3f66e37
load resources from package directory, if present
Claus Gittinger <cg@exept.de>
parents:
3047
diff
changeset
|
206 |
baseName := (Smalltalk fileNameForClass:nm) , '.rs'. |
3046 | 207 |
|
3049
d5f2b3f66e37
load resources from package directory, if present
Claus Gittinger <cg@exept.de>
parents:
3047
diff
changeset
|
208 |
"/ search in the classes package directory first ... |
d5f2b3f66e37
load resources from package directory, if present
Claus Gittinger <cg@exept.de>
parents:
3047
diff
changeset
|
209 |
prjDir := Smalltalk projectDirectoryForClass:aClass. |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
210 |
|
2971 | 211 |
(prjDir notNil |
212 |
and:[(prjDir := prjDir asFilename) exists |
|
213 |
and:[(prjDir := prjDir construct:'resources') exists |
|
214 |
and:[(prjDir construct:baseName) exists]]]) ifTrue:[ |
|
3762 | 215 |
pack := self fromFile:baseName directory:prjDir pathName. |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
216 |
] ifFalse:[ |
3762 | 217 |
pack := self fromFile:baseName. |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
218 |
]. |
244 | 219 |
aClass == Object ifFalse:[ |
3762 | 220 |
pack superPack:(self for:(aClass superclass)). |
244 | 221 |
]. |
222 |
pack packsClassName:nm. |
|
223 |
self addToCache:pack. |
|
224 |
^ pack |
|
225 |
||
226 |
" |
|
3046 | 227 |
ResourcePack for:TextView |
244 | 228 |
ResourcePack for:CodeView |
3046 | 229 |
ResourcePack for:Workspace |
3049
d5f2b3f66e37
load resources from package directory, if present
Claus Gittinger <cg@exept.de>
parents:
3047
diff
changeset
|
230 |
ResourcePack for:View |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
231 |
ResourcePack for:ErrorLogger |
3101
38cc69894380
fix to avoid loosing the directory with #includes
Claus Gittinger <cg@exept.de>
parents:
3097
diff
changeset
|
232 |
ResourcePack for:NewLauncher |
244 | 233 |
Workspace classResources |
234 |
" |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
235 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
236 |
"Modified: / 29.1.1998 / 22:42:53 / cg" |
244 | 237 |
! |
238 |
||
239 |
fromFile:aFileName |
|
240 |
"get the resource definitions from a file in the default directory. |
|
241 |
Uncached low-level entry." |
|
242 |
||
243 |
^ self fromFile:aFileName directory:'resources' |
|
244 |
||
245 |
" |
|
246 |
ResourcePack fromFile:'SBrowser.rs' |
|
247 |
ResourcePack fromFile:'FBrowser.rs' |
|
248 |
ResourcePack fromFile:'Smalltalk.rs' |
|
3678 | 249 |
ResourcePack fromFile:'Smalltalk.rs' asFilename |
244 | 250 |
" |
251 |
! |
|
252 |
||
253 |
fromFile:aFileName directory:dirName |
|
254 |
"get the resource definitions from a file in a directory. |
|
255 |
Uncached low-level entry." |
|
256 |
||
257 |
|newPack| |
|
258 |
||
259 |
newPack := self new. |
|
260 |
newPack readFromFile:aFileName directory:dirName. |
|
261 |
^ newPack |
|
0 | 262 |
! ! |
263 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
264 |
!ResourcePack class methodsFor:'private'! |
54 | 265 |
|
266 |
addToCache:aPack |
|
267 |
|idx| |
|
0 | 268 |
|
54 | 269 |
idx := Packs identityIndexOf:nil. |
270 |
idx == 0 ifTrue:[ |
|
1078
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
271 |
idx := Packs identityIndexOf:0 |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
272 |
]. |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
273 |
idx == 0 ifTrue:[ |
72 | 274 |
" |
275 |
throw away oldest |
|
276 |
" |
|
277 |
idx := Packs size. |
|
278 |
Packs replaceFrom:1 to:idx-1 with:Packs startingAt:2. |
|
54 | 279 |
]. |
280 |
Packs at:idx put:aPack |
|
281 |
! |
|
0 | 282 |
|
54 | 283 |
searchCacheFor:aClassname |
998 | 284 |
|sz "{ Class: SmallInteger }" | |
0 | 285 |
|
24 | 286 |
Packs isNil ifTrue:[ |
72 | 287 |
self initialize. |
288 |
^ nil |
|
0 | 289 |
]. |
54 | 290 |
|
291 |
sz := Packs size. |
|
292 |
1 to:sz do:[:idx | |
|
72 | 293 |
|aPack| |
54 | 294 |
|
72 | 295 |
aPack := Packs at:idx. |
1078
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
296 |
(aPack notNil |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
297 |
and:[aPack ~~ 0]) ifTrue:[ |
72 | 298 |
aClassname = aPack packsClassName ifTrue:[ |
299 |
" |
|
300 |
bring to end for LRU |
|
301 |
" |
|
302 |
Packs replaceFrom:idx to:sz-1 with:Packs startingAt:idx+1. |
|
303 |
Packs at:sz put:aPack. |
|
304 |
^ aPack |
|
305 |
] |
|
306 |
] |
|
0 | 307 |
]. |
54 | 308 |
^ nil |
123 | 309 |
|
310 |
" |
|
311 |
ResourcePack searchCacheFor:'TextView' |
|
312 |
" |
|
54 | 313 |
! ! |
314 |
||
0 | 315 |
!ResourcePack methodsFor:'accessing'! |
316 |
||
244 | 317 |
array:anArray |
318 |
"translate a collection of strings" |
|
0 | 319 |
|
244 | 320 |
^ anArray collect:[:r | self at:r default:r] |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
321 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
322 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
323 |
Launcher classResources array:#('file' 'classes') |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
324 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
325 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
326 |
"Modified: / 29.1.1998 / 22:44:22 / cg" |
0 | 327 |
! |
328 |
||
2 | 329 |
at:aKey |
123 | 330 |
"translate a string" |
331 |
||
72 | 332 |
^ self at:aKey ifAbsent:aKey |
0 | 333 |
! |
334 |
||
335 |
at:aKey default:default |
|
123 | 336 |
"translate a string" |
337 |
||
72 | 338 |
^ self at:aKey ifAbsent:default |
0 | 339 |
! |
340 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
341 |
at:aKey ifAbsent:defaultValue |
123 | 342 |
"translate a string" |
343 |
||
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
344 |
|val alternativeKey| |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
345 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
346 |
aKey notNil ifTrue:[ |
3762 | 347 |
val := super at:aKey ifAbsent:nil. |
348 |
val notNil ifTrue:[^ val]. |
|
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
349 |
|
3762 | 350 |
"/ try with case-first swapped... |
351 |
(aKey isString |
|
352 |
and:[aKey size > 0 |
|
353 |
and:[aKey first isLetter]]) ifTrue:[ |
|
354 |
alternativeKey := aKey first isUppercase |
|
355 |
ifTrue:[aKey asLowercaseFirst] |
|
356 |
ifFalse:[aKey asUppercaseFirst]. |
|
357 |
val := super at:alternativeKey ifAbsent:nil. |
|
358 |
val notNil ifTrue:[ |
|
359 |
aKey first isUppercase |
|
360 |
ifTrue:[^val asUppercaseFirst]. |
|
361 |
^ val asLowercaseFirst. |
|
362 |
]. |
|
363 |
]. |
|
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
364 |
|
3762 | 365 |
superPack notNil ifTrue:[ |
366 |
^ superPack at:aKey ifAbsent:defaultValue. |
|
367 |
]. |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
368 |
]. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
369 |
^ defaultValue value |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
370 |
|
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
371 |
"Modified: / 16.11.2001 / 12:25:33 / cg" |
2 | 372 |
! |
373 |
||
374 |
name:aKey default:default |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
375 |
"translate a string. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
376 |
Obsolete - use #string:default:" |
123 | 377 |
|
72 | 378 |
^ self at:aKey ifAbsent:default |
2 | 379 |
! |
380 |
||
0 | 381 |
string:s |
3097 | 382 |
"translate (retrieve) a string - if not present, return s" |
123 | 383 |
|
72 | 384 |
^ self at:s ifAbsent:s |
3097 | 385 |
|
386 |
" |
|
387 |
NewLauncher classResources |
|
3762 | 388 |
string:'LICENCEFILE' |
3097 | 389 |
" |
0 | 390 |
! |
391 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
392 |
string:s default:defaultString |
3097 | 393 |
"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
|
394 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
395 |
^ self at:s ifAbsent:defaultString |
3097 | 396 |
|
397 |
" |
|
398 |
NewLauncher classResources |
|
3762 | 399 |
string:'fooBar' default:'Hello world' |
3097 | 400 |
" |
401 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
402 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
403 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
404 |
string:s default:defaultString with:arg |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
405 |
"translate and expand arg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
406 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
407 |
^ self string:s default:defaultString withArgs:(Array with:arg) |
3097 | 408 |
|
409 |
" |
|
410 |
NewLauncher classResources |
|
3762 | 411 |
string:'%1 fooBar' default:'Hello %1' with:'foo' |
3097 | 412 |
" |
413 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
414 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
415 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
416 |
string:s default:defaultString with:arg1 with:arg2 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
417 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
418 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
419 |
^ 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
|
420 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
421 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
422 |
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
|
423 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
424 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
425 |
^ 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
|
426 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
427 |
"Created: 9.12.1995 / 19:08:50 / cg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
428 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
429 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
430 |
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
|
431 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
432 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
433 |
^ 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
|
434 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
435 |
"Created: 9.9.1996 / 18:52:14 / cg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
436 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
437 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
438 |
string:s default:defaultString withArgs:argArray |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
439 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
440 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
441 |
|template| |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
442 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
443 |
template := self at:s ifAbsent:defaultString. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
444 |
^ template expandPlaceholdersWith:argArray |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
445 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
446 |
|
0 | 447 |
string:s with:arg |
123 | 448 |
"translate and expand arg" |
449 |
||
0 | 450 |
^ self string:s withArgs:(Array with:arg) |
451 |
! |
|
452 |
||
453 |
string:s with:arg1 with:arg2 |
|
123 | 454 |
"translate and expand args" |
455 |
||
0 | 456 |
^ self string:s withArgs:(Array with:arg1 with:arg2) |
457 |
! |
|
458 |
||
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
459 |
string:s with:arg1 with:arg2 with:arg3 |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
460 |
"translate and expand args" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
461 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
462 |
^ 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
|
463 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
464 |
"Created: 9.12.1995 / 19:08:50 / cg" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
465 |
! |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
466 |
|
1042 | 467 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 |
468 |
"translate and expand args" |
|
469 |
||
470 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
471 |
||
472 |
"Created: 9.9.1996 / 18:52:14 / cg" |
|
473 |
! |
|
474 |
||
3184 | 475 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
476 |
"translate and expand args" |
|
477 |
||
478 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
479 |
||
480 |
! |
|
481 |
||
0 | 482 |
string:s withArgs:argArray |
123 | 483 |
"translate and expand args" |
484 |
||
135 | 485 |
|template| |
0 | 486 |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
487 |
template := self at:s ifAbsent:s. |
135 | 488 |
^ template expandPlaceholdersWith:argArray |
0 | 489 |
! ! |
490 |
||
3317 | 491 |
!ResourcePack methodsFor:'accessing-internals'! |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
492 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
493 |
name:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
494 |
"translate a string" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
495 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
496 |
^ self at:aKey ifAbsent:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
497 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
498 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
499 |
packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
500 |
^ packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
501 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
502 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
503 |
packsClassName:aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
504 |
packsClassName := aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
505 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
506 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
507 |
superPack:anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
508 |
superPack := anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
509 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
510 |
"Created: / 29.1.1998 / 22:43:09 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
511 |
! ! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
512 |
|
0 | 513 |
!ResourcePack methodsFor:'file reading'! |
514 |
||
684 | 515 |
fileReadFailed |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
516 |
"return true, if the pack does not really contain |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
517 |
valid translations, since the fileRead failed. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
518 |
However, all inherited translations are still available |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
519 |
through the receiver" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
520 |
|
687 | 521 |
^ fileReadFailed ~~ false |
684 | 522 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
523 |
"Created: / 14.5.1996 / 10:19:26 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
524 |
"Modified: / 29.1.1998 / 22:46:38 / cg" |
684 | 525 |
! |
526 |
||
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
527 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
528 |
"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
|
529 |
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
|
530 |
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
|
531 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
532 |
^ nil |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
533 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
534 |
"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
|
535 |
! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
536 |
|
2291
eaac1c5f2a61
show fileName if a line has error.
Claus Gittinger <cg@exept.de>
parents:
2153
diff
changeset
|
537 |
processLine:aLine encoding:encoding file:fileName |
145 | 538 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
539 |
||
2314 | 540 |
|lineString name stream l rest macroName value |
541 |
conditional hasError| |
|
144 | 542 |
|
145 | 543 |
lineString := aLine withoutSeparators. |
144 | 544 |
name := nil. |
545 |
(lineString at:1) == $' ifTrue:[ |
|
3762 | 546 |
stream := ReadStream on:lineString. |
547 |
stream signalAtEnd:false. |
|
548 |
name := String |
|
549 |
readFrom:stream |
|
550 |
onError:[('ResourcePack [warning]: invalid line <' |
|
551 |
,lineString |
|
552 |
,'> in file:' |
|
553 |
, fileName |
|
554 |
) errorPrintCR. nil]. |
|
158 | 555 |
"/ OLD: l := stream position |
3762 | 556 |
l := stream position + 1. |
144 | 557 |
|
558 |
"/ l := lineString indexOf:$' startingAt:2. |
|
559 |
"/ l ~~ 0 ifTrue:[ |
|
560 |
"/ name := (lineString copyFrom:2 to:l-1). |
|
561 |
"/ l := l + 1 |
|
562 |
"/ ] |
|
563 |
] ifFalse:[ |
|
3762 | 564 |
l := lineString indexOfSeparatorStartingAt:1. |
565 |
l ~~ 0 ifTrue:[ |
|
566 |
name := lineString copyFrom:1 to:l-1. |
|
567 |
] |
|
144 | 568 |
]. |
569 |
name notNil ifTrue:[ |
|
3762 | 570 |
hasError := false. |
2153 | 571 |
|
3762 | 572 |
rest := (lineString copyFrom:l) withoutSeparators. |
573 |
" |
|
574 |
skip <type> if present |
|
575 |
" |
|
576 |
(rest startsWith:$<) ifTrue:[ |
|
577 |
l := lineString indexOf:$> startingAt:l. |
|
578 |
rest := (lineString copyFrom:l+1) withoutSeparators. |
|
579 |
]. |
|
2153 | 580 |
|
3762 | 581 |
conditional := false. |
582 |
(rest startsWith:$?) ifTrue:[ |
|
583 |
rest := (rest copyFrom:2) withoutSeparators. |
|
584 |
conditional := true. |
|
585 |
]. |
|
2153 | 586 |
|
3762 | 587 |
(rest startsWith:$=) ifTrue:[ |
588 |
rest := rest copyFrom:2. |
|
589 |
stream := ReadStream on:rest. |
|
590 |
macroName := stream nextAlphaNumericWord. |
|
591 |
[stream peek == $.] whileTrue:[ |
|
592 |
stream next. |
|
593 |
stream peek notNil ifTrue:[ |
|
594 |
macroName := macroName , '.' , (stream nextAlphaNumericWord) |
|
595 |
] |
|
596 |
]. |
|
597 |
rest := stream upToEnd. |
|
598 |
value := self at:macroName ifAbsent:nil. |
|
599 |
(value isNil) ifTrue:[ |
|
600 |
hasError := true. |
|
601 |
('ResourcePack [warning]: bad (nil-valued) macro: ' , macroName) errorPrintCR. |
|
602 |
('ResourcePack [warning]: in line: ' , lineString) errorPrintCR. |
|
603 |
('ResourcePack [warning]: in file: ' , fileName) errorPrintCR. |
|
604 |
]. |
|
605 |
value isBlock ifTrue:[ |
|
606 |
value := value value |
|
607 |
]. |
|
608 |
value := Compiler evaluate:('self ' , rest) |
|
609 |
receiver:value |
|
610 |
notifying:nil |
|
611 |
compile:false. |
|
612 |
(value == #Error) ifTrue:[ |
|
613 |
hasError := true. |
|
614 |
('ResourcePack [warning]: error in line: "self ' , rest , '"') errorPrintCR. |
|
615 |
('ResourcePack [warning]: in file: ' , fileName) errorPrintCR. |
|
616 |
] |
|
617 |
] ifFalse:[ |
|
618 |
value := Compiler evaluate:rest compile:false. |
|
619 |
(value == #Error) ifTrue:[ |
|
620 |
hasError := true. |
|
621 |
('ResourcePack [warning]: error in line: "' , rest , '"') errorPrintCR. |
|
622 |
('ResourcePack [warning]: in file: ' , fileName) errorPrintCR. |
|
623 |
] ifFalse:[ |
|
624 |
encoding notNil ifTrue:[ |
|
625 |
value isString ifTrue:[ |
|
626 |
value := value decodeFrom:encoding |
|
627 |
] |
|
628 |
] |
|
629 |
] |
|
630 |
]. |
|
631 |
hasError ifFalse:[ |
|
632 |
(conditional not |
|
633 |
or:[(self includesKey:name) not]) ifTrue:[ |
|
634 |
self at:name put:value. |
|
635 |
] |
|
636 |
] |
|
144 | 637 |
] |
462
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
638 |
|
2291
eaac1c5f2a61
show fileName if a line has error.
Claus Gittinger <cg@exept.de>
parents:
2153
diff
changeset
|
639 |
"Created: / 30.8.1998 / 12:35:37 / cg" |
2608 | 640 |
"Modified: / 28.4.1999 / 22:23:14 / cg" |
144 | 641 |
! |
642 |
||
244 | 643 |
readFromFile:fileName directory:dirName |
644 |
"read definitions from a file in a directory" |
|
645 |
||
646 |
|inStream ok| |
|
647 |
||
686 | 648 |
fileReadFailed := false. |
244 | 649 |
dirName = 'resources' ifTrue:[ |
3769 | 650 |
inStream := Smalltalk resourceFileStreamFor:fileName |
244 | 651 |
] ifFalse:[ |
3769 | 652 |
inStream := Smalltalk |
653 |
systemFileStreamFor:(dirName |
|
654 |
isNil ifTrue:[fileName] |
|
655 |
ifFalse:[dirName asFilename construct:fileName]). |
|
244 | 656 |
]. |
657 |
inStream isNil ifTrue:[ |
|
3769 | 658 |
" |
659 |
an empty pack |
|
660 |
" |
|
661 |
^ self nonexistingFileRead |
|
244 | 662 |
]. |
2996 | 663 |
|
244 | 664 |
ok := self readFromResourceStream:inStream in:dirName. |
665 |
inStream close. |
|
686 | 666 |
|
244 | 667 |
ok ifFalse:[ |
3769 | 668 |
fileReadFailed := true. |
684 | 669 |
|
3769 | 670 |
('ResourcePack [warning]: ''' , inStream pathName , ''' contains error(s) - data may be incomplete.') errorPrintCR. |
244 | 671 |
]. |
672 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
673 |
"Modified: 10.1.1997 / 18:05:17 / cg" |
244 | 674 |
! |
675 |
||
72 | 676 |
readFromResourceStream:inStream in:dirName |
145 | 677 |
"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
|
678 |
specify where #include files are searched for. |
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
679 |
Return true, if the style sheet could be read without errors, false otherwise." |
145 | 680 |
|
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
681 |
|lineString l lNo rest value ifLevel skipping first ok encoding pack errorHandler| |
462
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
682 |
|
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
683 |
encoding := nil. |
0 | 684 |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
685 |
ok := true. |
0 | 686 |
ifLevel := 0. |
687 |
skipping := false. |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
688 |
lNo := 0. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
689 |
|
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
690 |
errorHandler := [:ex | |
3762 | 691 |
|con| |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
692 |
|
3762 | 693 |
('ResourcePack [warning]: ''' , ex errorString , '''') errorPrintCR. |
694 |
('ResourcePack [info]: file: ' , inStream pathName printString , ' line: ' , lNo printString , ': ''' , lineString , '''') errorPrintCR. |
|
695 |
con := ex suspendedContext. |
|
696 |
('ResourcePack [info]: in: ' , con fullPrintString) errorPrintCR. |
|
697 |
con := con sender. |
|
698 |
('ResourcePack [info]: : ' , con fullPrintString) errorPrintCR. |
|
699 |
con := con sender. |
|
700 |
('ResourcePack [info]: : ' , con fullPrintString) errorPrintCR. |
|
701 |
value := nil. |
|
702 |
ok := false. |
|
703 |
]. |
|
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
704 |
|
0 | 705 |
[inStream atEnd] whileFalse:[ |
3762 | 706 |
lineString := inStream nextLine. lNo := lNo + 1. |
707 |
[lineString notNil and:[lineString endsWith:$\]] whileTrue:[ |
|
708 |
lineString := lineString copyWithoutLast:1. |
|
709 |
l := inStream nextLine. lNo := lNo + 1. |
|
710 |
l notNil ifTrue:[ |
|
711 |
lineString := lineString , l. |
|
712 |
]. |
|
713 |
]. |
|
177 | 714 |
|
3762 | 715 |
(lineString size > 0) ifTrue:[ |
716 |
first := lineString at:1. |
|
717 |
"/ |
|
718 |
"/ for your convenience: treat ; AND "/ as comment-line |
|
719 |
"/ |
|
720 |
((first == $;) or:[lineString startsWith:'"/']) ifFalse:[ |
|
721 |
first == $# ifTrue:[ |
|
722 |
"/ a directive |
|
723 |
lineString := (lineString copyFrom:2) withoutSpaces. |
|
72 | 724 |
|
3762 | 725 |
(lineString startsWith:'if') ifTrue:[ |
726 |
skipping ifFalse:[ |
|
727 |
rest := lineString copyFrom:3. |
|
728 |
ErrorSignal |
|
729 |
handle:errorHandler |
|
730 |
do:[ |
|
731 |
value := Compiler evaluate:rest compile:false]. |
|
732 |
(value == #Error) ifTrue:[ |
|
733 |
('ResourcePack [warning]: error in resource:' , lineString) errorPrintCR. |
|
734 |
]. |
|
735 |
(value == false) ifTrue:[ |
|
736 |
skipping := true |
|
737 |
] |
|
738 |
]. |
|
739 |
ifLevel := ifLevel + 1 |
|
740 |
] ifFalse:[ |
|
741 |
(lineString startsWith:'endif') ifTrue:[ |
|
742 |
ifLevel := ifLevel - 1. |
|
743 |
ifLevel == 0 ifTrue:[ |
|
744 |
skipping := false |
|
745 |
] |
|
746 |
] ifFalse:[ |
|
747 |
(lineString startsWith:'else') ifTrue:[ |
|
748 |
skipping := skipping not |
|
749 |
] ifFalse:[ |
|
750 |
skipping ifFalse:[ |
|
751 |
(lineString startsWith:'include') ifTrue:[ |
|
752 |
(lineString startsWith:'includeResourcesFor') ifTrue:[ |
|
753 |
"/ include those resources ... |
|
754 |
rest := lineString copyFrom:('includeResourcesFor' size + 1). |
|
755 |
value := Compiler evaluate:rest compile:false. |
|
756 |
value isBehavior ifTrue:[ |
|
757 |
pack := self class for:value. |
|
758 |
pack notNil ifTrue:[ |
|
759 |
self declareAllFrom:pack. |
|
760 |
] |
|
761 |
] |
|
762 |
] ifFalse:[ |
|
763 |
rest := lineString copyFrom:('include' size + 1). |
|
764 |
value := Compiler evaluate:rest compile:false. |
|
765 |
value isString ifFalse:[ |
|
766 |
('ResourcePack [warning]: bad include filename: ' , value printString) errorPrintCR. |
|
767 |
('ResourcePack [info]: line ' , lNo printString , ': ''' , lineString , '''') infoPrintCR. |
|
768 |
] ifTrue:[ |
|
769 |
self readFromFile:value directory:dirName |
|
770 |
] |
|
771 |
] |
|
772 |
] ifFalse:[ |
|
773 |
(lineString startsWith:'encoding') ifTrue:[ |
|
774 |
rest := lineString copyFrom:9. |
|
775 |
encoding := rest withoutSeparators asSymbol |
|
776 |
] |
|
777 |
] |
|
778 |
] |
|
779 |
] |
|
780 |
] |
|
781 |
]. |
|
782 |
] ifFalse:[ |
|
783 |
skipping ifFalse:[ |
|
784 |
ErrorSignal |
|
785 |
handle:errorHandler |
|
786 |
do:[ |
|
787 |
(lineString at:1) == $!! ifTrue:[ |
|
788 |
"/ evaluate the rest |
|
789 |
Compiler evaluate:(lineString copyFrom:2) |
|
790 |
receiver:nil |
|
791 |
notifying:nil |
|
792 |
compile:false. |
|
793 |
] ifFalse:[ |
|
794 |
"/ process as resource |
|
795 |
self |
|
796 |
processLine:lineString |
|
797 |
encoding:encoding |
|
798 |
file:(inStream isFileStream |
|
799 |
ifTrue:[inStream pathName] |
|
800 |
ifFalse:['---']) |
|
801 |
]] |
|
802 |
] |
|
803 |
] |
|
804 |
] |
|
805 |
] |
|
0 | 806 |
]. |
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
807 |
^ ok |
177 | 808 |
|
2291
eaac1c5f2a61
show fileName if a line has error.
Claus Gittinger <cg@exept.de>
parents:
2153
diff
changeset
|
809 |
"Modified: / 31.8.1995 / 02:33:45 / claus" |
eaac1c5f2a61
show fileName if a line has error.
Claus Gittinger <cg@exept.de>
parents:
2153
diff
changeset
|
810 |
"Modified: / 30.8.1998 / 12:35:24 / cg" |
0 | 811 |
! ! |
812 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
813 |
!ResourcePack class methodsFor:'documentation'! |
251 | 814 |
|
815 |
version |
|
3769 | 816 |
^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.74 2002-11-20 09:56:43 cg Exp $' |
251 | 817 |
! ! |
3769 | 818 |
|
0 | 819 |
ResourcePack initialize! |