author | Stefan Vogel <sv@exept.de> |
Tue, 16 Oct 2018 17:14:14 +0200 | |
changeset 8522 | 66f1c511b061 |
parent 8520 | ca6931598931 |
child 8537 | 8bd2123b96c6 |
permissions | -rw-r--r-- |
8445 | 1 |
"{ Encoding: utf8 }" |
2 |
||
5 | 3 |
" |
4 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
8462 | 5 |
All Rights Reserved |
5 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
3263 | 14 |
"{ Package: 'stx:libview' }" |
15 |
||
6767 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
0 | 18 |
Dictionary subclass:#ResourcePack |
8470 | 19 |
instanceVariableNames:'packsClassName packsFileName fileReadFailed superPack projectPack |
8510 | 20 |
usedKeys cache superPacks' |
21 |
classVariableNames:'DebugModifications FailedToLoadPacks KeepStatisticsOnUsedKeys |
|
22 |
Packs' |
|
8470 | 23 |
poolDictionaries:'' |
24 |
category:'Interface-Internationalization' |
|
0 | 25 |
! |
26 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
27 |
!ResourcePack class methodsFor:'documentation'! |
46 | 28 |
|
29 |
copyright |
|
30 |
" |
|
31 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
8462 | 32 |
All Rights Reserved |
5 | 33 |
|
46 | 34 |
This software is furnished under a license and may be used |
35 |
only in accordance with the terms of that license and with the |
|
36 |
inclusion of the above copyright notice. This software may not |
|
37 |
be provided or otherwise made available to, or used by, any |
|
38 |
other person. No title to or ownership of the software is |
|
39 |
hereby transferred. |
|
40 |
" |
|
41 |
! |
|
5 | 42 |
|
46 | 43 |
documentation |
44 |
" |
|
1942 | 45 |
This class supports easy customization of smalltalk code (i.e. internationalization |
46 |
and viewStyle adaption). |
|
145 | 47 |
ResourcePacks are class specific, meaning that every subclass of View |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
48 |
and ApplicationModel has an instance of ResourcePack (instVar called 'resources') |
1942 | 49 |
which is created when the first instance of the view/app is created, |
50 |
and cached in a class-instVar (so the file is only read once). |
|
54 | 51 |
|
50 | 52 |
The resourcePack consists of a mapping from strings to values, which are |
53 |
then used in labels, buttons, menus etc. |
|
54 |
The resourcePack initializes itself from a file found in 'resources/<className>.rs', |
|
55 |
where 'className' is built by the usual abbreviation mechanism (see abbrev-files). |
|
1942 | 56 |
|
50 | 57 |
Conditional mappings are possible, by including lines as: |
7649 | 58 |
#if <expression> |
59 |
#endif |
|
50 | 60 |
in the resourcefile. Example: |
61 |
file 'foo.rs': |
|
7649 | 62 |
#if Language == #de |
63 |
'abort' 'Abbruch' |
|
64 |
#endif |
|
65 |
#if Language == #fr |
|
66 |
'abort' 'canceller' |
|
67 |
#endif |
|
145 | 68 |
|
69 |
the corresponding resource-strings are accessed (from methods within the class) |
|
70 |
using: |
|
7649 | 71 |
resources string:'abort' |
145 | 72 |
|
54 | 73 |
returning the mapped string (i.e. 'Abbruch' if the global Language is set |
3422 | 74 |
to #de).. |
145 | 75 |
|
1942 | 76 |
If no corresponding entry is found in the resources, the key is returned; |
77 |
alternatively, use: |
|
7649 | 78 |
resources string:'foo' default:'bar' |
1942 | 79 |
which returns 'bar', if no resource definition for 'foo' is found. |
80 |
||
54 | 81 |
Translations can also include arguments, such as: |
7649 | 82 |
resources string:'really delete %1' with:fileName |
145 | 83 |
|
84 |
This scheme has the advantage, that you can write your programs using your |
|
85 |
native language strings. Later, when new languages are to be supported, |
|
86 |
simply create a resource file for the class and add translations for |
|
87 |
all those strings. (find the keys by looking at users of resource or senders |
|
1942 | 88 |
of 'string:*'). |
89 |
Notice, that the grammar of different languages may imply a reordering, |
|
8445 | 90 |
so the above string becomes the german 'wollen Sie %1 wirklich löschen'; |
1942 | 91 |
so using percent-placeholders is much better than simple concatenations of |
92 |
arguments to the question. |
|
145 | 93 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
94 |
More languages can be added later without any change in the code, or recompilation |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
95 |
or the like. Even by people without access to the source code (i.e. which only have the |
8428 | 96 |
application's binary). |
145 | 97 |
|
98 |
Also, unsupported languages' strings are simply left unchanged - if you |
|
99 |
write your application in (say) english, and only plan to use it in english, |
|
5653 | 100 |
no additional work is required (i.e you don't even need a resource file then). |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
101 |
Strings for unknown languages will come in english |
145 | 102 |
(which is better than nothing or empty button labels ;-) |
103 |
||
7649 | 104 |
Notice, that you can also translate english to english, by providing an en.rs file. |
5653 | 105 |
This is sometimes useful to fix typing errors or bad syntax in the english, |
106 |
as sometimes made by the programmer, without a need to recompile or to also adjust other |
|
107 |
language translations. |
|
108 |
||
109 |
Finally, this scheme is also compatible to a pure enum-key based translation mechanism, |
|
110 |
as typically used in the C-world. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
111 |
Simple use keys as argument, and provide translations for all languages (incl. english). |
5653 | 112 |
For example: |
7649 | 113 |
Button label:(resources string:#BTN_FOO_LABEL) |
5653 | 114 |
|
115 |
||
145 | 116 |
Summary: |
7649 | 117 |
in subclasses of View and ApplicationModel, instead of writing: |
145 | 118 |
|
7649 | 119 |
... |
120 |
b := Button label:'press me' |
|
121 |
... |
|
145 | 122 |
|
7649 | 123 |
always write: |
612 | 124 |
|
7649 | 125 |
... |
126 |
b := Button label:(resources string:'press me') |
|
127 |
... |
|
145 | 128 |
|
7649 | 129 |
if your class is not a subclass of one of the above, AND you need |
130 |
resource translations, you won't inherit the resources variable |
|
131 |
(which is automatically initialized). |
|
132 |
In this case, you have to ask the ResourcePack class explicitely for |
|
133 |
a corresponding package: |
|
5483 | 134 |
|
7649 | 135 |
ResourcePack for:aClassName |
136 |
or (even better): |
|
137 |
ResourcePack forPackage:aPackageID |
|
145 | 138 |
|
7649 | 139 |
as an example, see how the Date class gets the national names of |
140 |
week & monthnames. |
|
145 | 141 |
|
5483 | 142 |
Debugging: |
7649 | 143 |
in the past, it happened that strings as returned by me were modified by someone else |
144 |
(replaceAll:with:) and then lead to invalid presentation in the future. |
|
145 |
To detect any bad guy which writes into one of my returned strings, set the DebugModifications |
|
146 |
classVar to true. Then I will return ImmutableStrings which trap on writes. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
147 |
|
612 | 148 |
[author:] |
7649 | 149 |
Claus Gittinger |
145 | 150 |
" |
151 |
! |
|
152 |
||
153 |
examples |
|
154 |
" |
|
155 |
normally, resources are found in files named after their classes sourcefile |
|
156 |
For example, the FileBrowsers resources are found in 'FBrowser.rs'. |
|
157 |
For the examples below, we process resources from a constant string; |
|
8462 | 158 |
this is NOT representative. |
159 |
[exBegin] |
|
160 |
|stream res| |
|
145 | 161 |
|
8462 | 162 |
stream := ReadStream on:' |
145 | 163 |
foo ''the translation for foo'' |
3422 | 164 |
#if Language == #de |
145 | 165 |
bar ''die deutsche uebersetzung von bar'' |
166 |
baz ''baz hat den Wert %1'' |
|
167 |
#endif |
|
3422 | 168 |
#if Language == #fr |
145 | 169 |
bar ''bar en francaise'' |
170 |
baz ''%1, c''''est baz'' |
|
171 |
#endif |
|
172 |
||
173 |
'. |
|
174 |
||
8462 | 175 |
res := ResourcePack new readFromResourceStream:stream in:nil. |
145 | 176 |
|
8462 | 177 |
Transcript showCR:'baz is translated to: ' , (res string:'baz' with:'1234'). |
178 |
Transcript showCR:'bar is translated to: ' , (res string:'bar'). |
|
179 |
Transcript showCR:'foo is translated to: ' , (res string:'foo'). |
|
180 |
Transcript showCR:'fooBar is translated to: ' , (res string:'fooBar'). |
|
181 |
[exEnd] |
|
145 | 182 |
set the Language to french: |
8462 | 183 |
[exBegin] |
184 |
Language := #fr |
|
185 |
[exEnd] |
|
145 | 186 |
and repeat the above. |
620 | 187 |
back to english: |
8462 | 188 |
[exBegin] |
189 |
Language := #en |
|
190 |
[exEnd] |
|
620 | 191 |
back to german: |
8462 | 192 |
[exBegin] |
193 |
Language := #de |
|
194 |
[exEnd] |
|
46 | 195 |
" |
196 |
! ! |
|
5 | 197 |
|
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
198 |
!ResourcePack class methodsFor:'initialization'! |
0 | 199 |
|
72 | 200 |
flushCachedResourcePacks |
24 | 201 |
"forget all cached resources - needed after a style change" |
202 |
||
8509 | 203 |
Packs := FailedToLoadPacks := nil. |
24 | 204 |
self initialize |
205 |
||
4093 | 206 |
" |
207 |
ResourcePack flushCachedResourcePacks |
|
208 |
" |
|
244 | 209 |
! |
210 |
||
211 |
initialize |
|
212 |
Packs isNil ifTrue:[ |
|
8510 | 213 |
Packs := WeakArray new:50. |
8462 | 214 |
FailedToLoadPacks := Set new. |
244 | 215 |
]. |
216 |
||
4093 | 217 |
" |
218 |
ResourcePack initialize |
|
8510 | 219 |
ResourcePack flushCachedResourcePacks. |
220 |
ApplicationModel flushAllClassResources. |
|
221 |
SimpleView flushAllClassResources. |
|
222 |
||
223 |
SimpleView classResources |
|
4093 | 224 |
" |
4623 | 225 |
|
5826
c4ed474970c1
forPackage:resourceFileName:cached:
Claus Gittinger <cg@exept.de>
parents:
5781
diff
changeset
|
226 |
"Modified: / 28-09-2011 / 15:53:21 / cg" |
244 | 227 |
! ! |
228 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
229 |
!ResourcePack class methodsFor:'instance creation'! |
244 | 230 |
|
8520 | 231 |
addAdditionalSuperPacksForPackage:packageID to:resourcePack |
232 |
|prjDefinition| |
|
8517 | 233 |
|
8520 | 234 |
prjDefinition := ProjectDefinition definitionClassForPackage:packageID. |
235 |
prjDefinition notNil ifTrue:[ |
|
236 |
(prjDefinition additionalClassResources ? #()) do:[:each | |
|
237 |
resourcePack addSuperPack:each |
|
238 |
] |
|
8517 | 239 |
]. |
240 |
! |
|
241 |
||
244 | 242 |
for:aClass |
243 |
"get the full resource definitions for aClass (i.e. with super packs). |
|
244 |
Also leave the resulting pack in the cache for faster access next time." |
|
245 |
||
4619 | 246 |
^ self for:aClass cached:false |
4030 | 247 |
|
248 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
249 |
ResourcePack for:TextView |
4030 | 250 |
ResourcePack for:CodeView |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
251 |
ResourcePack for:Workspace |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
252 |
ResourcePack for:View |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
253 |
ResourcePack for:ErrorLogger |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
254 |
ResourcePack for:NewLauncher |
6799 | 255 |
ResourcePack for:SmallSense::SettingsAppl |
4030 | 256 |
Workspace classResources |
257 |
" |
|
4619 | 258 |
|
259 |
"Modified: / 18-09-2006 / 19:02:57 / cg" |
|
4030 | 260 |
! |
261 |
||
262 |
for:aClass cached:cached |
|
263 |
"get the full resource definitions for aClass (i.e. with super packs). |
|
264 |
Also leave the resulting pack in the cache for faster access next time." |
|
265 |
||
8522 | 266 |
^ self forPackage:(aClass package) cached:cached. |
8520 | 267 |
|
8510 | 268 |
"/ |nm pack rsrcDir baseName| |
269 |
"/ |
|
270 |
"/ nm := aClass resourcePackName. |
|
271 |
"/ cached ifTrue:[ |
|
272 |
"/ pack := self searchCacheFor:nm. |
|
273 |
"/ pack notNil ifTrue:[^ pack]. |
|
274 |
"/ ]. |
|
275 |
"/ |
|
276 |
"/ baseName := (Smalltalk fileNameForClass:nm) , '.rs'. |
|
277 |
"/ rsrcDir := aClass resourceDirectory. |
|
278 |
"/ |
|
279 |
"/"/ CHECK this |
|
280 |
"/"/ (rsrcDir notNil and:[rsrcDir suffix = 'rs']) ifTrue:[ |
|
281 |
"/"/ baseName := (Smalltalk fileNameForClass: rsrcDir tail asFilename withoutSuffix pathName),'.rs'. |
|
282 |
"/"/ rsrcDir := rsrcDir head asFilename. |
|
283 |
"/"/ ]. |
|
284 |
"/ |
|
285 |
"/ rsrcDir notNil ifTrue:[ |
|
286 |
"/ pack := self new. |
|
287 |
"/ rsrcDir exists ifTrue:[ |
|
288 |
"/ (rsrcDir construct:baseName) exists ifTrue:[ |
|
289 |
"/ pack := self fromFile:baseName directory:(rsrcDir name) cached:cached. |
|
290 |
"/ ]. |
|
291 |
"/ ] |
|
292 |
"/ ] ifFalse:[ |
|
293 |
"/ pack := self fromFile:baseName directory:'resources' cached:cached. |
|
294 |
"/ ]. |
|
295 |
"/ aClass superclass notNil ifTrue:[ |
|
296 |
"/ pack superPack:(self for:(aClass superclass) cached:cached). |
|
297 |
"/ ]. |
|
298 |
"/ pack packsClassOrFileName:nm. |
|
299 |
"/ cached ifTrue:[ |
|
300 |
"/ self addToCache:pack. |
|
301 |
"/ ]. |
|
302 |
"/ pack projectPack:(self forPackage:(aClass resourcePackage) cached:cached). |
|
303 |
"/ ^ pack |
|
244 | 304 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
305 |
" |
4656 | 306 |
ResourcePack forPackage:'bosch:dapasx' cached:true |
307 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
308 |
ResourcePack for:TextView |
244 | 309 |
ResourcePack for:CodeView |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
310 |
ResourcePack for:Workspace |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
311 |
ResourcePack for:View |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
312 |
ResourcePack for:ErrorLogger |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
313 |
ResourcePack for:NewLauncher |
244 | 314 |
Workspace classResources |
315 |
" |
|
4617 | 316 |
|
5642
494cea2296dc
comment/format in: #for:cached:
Claus Gittinger <cg@exept.de>
parents:
5603
diff
changeset
|
317 |
"Modified: / 01-11-2010 / 09:09:43 / cg" |
8522 | 318 |
"Modified: / 16-10-2018 / 17:12:25 / Stefan Vogel" |
244 | 319 |
! |
320 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
321 |
forPackage:package |
4078 | 322 |
"get the full resource definitions given a package id (such as stx:libbasic'). |
323 |
Also leave the resulting pack in the cache for faster access next time." |
|
324 |
||
325 |
^ self forPackage:package cached:true |
|
326 |
||
327 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
328 |
ResourcePack forPackage:'stx:libbasic' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
329 |
ResourcePack forPackage:'stx:libtool' |
8509 | 330 |
ResourcePack forPackage:'stx:libView' |
4078 | 331 |
" |
4618 | 332 |
|
333 |
"Modified: / 18-09-2006 / 18:45:31 / cg" |
|
4078 | 334 |
! |
335 |
||
336 |
forPackage:package cached:cached |
|
337 |
"get the full resource definitions given a package id (such as stx:libbasic'). |
|
338 |
Also optionally leave the resulting pack in the cache for faster access next time." |
|
339 |
||
4673 | 340 |
^ self forPackage:package resourceFileName:'resources.rs' cached:cached |
341 |
||
342 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
343 |
ResourcePack forPackage:'stx:libbasic' cached:false |
4673 | 344 |
" |
345 |
||
346 |
"Modified: / 19-10-2006 / 23:18:28 / cg" |
|
347 |
! |
|
348 |
||
349 |
forPackage:package resourceFileName:resourceFileName cached:cached |
|
350 |
"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
|
351 |
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
|
352 |
Remember failed packs, to avoid retrying reading the file again and again" |
4673 | 353 |
|
4428 | 354 |
|fullName pack rsrcDir file| |
4078 | 355 |
|
8517 | 356 |
package isNil ifTrue:[ |
357 |
'[ResourcePack] warning: nil package asking for resource file'. |
|
8520 | 358 |
^ self newDefaultResourcePack |
8517 | 359 |
]. |
360 |
||
8510 | 361 |
fullName := (package copyReplaceAll:$: with:$/),'/resources/',resourceFileName. |
4078 | 362 |
|
363 |
cached ifTrue:[ |
|
8462 | 364 |
pack := self searchCacheFor:fullName. |
365 |
pack notNil ifTrue:[^ pack]. |
|
8520 | 366 |
|
8517 | 367 |
(FailedToLoadPacks includes:fullName) ifTrue:[ |
8520 | 368 |
"/ it already failed to load - do not try again |
369 |
pack := self newDefaultResourcePack. |
|
370 |
self addAdditionalSuperPacksForPackage:package to:pack. |
|
371 |
^ pack |
|
8517 | 372 |
]. |
4078 | 373 |
]. |
374 |
||
8510 | 375 |
"/ Smalltalk projectDirectoryForPackage:'stx:libview' |
4078 | 376 |
rsrcDir := Smalltalk projectDirectoryForPackage:package. |
8514 | 377 |
"/ '1) projectDirectoryForPackage -> ' print. |
378 |
"/ rsrcDir printCR. |
|
8517 | 379 |
rsrcDir notNil ifTrue:[ |
380 |
rsrcDir := rsrcDir asFilename / 'resources'. |
|
8514 | 381 |
"/ '3) rsrcDir -> ' print. |
382 |
"/ rsrcDir printCR. |
|
8517 | 383 |
rsrcDir exists ifTrue:[ |
384 |
pack := self fromFile:resourceFileName directory:rsrcDir cached:cached. |
|
385 |
pack packsPackage:package. |
|
8520 | 386 |
self addAdditionalSuperPacksForPackage:package to:pack. |
8517 | 387 |
^ pack |
8462 | 388 |
]. |
8517 | 389 |
]. |
390 |
||
391 |
file := Smalltalk getResourceFileName:resourceFileName forPackage:package. |
|
8519 | 392 |
(file notNil and:[(file := file asFilename) exists]) ifTrue:[ |
393 |
rsrcDir := file directory. |
|
8517 | 394 |
pack := self fromFile:resourceFileName directory:rsrcDir cached:cached. |
395 |
pack packsPackage:package. |
|
8520 | 396 |
self addAdditionalSuperPacksForPackage:package to:pack. |
8517 | 397 |
^ pack |
4428 | 398 |
]. |
8517 | 399 |
|
400 |
FailedToLoadPacks add:fullName. |
|
8520 | 401 |
pack := self newDefaultResourcePack. |
402 |
self addAdditionalSuperPacksForPackage:package to:pack. |
|
403 |
^ pack |
|
4078 | 404 |
|
405 |
" |
|
8517 | 406 |
ResourcePack flushCachedResourcePacks. |
407 |
||
8510 | 408 |
ResourcePack |
409 |
forPackage:'stx:libbasic' |
|
410 |
resourceFileName:'resources.rs' |
|
411 |
cached:false |
|
4078 | 412 |
" |
4656 | 413 |
|
5826
c4ed474970c1
forPackage:resourceFileName:cached:
Claus Gittinger <cg@exept.de>
parents:
5781
diff
changeset
|
414 |
"Modified: / 28-09-2011 / 15:55:30 / cg" |
8470 | 415 |
"Modified: / 17-09-2018 / 12:55:54 / Claus Gittinger" |
4078 | 416 |
! |
417 |
||
244 | 418 |
fromFile:aFileName |
4611 | 419 |
"get the resource definitions from a file in the default directory." |
244 | 420 |
|
421 |
^ self fromFile:aFileName directory:'resources' |
|
422 |
||
423 |
" |
|
424 |
ResourcePack fromFile:'SBrowser.rs' |
|
425 |
ResourcePack fromFile:'FBrowser.rs' |
|
426 |
ResourcePack fromFile:'Smalltalk.rs' |
|
3678 | 427 |
ResourcePack fromFile:'Smalltalk.rs' asFilename |
3983 | 428 |
ResourcePack fromFile:'../../libtool/resources/AboutBox_ru.rs' asFilename |
244 | 429 |
" |
430 |
! |
|
431 |
||
432 |
fromFile:aFileName directory:dirName |
|
4611 | 433 |
"get the resource definitions from a file in a directory." |
434 |
||
435 |
^ self fromFile:aFileName directory:dirName cached:false |
|
436 |
! |
|
437 |
||
438 |
fromFile:aFileName directory:dirName cached:cached |
|
244 | 439 |
"get the resource definitions from a file in a directory. |
440 |
Uncached low-level entry." |
|
441 |
||
8483 | 442 |
|cachedPack newPack fn| |
244 | 443 |
|
8483 | 444 |
fn := (dirName asFilename / aFileName) pathName. |
445 |
cachedPack := Packs detect:[:p | p notNil and:[p isInteger not and:[p packsFileName = fn]]] ifNone:nil. |
|
446 |
cachedPack notNil ifTrue:[ |
|
447 |
"/ Transcript showCR:'cached pack: ',fn asString. |
|
448 |
^ cachedPack |
|
449 |
]. |
|
450 |
||
244 | 451 |
newPack := self new. |
7388 | 452 |
KeepStatisticsOnUsedKeys == true ifTrue:[ |
453 |
newPack rememberUsedKeys. |
|
454 |
]. |
|
8514 | 455 |
"/ '5) file ' print. aFileName print. |
456 |
"/ ' in ' print. dirName printCR. |
|
244 | 457 |
newPack readFromFile:aFileName directory:dirName. |
4611 | 458 |
cached ifTrue:[ |
7388 | 459 |
self addToCache:newPack. |
4611 | 460 |
]. |
244 | 461 |
^ newPack |
8483 | 462 |
|
463 |
"Modified: / 25-09-2018 / 09:57:42 / Claus Gittinger" |
|
8520 | 464 |
! |
465 |
||
466 |
newDefaultResourcePack |
|
467 |
|rsrcs cls superPack| |
|
468 |
||
469 |
rsrcs := ResourcePack new. |
|
470 |
(cls := Smalltalk classNamed:'stx_libtool') notNil ifTrue:[ |
|
471 |
superPack := cls classResources |
|
472 |
] ifFalse:[ |
|
473 |
(cls := Smalltalk classNamed:'stx_libview') notNil ifTrue:[ |
|
474 |
superPack := cls classResources |
|
475 |
]. |
|
476 |
]. |
|
477 |
superPack notNil ifTrue:[ rsrcs addSuperPack:superPack ]. |
|
478 |
^ rsrcs |
|
0 | 479 |
! ! |
480 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
481 |
!ResourcePack class methodsFor:'private'! |
54 | 482 |
|
483 |
addToCache:aPack |
|
484 |
|idx| |
|
0 | 485 |
|
4084 | 486 |
Packs isNil ifTrue:[ |
8462 | 487 |
self initialize. |
4084 | 488 |
]. |
489 |
||
54 | 490 |
idx := Packs identityIndexOf:nil. |
491 |
idx == 0 ifTrue:[ |
|
8462 | 492 |
idx := Packs findFirst:[:slot | slot class == SmallInteger]. |
1078
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
493 |
]. |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
494 |
idx == 0 ifTrue:[ |
8462 | 495 |
" |
496 |
throw away oldest |
|
497 |
" |
|
498 |
idx := Packs size. |
|
499 |
Packs replaceFrom:1 to:idx-1 with:Packs startingAt:2. |
|
54 | 500 |
]. |
5357 | 501 |
aPack at:'__language__' put:(UserPreferences current language,'_',UserPreferences current languageTerritory). |
4619 | 502 |
Packs at:idx put:aPack. |
503 |
||
504 |
"Modified: / 18-09-2006 / 19:12:12 / cg" |
|
54 | 505 |
! |
0 | 506 |
|
8517 | 507 |
searchCacheFor:aPackageName |
4619 | 508 |
|sz "{ Class: SmallInteger }" lang| |
0 | 509 |
|
24 | 510 |
Packs isNil ifTrue:[ |
8462 | 511 |
self initialize. |
512 |
^ nil |
|
0 | 513 |
]. |
54 | 514 |
|
5357 | 515 |
lang := (UserPreferences current language,'_',UserPreferences current languageTerritory). |
4619 | 516 |
|
54 | 517 |
sz := Packs size. |
518 |
1 to:sz do:[:idx | |
|
8462 | 519 |
|aPack| |
54 | 520 |
|
8462 | 521 |
aPack := Packs at:idx. |
522 |
(aPack notNil and:[aPack class ~~ SmallInteger]) ifTrue:[ |
|
523 |
(aPack at:'__language__' ifAbsent:nil) = lang ifTrue:[ |
|
8517 | 524 |
aPackageName = aPack packsPackage ifTrue:[ |
8462 | 525 |
" |
526 |
bring to front for LRU |
|
527 |
" |
|
528 |
idx ~~ 1 ifTrue:[ |
|
529 |
Packs replaceFrom:2 to:idx with:Packs startingAt:1. |
|
530 |
Packs at:1 put:aPack. |
|
531 |
]. |
|
532 |
^ aPack |
|
533 |
] |
|
534 |
] |
|
535 |
] |
|
0 | 536 |
]. |
54 | 537 |
^ nil |
123 | 538 |
|
539 |
" |
|
8517 | 540 |
ResourcePack searchCacheFor:'stx:libview' |
123 | 541 |
" |
4619 | 542 |
|
543 |
"Modified: / 18-09-2006 / 19:13:13 / cg" |
|
54 | 544 |
! ! |
545 |
||
4509 | 546 |
!ResourcePack class methodsFor:'utilities'! |
547 |
||
548 |
extractEncodingFromLine:lineString |
|
549 |
|rest encoding| |
|
550 |
||
551 |
(lineString startsWith:'encoding') ifFalse:[^ nil]. |
|
552 |
||
553 |
rest := lineString copyFrom:9. |
|
554 |
rest := rest withoutSeparators. |
|
555 |
(rest startsWith:'#') ifTrue:[ |
|
8462 | 556 |
rest := rest copyFrom:2. |
4509 | 557 |
]. |
558 |
(rest startsWith:'''') ifTrue:[ |
|
8462 | 559 |
rest := rest copyFrom:2. |
560 |
(rest endsWith:'''') ifTrue:[ |
|
561 |
rest := rest copyButLast:1. |
|
562 |
]. |
|
4509 | 563 |
]. |
564 |
encoding := rest asSymbol. |
|
565 |
^ encoding. |
|
566 |
! |
|
567 |
||
568 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack |
|
569 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
|
570 |
||
4510 | 571 |
self |
8462 | 572 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack |
573 |
keepUselessTranslations:false. |
|
4510 | 574 |
! |
575 |
||
576 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack keepUselessTranslations:keepUselessTranslations |
|
577 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
|
578 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
579 |
|name lineStream idx rest macroName value |
4670 | 580 |
conditional hasError decoder oldValue ignoreTranslation indirect| |
4509 | 581 |
|
6250 | 582 |
"/ Transcript showCR:lineString. |
4531 | 583 |
encodingSymbolOrEncoder notNil ifTrue:[ |
8462 | 584 |
encodingSymbolOrEncoder isSymbol ifTrue:[ |
585 |
decoder := CharacterEncoder encoderFor:encodingSymbolOrEncoder ifAbsent:nil. |
|
586 |
decoder isNil ifTrue:[ decoder := CharacterEncoder nullEncoderInstance ]. |
|
587 |
] ifFalse:[ |
|
588 |
decoder := encodingSymbolOrEncoder |
|
589 |
]. |
|
4531 | 590 |
]. |
591 |
||
592 |
decoder notNil ifTrue:[ |
|
8462 | 593 |
lineStream := (decoder decodeString:lineString) readStream. |
4531 | 594 |
] ifFalse:[ |
8462 | 595 |
lineStream := lineString readStream. |
4531 | 596 |
]. |
4509 | 597 |
lineStream signalAtEnd:false. |
598 |
lineStream skipSeparators. |
|
5080 | 599 |
|
4509 | 600 |
lineStream peek == $# ifTrue:[ |
8462 | 601 |
name := Array |
602 |
readFrom:lineStream |
|
603 |
onError:[ |
|
604 |
printError value:('invalid line <' , lineString , '>'). |
|
605 |
nil |
|
606 |
]. |
|
4509 | 607 |
] ifFalse:[ |
8462 | 608 |
lineStream peek == $' ifTrue:[ |
609 |
name := String |
|
610 |
readSmalltalkStringFrom:lineStream |
|
611 |
onError:[ |
|
612 |
printError value:('invalid line <' , lineString , '>'). |
|
613 |
nil |
|
614 |
]. |
|
615 |
] ifFalse:[ |
|
616 |
name := lineStream upToSeparator. |
|
617 |
]. |
|
4509 | 618 |
]. |
619 |
||
4510 | 620 |
name isNil ifTrue:[^ self ]. |
621 |
||
622 |
ignoreTranslation := false. |
|
623 |
hasError := false. |
|
4509 | 624 |
|
4510 | 625 |
lineStream skipSeparators. |
6113 | 626 |
idx := lineStream position + 1 + 1. |
4510 | 627 |
|
628 |
lineStream peek == $< ifTrue:[ |
|
8462 | 629 |
" |
630 |
skip <type> if present |
|
631 |
" |
|
632 |
lineStream skipThrough:$>. |
|
633 |
lineStream skipSeparators. |
|
634 |
idx := lineStream position + 2. |
|
4510 | 635 |
]. |
4509 | 636 |
|
4670 | 637 |
conditional := indirect := false. |
4510 | 638 |
lineStream peek == $? ifTrue:[ |
8462 | 639 |
conditional := true. |
640 |
lineStream next. |
|
641 |
lineStream skipSeparators. |
|
4670 | 642 |
]. |
643 |
||
644 |
lineStream peek == $@ ifTrue:[ |
|
8462 | 645 |
indirect := true. |
646 |
lineStream next. |
|
647 |
lineStream skipSeparators. |
|
4510 | 648 |
]. |
4509 | 649 |
|
4510 | 650 |
lineStream peek == $= ifTrue:[ |
8462 | 651 |
lineStream next. |
4510 | 652 |
|
8462 | 653 |
macroName := lineStream nextAlphaNumericWord. |
654 |
[lineStream peek == $.] whileTrue:[ |
|
655 |
lineStream next. |
|
656 |
lineStream peek notNil ifTrue:[ |
|
657 |
macroName := macroName , '.' , (lineStream nextAlphaNumericWord) |
|
658 |
] |
|
659 |
]. |
|
660 |
rest := lineStream upToEnd. |
|
661 |
value := aResourcePack at:macroName ifAbsent:nil. |
|
662 |
(value isNil) ifTrue:[ |
|
663 |
hasError := true. |
|
664 |
printError value:('bad (nil-valued) macro: ' , macroName). |
|
665 |
]. |
|
4678
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
666 |
"/ value isBlock ifTrue:[ |
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
667 |
"/ value := value value |
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
668 |
"/ ]. |
8462 | 669 |
rest isBlank ifFalse:[ |
670 |
value := Compiler evaluate:('self ' , rest) |
|
671 |
receiver:value |
|
672 |
notifying:nil |
|
673 |
compile:false. |
|
674 |
(value == #Error) ifTrue:[ |
|
675 |
hasError := true. |
|
676 |
printError value:('error in: "self ' , rest , '"'). |
|
677 |
]. |
|
678 |
"/ 'self ' print. rest print. ' -> ' print. value printCR. |
|
679 |
] |
|
4510 | 680 |
] ifFalse:[ |
8462 | 681 |
lineStream peek == $' ifTrue:[ |
682 |
value := String |
|
683 |
readSmalltalkStringFrom:lineStream |
|
684 |
onError:[ |
|
685 |
printError value:('invalid line <' , lineString , '>'). |
|
686 |
nil |
|
687 |
]. |
|
688 |
"/ ' -> ' print. value printCR. |
|
689 |
] ifFalse:[ |
|
690 |
rest := lineStream upToEnd. |
|
691 |
[ |
|
692 |
value := Compiler evaluate:rest compile:"true" false. |
|
693 |
] on:Error do:[ |
|
8476 | 694 |
printError value:('invalid line <' , lineString , '>'). |
8462 | 695 |
"/ value := rest |
696 |
]. |
|
697 |
"/ rest print. ' -> ' print. value printCR. |
|
698 |
]. |
|
699 |
(value == #Error) ifTrue:[ |
|
700 |
hasError := true. |
|
701 |
printError value:('error in: "' , rest , '"'). |
|
702 |
] ifFalse:[ |
|
4531 | 703 |
"/ value isString ifTrue:[ |
704 |
"/ decoder notNil ifTrue:[ |
|
705 |
"/ value := decoder decodeString:value |
|
706 |
"/ ] |
|
707 |
"/ ] |
|
8462 | 708 |
] |
4510 | 709 |
]. |
710 |
||
5430
128e9b37fd8a
comment/format in: #processResourceLine:encoding:file:printErrorWith:for:
sr
parents:
5370
diff
changeset
|
711 |
"/ Transcript show:name; show:' -> '; showCR:value. |
128e9b37fd8a
comment/format in: #processResourceLine:encoding:file:printErrorWith:for:
sr
parents:
5370
diff
changeset
|
712 |
|
4510 | 713 |
hasError ifFalse:[ |
8462 | 714 |
(conditional not |
715 |
or:[(aResourcePack includesKey:name) not]) ifTrue:[ |
|
716 |
name = value ifTrue:[ |
|
717 |
keepUselessTranslations ifFalse:[ |
|
718 |
printError value:('useless resource: "' , name , '"'). |
|
719 |
ignoreTranslation := true |
|
720 |
]. |
|
721 |
]. |
|
722 |
ignoreTranslation ifFalse:[ |
|
723 |
oldValue := aResourcePack at:name ifAbsent:nil. |
|
724 |
oldValue notNil ifTrue:[ |
|
725 |
oldValue ~= value ifTrue:[ |
|
726 |
printError value:('conflicting resource: "' , name , '"'). |
|
727 |
printError value:('oldValue: ' , oldValue printString). |
|
728 |
printError value:('newValue: ' , value printString). |
|
729 |
] ifFalse:[ |
|
730 |
printError value:('duplicate resource: "' , name , '"'). |
|
731 |
]. |
|
732 |
]. |
|
733 |
indirect ifTrue:[ |
|
734 |
value := aResourcePack string:value. |
|
735 |
]. |
|
5431 | 736 |
|
8462 | 737 |
DebugModifications == true ifTrue:[ |
738 |
"/ for debugging only !! (not all primitive code is ready for immutableStrings) |
|
739 |
value class == String ifTrue:[ |
|
740 |
value := value asImmutableString. |
|
741 |
]. |
|
742 |
]. |
|
5431 | 743 |
|
8462 | 744 |
aResourcePack at:name put:value. |
745 |
] |
|
746 |
] |
|
4509 | 747 |
] |
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
748 |
|
6250 | 749 |
"Modified: / 06-02-2014 / 15:33:03 / cg" |
8476 | 750 |
"Modified: / 20-09-2018 / 11:10:06 / Claus Gittinger" |
6661 | 751 |
! |
752 |
||
753 |
resourceFileEntryFor:keyString to:nationalString |
|
754 |
"generate a line for a translation file, which defines a translation |
|
755 |
from keyString to nationalString. |
|
756 |
Naivly, this could be a simple line containing the two storeStrings |
|
757 |
separated by a space. However, it is better to first cut of any leading |
|
758 |
and trailing spaces and special characters, such as ':*.,' etc." |
|
759 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
760 |
^ (self resourceFileStringFor:keyString),' ',(self resourceFileStringFor:nationalString) |
6661 | 761 |
! |
762 |
||
763 |
resourceFileStringFor:aString |
|
764 |
"generate a key or value entry for a translation file, for aString. |
|
765 |
Naivly, this could be a simple the storeString. |
|
766 |
However, it is better to first cut of any leading |
|
767 |
and trailing spaces and special characters, sch as ':*.,' etc." |
|
768 |
||
769 |
^ (self shortenedKeyFor:aString) storeString |
|
770 |
||
771 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
772 |
self resourceFileStringFor:' foo: ' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
773 |
self resourceFileStringFor:' foo bar: ' |
6661 | 774 |
" |
775 |
! |
|
776 |
||
777 |
shortenedKeyFor:aKey |
|
778 |
"if |
|
8462 | 779 |
aKey is '(...)', then return '...' |
780 |
if aKey is '[...]', then return '...' |
|
781 |
if aKey is '{...}', then return '...' |
|
782 |
if aKey starts or ends with any of '\:=.,?!! ', then return aKey without it |
|
6661 | 783 |
|
784 |
This means, that only a single translation is required to provide local translations for |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
785 |
things like |
8462 | 786 |
'search' |
787 |
'search:' |
|
788 |
'search...' |
|
6661 | 789 |
" |
790 |
||
791 |
|idx idx1 idx2 first last keySize| |
|
792 |
||
793 |
first := aKey first. |
|
794 |
last := aKey last. |
|
795 |
keySize := aKey size. |
|
796 |
||
797 |
((first == $( and:[last == $) ]) |
|
798 |
or:[ (first == $[ and:[last == $] ]) |
|
799 |
or:[ (first == ${ and:[last == $} ]) ]]) ifTrue:[ |
|
8462 | 800 |
^ self shortenedKeyFor:(aKey copyFrom:2 to:keySize-1). |
6661 | 801 |
]. |
802 |
||
803 |
idx1 := aKey findFirst:[:ch | ch isSeparator not]. |
|
804 |
idx2 := aKey findLast:[:ch | ch isSeparator not] ifNone:keySize. |
|
805 |
(idx1 > 1 or:[idx2 < keySize]) ifTrue:[ |
|
8462 | 806 |
^ self shortenedKeyFor:(aKey copyFrom:idx1 to:idx2) |
6661 | 807 |
]. |
808 |
||
809 |
idx1 := aKey findFirst:[:ch | ('*:=.?!!,-><\' includes:ch) not]. |
|
810 |
idx2 := aKey findLast:[:ch | ('*:=.?!!,-><\' includes:ch) not] ifNone:keySize. |
|
811 |
(idx1 > 1 or:[idx2 < keySize]) ifTrue:[ |
|
8462 | 812 |
^ self shortenedKeyFor:(aKey copyFrom:idx1 to:idx2) |
6661 | 813 |
]. |
814 |
||
815 |
"/ change duplicated &'s to single |
|
816 |
(idx := aKey indexOf:$&) ~~ 0 ifTrue:[ |
|
8462 | 817 |
(aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[ |
818 |
^ self shortenedKeyFor:(aKey copyTo:idx-1),(aKey copyFrom:idx+1). |
|
819 |
]. |
|
6661 | 820 |
]. |
821 |
^ aKey. |
|
822 |
||
823 |
" |
|
824 |
'abcde' findFirst:[:ch | 'bcd' includes:ch] |
|
825 |
'abcde' indexOfAny:'bcd' |
|
826 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
827 |
self shortenedKeyFor:'abc' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
828 |
self shortenedKeyFor:' abc ' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
829 |
self shortenedKeyFor:'(abc)' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
830 |
self shortenedKeyFor:'abc...' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
831 |
self shortenedKeyFor:'(abc...)' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
832 |
self shortenedKeyFor:'abc:*' |
6661 | 833 |
" |
4509 | 834 |
! ! |
835 |
||
0 | 836 |
!ResourcePack methodsFor:'accessing'! |
837 |
||
244 | 838 |
array:anArray |
839 |
"translate a collection of strings" |
|
0 | 840 |
|
244 | 841 |
^ anArray collect:[:r | self at:r default:r] |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
842 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
843 |
" |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
844 |
Launcher classResources array:#('file' 'classes') |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
845 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
846 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
847 |
"Modified: / 29.1.1998 / 22:44:22 / cg" |
0 | 848 |
! |
849 |
||
2 | 850 |
at:aKey |
123 | 851 |
"translate a string" |
852 |
||
72 | 853 |
^ self at:aKey ifAbsent:aKey |
0 | 854 |
! |
855 |
||
856 |
at:aKey default:default |
|
123 | 857 |
"translate a string" |
858 |
||
72 | 859 |
^ self at:aKey ifAbsent:default |
0 | 860 |
! |
861 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
862 |
at:aKey ifAbsent:defaultValue |
4617 | 863 |
"translate a string; search here, in my projects pack and in my superpack(s)" |
864 |
||
8516 | 865 |
|val pack projectPack alreadySearched toSearch more| |
4617 | 866 |
|
867 |
aKey isNil ifTrue:[ ^ defaultValue value ]. |
|
868 |
||
8517 | 869 |
usedKeys notNil ifTrue:[usedKeys add:aKey]. |
870 |
||
4617 | 871 |
val := self localAt:aKey. |
872 |
val notNil ifTrue:[^ val]. |
|
873 |
||
8461 | 874 |
cache isNil ifTrue:[ cache := CacheDictionary new:1000 ]. |
875 |
(val := cache at:aKey ifAbsent:nil) notNil ifTrue:[ |
|
876 |
^ val |
|
877 |
]. |
|
878 |
||
8516 | 879 |
superPacks notEmptyOrNil ifTrue:[ |
8510 | 880 |
alreadySearched := Set new. |
881 |
toSearch := OrderedCollection withAll:superPacks. |
|
882 |
[toSearch notEmpty] whileTrue:[ |
|
883 |
pack := toSearch removeFirst. |
|
884 |
(alreadySearched includes:pack) ifFalse:[ |
|
885 |
val := pack localAt:aKey. |
|
8461 | 886 |
val notNil ifTrue:[ |
887 |
cache at:aKey put:val. |
|
888 |
^ val |
|
889 |
]. |
|
8510 | 890 |
alreadySearched add:pack. |
8516 | 891 |
(more := pack superPacks) notEmptyOrNil ifTrue:[ |
892 |
self assert:(more conform:[:each | each isNil or:[pack isKindOf:ResourcePack]]). |
|
893 |
toSearch addAll:more. |
|
894 |
]. |
|
8461 | 895 |
]. |
896 |
]. |
|
4617 | 897 |
]. |
8510 | 898 |
^ defaultValue value. |
4618 | 899 |
|
8510 | 900 |
"/ (projectPack := self projectPack) notNil ifTrue:[ |
901 |
"/ val := projectPack localAt:aKey. |
|
902 |
"/ val notNil ifTrue:[ |
|
903 |
"/ cache at:aKey put:val. |
|
904 |
"/ ^ val |
|
905 |
"/ ]. |
|
906 |
"/ ]. |
|
907 |
"/ alreadySearched := IdentitySet new. |
|
908 |
"/ projectPack notNil ifTrue:[ alreadySearched add:projectPack ]. |
|
909 |
"/ |
|
910 |
"/ pack := self superPack. |
|
911 |
"/ [ pack notNil ] whileTrue:[ |
|
912 |
"/ val := pack localAt:aKey. |
|
913 |
"/ val notNil ifTrue:[ |
|
914 |
"/ cache at:aKey put:val. |
|
915 |
"/ ^ val |
|
916 |
"/ ]. |
|
917 |
"/ |
|
918 |
"/ (projectPack := pack projectPack) notNil ifTrue:[ |
|
919 |
"/ (alreadySearched includes:projectPack) ifFalse:[ |
|
920 |
"/ val := projectPack localAt:aKey. |
|
921 |
"/ val notNil ifTrue:[ |
|
922 |
"/ cache at:aKey put:val. |
|
923 |
"/ ^ val |
|
924 |
"/ ]. |
|
925 |
"/ alreadySearched add:projectPack. |
|
926 |
"/ ]. |
|
927 |
"/ ]. |
|
928 |
"/ pack := pack superPack |
|
929 |
"/ ]. |
|
930 |
"/ |
|
931 |
"/ alreadySearched copy do:[:projectPack | |
|
932 |
"/ |p| |
|
933 |
"/ |
|
934 |
"/ p := projectPack superPack. |
|
935 |
"/ [p notNil and:[(alreadySearched includes:p) not]] whileTrue:[ |
|
936 |
"/ val := p localAt:aKey. |
|
937 |
"/ val notNil ifTrue:[ |
|
938 |
"/ cache at:aKey put:val. |
|
939 |
"/ ^ val |
|
940 |
"/ ]. |
|
941 |
"/ alreadySearched add:p. |
|
942 |
"/ p := p superPack. |
|
943 |
"/ ]. |
|
944 |
"/ ]. |
|
945 |
"/ |
|
946 |
"/ val := defaultValue value. |
|
947 |
"/ cache at:aKey put:val. |
|
948 |
"/ ^ val |
|
4617 | 949 |
|
4618 | 950 |
"Modified: / 18-09-2006 / 18:50:52 / cg" |
8461 | 951 |
"Modified: / 12-09-2018 / 18:32:57 / Claus Gittinger" |
4617 | 952 |
! |
953 |
||
954 |
localAt:aKey |
|
4035 | 955 |
"translate a string. |
956 |
Some special 'intelligence' has been added: |
|
8226 | 957 |
if no value for aKey is found, |
958 |
lookup aKey with first character caseChanged and change the results first characters case. |
|
959 |
or aKey is '(...)', then lookup ... wrap () around the result. |
|
960 |
or aKey is '[...]', then lookup ... wrap [] around the result. |
|
961 |
or aKey is '{...}', then lookup ... wrap {} around the result. |
|
962 |
or aKey starts with a '\', then lookup aKey without '\' and prepend '\' to the result. |
|
963 |
or aKey starts with a '*', then lookup aKey without '*' and prepend '*' to the result. |
|
964 |
or aKey ends with a '\', then lookup aKey without '\' and append '\' to the result. |
|
965 |
or aKey ends with a ':', then lookup aKey without ':' and append ':' to the result. |
|
966 |
or aKey ends with a '=', then lookup aKey without '=' and append '=' to the result. |
|
967 |
or aKey ends with a '.', then lookup aKey without '.' and append '.' to the result. |
|
968 |
or aKey ends with a ',', then lookup aKey without ',' and append ',' to the result. |
|
969 |
or aKey ends with a '?', then lookup aKey without '?' and append '?' to the result. |
|
970 |
or aKey ends with a '!!', then lookup aKey without '!!' and append '!!' to the result. |
|
971 |
or aKey ends with a '*', then lookup aKey without '*' and append '*' to the result. |
|
972 |
or aKey ends with a ' ', then lookup aKey without ' ' and append ' ' to the result. |
|
973 |
or aKey ends with a ' ...', then lookup aKey without ' ...' and append '...' to the result. |
|
974 |
or aKey ends with a '...', then lookup aKey without '...' and append '...' to the result. |
|
975 |
or aKey includes '&', then lookup aKey without '&'. |
|
4035 | 976 |
|
977 |
This means, that only a single translation is required to provide local translations for |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
978 |
things like |
8226 | 979 |
'search' |
980 |
'search:' |
|
981 |
'search...' |
|
4035 | 982 |
" |
123 | 983 |
|
5573 | 984 |
|val alternativeKey usedKey idx first last| |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
985 |
|
4617 | 986 |
val := super at:aKey ifAbsent:nil. |
4678
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
987 |
val notNil ifTrue:[ |
8226 | 988 |
^ val value |
4678
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
989 |
]. |
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
990 |
|
4848 | 991 |
(aKey isString and:[aKey notEmpty]) ifTrue:[ |
8226 | 992 |
first := aKey first. |
993 |
last := aKey last. |
|
5573 | 994 |
|
8226 | 995 |
"/ try with case-first swapped... |
996 |
first isLetter ifTrue:[ |
|
997 |
alternativeKey := first isUppercase |
|
998 |
ifTrue:[aKey asLowercaseFirst] |
|
999 |
ifFalse:[aKey asUppercaseFirst]. |
|
1000 |
val := super at:alternativeKey ifAbsent:nil. |
|
1001 |
val notNil ifTrue:[ |
|
1002 |
first isUppercase ifTrue:[ |
|
1003 |
^ val asUppercaseFirst |
|
1004 |
]. |
|
1005 |
^ val asLowercaseFirst. |
|
1006 |
]. |
|
1007 |
]. |
|
4617 | 1008 |
|
8226 | 1009 |
((first == $( and:[last == $) ]) |
1010 |
or:[ (first == $[ and:[last == $] ]) |
|
1011 |
or:[ (first == ${ and:[last == $} ]) ]]) ifTrue:[ |
|
1012 |
usedKey := aKey copyFrom:2 to:aKey size-1. |
|
5593 | 1013 |
|
8226 | 1014 |
val := self localAt:usedKey. "/ recursion |
1015 |
val notNil ifTrue:[^ first asString,val,last asString]. |
|
1016 |
]. |
|
8498 | 1017 |
last == $… ifTrue:[ |
1018 |
usedKey := aKey copyButLast:1. |
|
5593 | 1019 |
|
8498 | 1020 |
val := self localAt:usedKey. "/ recursion |
1021 |
val notNil ifTrue:[^ val , '…']. |
|
1022 |
]. |
|
1023 |
||
8226 | 1024 |
last == $. ifTrue:[ |
1025 |
(aKey endsWith:' ...') ifTrue:[ |
|
1026 |
usedKey := aKey copyButLast:4. |
|
5573 | 1027 |
|
8226 | 1028 |
val := self localAt:usedKey. "/ recursion |
8498 | 1029 |
val notNil ifTrue:[^ val , '...']. |
8226 | 1030 |
]. |
1031 |
(aKey endsWith:'...') ifTrue:[ |
|
1032 |
usedKey := aKey copyButLast:3. |
|
5573 | 1033 |
|
8226 | 1034 |
val := self localAt:usedKey. "/ recursion |
1035 |
val notNil ifTrue:[^ val , '...']. |
|
1036 |
]. |
|
1037 |
]. |
|
5573 | 1038 |
|
8226 | 1039 |
first isSeparator ifTrue:[ |
1040 |
usedKey := aKey withoutLeadingSeparators. |
|
4634 | 1041 |
|
8226 | 1042 |
val := self localAt:usedKey. "/ recursion |
1043 |
val notNil ifTrue:[^ (aKey copyTo:(aKey size - usedKey size)), val]. "/ prepend the stripped separators |
|
1044 |
]. |
|
1045 |
last isSeparator ifTrue:[ |
|
1046 |
usedKey := aKey withoutTrailingSeparators. |
|
4634 | 1047 |
|
8226 | 1048 |
val := self localAt:usedKey. "/ recursion |
1049 |
val notNil ifTrue:[^ val, (aKey copyFrom:usedKey size + 1)]. "/ append the stripped separators |
|
1050 |
]. |
|
4634 | 1051 |
|
8226 | 1052 |
('*:=.?!!,-><\' includes:last) ifTrue:[ |
1053 |
aKey size >= 2 ifTrue:[ |
|
1054 |
usedKey := aKey copyButLast:1. |
|
4617 | 1055 |
|
8226 | 1056 |
val := self localAt:usedKey. "/ recursion |
1057 |
val notNil ifTrue:[^ val copyWith:last]. |
|
1058 |
]. |
|
1059 |
]. |
|
1060 |
('*:=.?!!-><\' includes:first) ifTrue:[ |
|
1061 |
aKey size >= 2 ifTrue:[ |
|
1062 |
usedKey := aKey copyButFirst:1. |
|
4634 | 1063 |
|
8226 | 1064 |
val := self localAt:usedKey. "/ recursion |
1065 |
val notNil ifTrue:[^ first asString , val]. |
|
1066 |
]. |
|
1067 |
]. |
|
4028 | 1068 |
|
8226 | 1069 |
(first == $( and:[last == $)]) ifTrue:[ |
1070 |
usedKey := aKey copyFrom:2 to:(aKey size - 1). |
|
4028 | 1071 |
|
8226 | 1072 |
val := self localAt:usedKey. "/ recursion |
1073 |
val notNil ifTrue:[^ '(' , val , ')']. |
|
1074 |
]. |
|
4017 | 1075 |
|
8226 | 1076 |
(idx := aKey indexOf:$&) ~~ 0 ifTrue:[ |
1077 |
(aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[ |
|
1078 |
usedKey := (aKey copyTo:idx-1) , (aKey copyFrom:idx+1). |
|
1079 |
val := self localAt:usedKey. "/ recursion |
|
1080 |
val notNil ifTrue:[^ val]. |
|
1081 |
]. |
|
1082 |
]. |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1083 |
]. |
4617 | 1084 |
^ nil. |
4580 | 1085 |
|
4617 | 1086 |
"Created: / 18-09-2006 / 17:33:27 / cg" |
5593 | 1087 |
"Modified: / 05-08-2010 / 16:52:32 / sr" |
8226 | 1088 |
"Modified: / 27-11-2017 / 15:33:48 / cg" |
2 | 1089 |
! |
1090 |
||
1091 |
name:aKey default:default |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1092 |
"translate a string. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1093 |
Obsolete - use #string:default:" |
123 | 1094 |
|
4844 | 1095 |
<resource: #obsolete> |
1096 |
||
72 | 1097 |
^ self at:aKey ifAbsent:default |
2 | 1098 |
! |
1099 |
||
0 | 1100 |
string:s |
3097 | 1101 |
"translate (retrieve) a string - if not present, return s" |
123 | 1102 |
|
72 | 1103 |
^ self at:s ifAbsent:s |
3097 | 1104 |
|
1105 |
" |
|
1106 |
NewLauncher classResources |
|
8462 | 1107 |
string:'LICENCEFILE' |
3097 | 1108 |
" |
0 | 1109 |
! |
1110 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1111 |
string:s default:defaultString |
3097 | 1112 |
"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
|
1113 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1114 |
^ self at:s ifAbsent:defaultString |
3097 | 1115 |
|
1116 |
" |
|
1117 |
NewLauncher classResources |
|
8462 | 1118 |
string:'fooBar' default:'Hello world' |
3097 | 1119 |
" |
1120 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1121 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1122 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1123 |
string:s default:defaultString with:arg |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1124 |
"translate and expand arg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1125 |
|
8445 | 1126 |
^ self string:s default:defaultString withArguments:(Array with:arg) |
3097 | 1127 |
|
1128 |
" |
|
1129 |
NewLauncher classResources |
|
8445 | 1130 |
string:'%1 fooBar' default:'Hello %1' with:'foo' |
3097 | 1131 |
" |
1132 |
||
8445 | 1133 |
"Modified: / 09-08-2018 / 14:55:56 / Claus Gittinger" |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1134 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1135 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1136 |
string:s default:defaultString with:arg1 with:arg2 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1137 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1138 |
|
8445 | 1139 |
^ self string:s default:defaultString withArguments:(Array with:arg1 with:arg2) |
1140 |
||
1141 |
"Modified: / 09-08-2018 / 14:55:53 / Claus Gittinger" |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1142 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1143 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1144 |
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
|
1145 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1146 |
|
8445 | 1147 |
^ self string:s default:defaultString withArguments:(Array with:arg1 with:arg2 with:arg3) |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1148 |
|
8445 | 1149 |
"Created: / 09-12-1995 / 19:08:50 / cg" |
1150 |
"Modified: / 09-08-2018 / 14:55:51 / Claus Gittinger" |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1151 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1152 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1153 |
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
|
1154 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1155 |
|
8445 | 1156 |
^ self string:s default:defaultString withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1157 |
|
8445 | 1158 |
"Created: / 09-09-1996 / 18:52:14 / cg" |
1159 |
"Modified: / 09-08-2018 / 14:55:47 / Claus Gittinger" |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1160 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1161 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1162 |
string:s default:defaultString withArgs:argArray |
8445 | 1163 |
<resource: #obsolete> |
1164 |
"translate and expand args" |
|
1165 |
||
1166 |
^ self string:s default:defaultString withArguments:argArray |
|
1167 |
||
1168 |
"Modified: / 09-08-2018 / 14:55:38 / Claus Gittinger" |
|
1169 |
! |
|
1170 |
||
1171 |
string:s default:defaultString withArguments:argArray |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1172 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1173 |
|
5070 | 1174 |
|template| |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1175 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1176 |
template := self at:s ifAbsent:defaultString. |
5070 | 1177 |
^ template expandPlaceholdersWith:argArray. |
8445 | 1178 |
|
1179 |
"Created: / 09-08-2018 / 14:55:29 / Claus Gittinger" |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1180 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1181 |
|
0 | 1182 |
string:s with:arg |
123 | 1183 |
"translate and expand arg" |
1184 |
||
8445 | 1185 |
^ self string:s withArguments:(Array with:arg) |
1186 |
||
1187 |
"Modified: / 09-08-2018 / 14:56:02 / Claus Gittinger" |
|
0 | 1188 |
! |
1189 |
||
1190 |
string:s with:arg1 with:arg2 |
|
123 | 1191 |
"translate and expand args" |
1192 |
||
8445 | 1193 |
^ self string:s withArguments:(Array with:arg1 with:arg2) |
1194 |
||
1195 |
"Modified: / 09-08-2018 / 14:56:04 / Claus Gittinger" |
|
0 | 1196 |
! |
1197 |
||
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1198 |
string:s with:arg1 with:arg2 with:arg3 |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1199 |
"translate and expand args" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1200 |
|
8445 | 1201 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3) |
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1202 |
|
8445 | 1203 |
"Created: / 09-12-1995 / 19:08:50 / cg" |
1204 |
"Modified: / 09-08-2018 / 14:56:06 / Claus Gittinger" |
|
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1205 |
! |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1206 |
|
1042 | 1207 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 |
1208 |
"translate and expand args" |
|
1209 |
||
8445 | 1210 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
1042 | 1211 |
|
8445 | 1212 |
"Created: / 09-09-1996 / 18:52:14 / cg" |
1213 |
"Modified: / 09-08-2018 / 14:56:09 / Claus Gittinger" |
|
1042 | 1214 |
! |
1215 |
||
3184 | 1216 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
1217 |
"translate and expand args" |
|
1218 |
||
8445 | 1219 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
3184 | 1220 |
|
8445 | 1221 |
"Modified: / 09-08-2018 / 14:56:12 / Claus Gittinger" |
3184 | 1222 |
! |
1223 |
||
5652 | 1224 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
1225 |
"translate and expand args" |
|
1226 |
||
8445 | 1227 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6) |
5652 | 1228 |
|
1229 |
"Created: / 13-11-2010 / 11:35:00 / cg" |
|
8445 | 1230 |
"Modified: / 09-08-2018 / 14:56:14 / Claus Gittinger" |
5652 | 1231 |
! |
1232 |
||
1233 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7 |
|
1234 |
"translate and expand args" |
|
1235 |
||
8445 | 1236 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7) |
5652 | 1237 |
|
1238 |
"Created: / 13-11-2010 / 11:35:07 / cg" |
|
8445 | 1239 |
"Modified: / 09-08-2018 / 14:55:07 / Claus Gittinger" |
5652 | 1240 |
! |
1241 |
||
0 | 1242 |
string:s withArgs:argArray |
8445 | 1243 |
<resource: #obsolete> |
1244 |
"translate and expand args - allow text as arguments" |
|
1245 |
||
1246 |
^ self string:s withArguments:argArray |
|
1247 |
||
1248 |
"Modified: / 09-08-2018 / 14:54:54 / Claus Gittinger" |
|
1249 |
! |
|
1250 |
||
1251 |
string:s withArguments:argArray |
|
4932
b19b928b0026
Allow (and insert) Texts as arguments in #string:with:
Stefan Vogel <sv@exept.de>
parents:
4848
diff
changeset
|
1252 |
"translate and expand args - allow text as arguments" |
123 | 1253 |
|
5069 | 1254 |
|template| |
0 | 1255 |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1256 |
template := self at:s ifAbsent:s. |
5069 | 1257 |
^ template expandPlaceholdersWith:argArray. |
4932
b19b928b0026
Allow (and insert) Texts as arguments in #string:with:
Stefan Vogel <sv@exept.de>
parents:
4848
diff
changeset
|
1258 |
|
8445 | 1259 |
"Created: / 09-08-2018 / 14:54:43 / Claus Gittinger" |
3823 | 1260 |
! |
1261 |
||
4402 | 1262 |
stringWithCRs:s |
8459 | 1263 |
"translate (retrieve) a string - if not present, return s. |
1264 |
replaces \'s with CRs" |
|
4402 | 1265 |
|
8459 | 1266 |
(s startsWith:':c:') ifTrue:[ |
1267 |
^ (self string:(s withoutPrefix:':c:')) withoutCEscapes |
|
1268 |
]. |
|
1269 |
(s startsWith:':st:') ifTrue:[ |
|
1270 |
^ (self string:(s withoutPrefix:':st:')) expandPlaceholdersWith:nil |
|
1271 |
]. |
|
4402 | 1272 |
^ (self string:s) withCRs |
1273 |
||
1274 |
" |
|
1275 |
NewLauncher classResources |
|
8459 | 1276 |
stringWithCRs:'LICENCEFILE' |
4402 | 1277 |
" |
8459 | 1278 |
|
1279 |
"Modified: / 07-09-2018 / 12:43:00 / Claus Gittinger" |
|
4402 | 1280 |
! |
1281 |
||
3823 | 1282 |
stringWithCRs:s with:arg |
1283 |
"translate, replace \'s with CRs and finally expand arg. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1284 |
CR-replacement is donw before args are inserted |
3823 | 1285 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1286 |
||
8445 | 1287 |
^ self stringWithCRs:s withArguments:(Array with:arg) |
3823 | 1288 |
|
8445 | 1289 |
"Modified: / 21-03-2003 / 14:22:09 / cg" |
1290 |
"Modified: / 09-08-2018 / 14:56:21 / Claus Gittinger" |
|
3823 | 1291 |
! |
1292 |
||
1293 |
stringWithCRs:s with:arg1 with:arg2 |
|
1294 |
"translate, replace \'s with CRs and finally expand args. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1295 |
CR-replacement is donw before args are inserted |
3823 | 1296 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1297 |
||
8445 | 1298 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2) |
3823 | 1299 |
|
8445 | 1300 |
"Modified: / 21-03-2003 / 14:22:06 / cg" |
1301 |
"Modified: / 09-08-2018 / 14:56:25 / Claus Gittinger" |
|
3823 | 1302 |
! |
1303 |
||
1304 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 |
|
1305 |
"translate, replace \'s with CRs and finally expand args. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1306 |
CR-replacement is donw before args are inserted |
3823 | 1307 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1308 |
||
8445 | 1309 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3) |
3823 | 1310 |
|
8445 | 1311 |
"Created: / 09-12-1995 / 19:08:50 / cg" |
1312 |
"Modified: / 09-08-2018 / 14:56:27 / Claus Gittinger" |
|
3823 | 1313 |
! |
1314 |
||
1315 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 |
|
1316 |
"translate, replace \'s with CRs and finally expand args. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1317 |
CR-replacement is donw before args are inserted |
3823 | 1318 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1319 |
||
8445 | 1320 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
3823 | 1321 |
|
8445 | 1322 |
"Modified: / 21-03-2003 / 14:21:48 / cg" |
1323 |
"Modified: / 09-08-2018 / 14:56:30 / Claus Gittinger" |
|
3823 | 1324 |
! |
1325 |
||
1326 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
1327 |
"translate, replace \'s with CRs and finally expand args. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1328 |
CR-replacement is donw before args are inserted |
3823 | 1329 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1330 |
||
8445 | 1331 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
3823 | 1332 |
|
8445 | 1333 |
"Modified: / 21-03-2003 / 14:21:55 / cg" |
1334 |
"Modified: / 09-08-2018 / 14:56:32 / Claus Gittinger" |
|
3823 | 1335 |
! |
1336 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1337 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
5652 | 1338 |
"translate, replace \'s with CRs and finally expand args. |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1339 |
CR-replacement is donw before args are inserted |
5652 | 1340 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1341 |
||
8445 | 1342 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6) |
5652 | 1343 |
|
1344 |
"Created: / 13-11-2010 / 11:35:30 / cg" |
|
8445 | 1345 |
"Modified: / 09-08-2018 / 14:56:35 / Claus Gittinger" |
5652 | 1346 |
! |
1347 |
||
1348 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7 |
|
1349 |
"translate, replace \'s with CRs and finally expand args. |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1350 |
CR-replacement is donw before args are inserted |
5652 | 1351 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1352 |
||
8445 | 1353 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7) |
5652 | 1354 |
|
1355 |
"Created: / 13-11-2010 / 11:35:20 / cg" |
|
8445 | 1356 |
"Modified: / 09-08-2018 / 14:56:37 / Claus Gittinger" |
5652 | 1357 |
! |
1358 |
||
3823 | 1359 |
stringWithCRs:s withArgs:argArray |
8445 | 1360 |
<resource: #obsolete> |
1361 |
"translate, replace \'s with CRs and finally expand args. |
|
1362 |
CR-replacement is done before args are inserted |
|
1363 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
1364 |
||
1365 |
^ self stringWithCRs:s withArguments:argArray |
|
1366 |
||
1367 |
"Modified: / 09-08-2018 / 14:54:29 / Claus Gittinger" |
|
1368 |
! |
|
1369 |
||
1370 |
stringWithCRs:s withArguments:argArray |
|
3823 | 1371 |
"translate, replace \'s with CRs and finally expand args. |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1372 |
CR-replacement is done before args are inserted |
3823 | 1373 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1374 |
||
5070 | 1375 |
|template| |
3823 | 1376 |
|
1377 |
template := self at:s ifAbsent:s. |
|
8459 | 1378 |
(s startsWith:':c:') ifTrue:[ |
1379 |
^ (self string:(s withoutPrefix:':c:')) withoutCEscapes expandPlaceholdersWith:argArray |
|
1380 |
]. |
|
1381 |
(s startsWith:':st:') ifTrue:[ |
|
1382 |
^ (self string:(s withoutPrefix:':st:')) expandPlaceholdersWith:argArray |
|
1383 |
]. |
|
5070 | 1384 |
^ template withCRs expandPlaceholdersWith:argArray. |
8445 | 1385 |
|
1386 |
"Created: / 09-08-2018 / 14:54:16 / Claus Gittinger" |
|
8459 | 1387 |
"Modified: / 07-09-2018 / 12:44:06 / Claus Gittinger" |
6174 | 1388 |
! |
1389 |
||
1390 |
whichPackIncludesKey:aKey |
|
1391 |
"for debugging: return the pack (alogn the super-pack chain), which |
|
1392 |
has a translation for a string" |
|
1393 |
||
8510 | 1394 |
|val pack projectPack alreadySearched toSearch| |
6174 | 1395 |
|
1396 |
aKey isNil ifTrue:[ ^ nil ]. |
|
1397 |
||
1398 |
val := self localAt:aKey. |
|
1399 |
val notNil ifTrue:[^ self]. |
|
1400 |
||
8516 | 1401 |
superPacks isEmptyOrNil ifTrue:[^ nil]. |
6174 | 1402 |
|
8510 | 1403 |
alreadySearched := Set new. |
1404 |
toSearch := OrderedCollection withAll:superPacks. |
|
1405 |
[toSearch notEmpty] whileTrue:[ |
|
1406 |
pack := toSearch removeFirst. |
|
1407 |
(alreadySearched includes:pack) ifFalse:[ |
|
1408 |
val := pack localAt:aKey. |
|
1409 |
val notNil ifTrue:[^ pack]. |
|
1410 |
alreadySearched add:pack. |
|
1411 |
toSearch addAll:(pack superPacks). |
|
8462 | 1412 |
]. |
6174 | 1413 |
]. |
8510 | 1414 |
^ nil. |
1415 |
||
1416 |
"/ (projectPack := self projectPack) notNil ifTrue:[ |
|
1417 |
"/ val := projectPack localAt:aKey. |
|
1418 |
"/ val notNil ifTrue:[^ projectPack]. |
|
1419 |
"/ ]. |
|
1420 |
"/ alreadySearched := Set new. |
|
1421 |
"/ projectPack notNil ifTrue:[ alreadySearched add:projectPack ]. |
|
1422 |
"/ |
|
1423 |
"/ pack := self superPack. |
|
1424 |
"/ [ pack notNil ] whileTrue:[ |
|
1425 |
"/ val := pack localAt:aKey. |
|
1426 |
"/ val notNil ifTrue:[^ pack]. |
|
1427 |
"/ |
|
1428 |
"/ (projectPack := pack projectPack) notNil ifTrue:[ |
|
1429 |
"/ (alreadySearched includes:projectPack) ifFalse:[ |
|
1430 |
"/ val := projectPack localAt:aKey. |
|
1431 |
"/ val notNil ifTrue:[^ projectPack]. |
|
1432 |
"/ alreadySearched add:projectPack. |
|
1433 |
"/ ]. |
|
1434 |
"/ ]. |
|
1435 |
"/ pack := pack superPack |
|
1436 |
"/ ]. |
|
1437 |
"/ |
|
1438 |
"/ alreadySearched copy do:[:projectPack | |
|
1439 |
"/ |p| |
|
1440 |
"/ |
|
1441 |
"/ p := projectPack superPack. |
|
1442 |
"/ [p notNil and:[(alreadySearched includes:p) not]] whileTrue:[ |
|
1443 |
"/ val := p localAt:aKey. |
|
1444 |
"/ val notNil ifTrue:[^ p]. |
|
1445 |
"/ alreadySearched add:p. |
|
1446 |
"/ p := p superPack. |
|
1447 |
"/ ]. |
|
1448 |
"/ ]. |
|
1449 |
"/ |
|
1450 |
"/ ^ nil |
|
0 | 1451 |
! ! |
1452 |
||
3317 | 1453 |
!ResourcePack methodsFor:'accessing-internals'! |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1454 |
|
8510 | 1455 |
addSuperPack:anotherResourcePack |
1456 |
(anotherResourcePack == self) ifTrue:[ |
|
1457 |
^ self |
|
1458 |
]. |
|
1459 |
superPacks isNil ifTrue:[ superPacks := OrderedCollection new ]. |
|
1460 |
(superPacks includes:anotherResourcePack) ifFalse:[ |
|
1461 |
self assert:(anotherResourcePack isKindOf:ResourcePack). |
|
1462 |
superPacks add:anotherResourcePack |
|
1463 |
]. |
|
1464 |
! |
|
1465 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1466 |
name:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1467 |
"translate a string" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1468 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1469 |
^ self at:aKey ifAbsent:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1470 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1471 |
|
8517 | 1472 |
packsFileName |
1473 |
^ packsFileName |
|
1474 |
! |
|
1475 |
||
1476 |
packsPackage |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1477 |
^ packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1478 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1479 |
|
8517 | 1480 |
packsPackage:aPackage |
1481 |
packsClassName := aPackage |
|
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1482 |
! |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1483 |
|
4617 | 1484 |
projectPack |
1485 |
^ projectPack |
|
1486 |
||
1487 |
"Created: / 18-09-2006 / 17:38:07 / cg" |
|
1488 |
! |
|
1489 |
||
8510 | 1490 |
superPacks |
1491 |
^ superPacks ? #() |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1492 |
! ! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1493 |
|
0 | 1494 |
!ResourcePack methodsFor:'file reading'! |
1495 |
||
684 | 1496 |
fileReadFailed |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1497 |
"return true, if the pack does not really contain |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1498 |
valid translations, since the fileRead failed. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1499 |
However, all inherited translations are still available |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1500 |
through the receiver" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1501 |
|
687 | 1502 |
^ fileReadFailed ~~ false |
684 | 1503 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1504 |
"Created: / 14.5.1996 / 10:19:26 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1505 |
"Modified: / 29.1.1998 / 22:46:38 / cg" |
684 | 1506 |
! |
1507 |
||
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1508 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1509 |
"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
|
1510 |
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
|
1511 |
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
|
1512 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1513 |
^ nil |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1514 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1515 |
"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
|
1516 |
! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1517 |
|
4332 | 1518 |
processLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError |
145 | 1519 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
1520 |
||
4509 | 1521 |
self class |
8462 | 1522 |
processResourceLine:lineString |
1523 |
encoding:encodingSymbolOrEncoder |
|
1524 |
file:fileName |
|
1525 |
printErrorWith:printError |
|
1526 |
for:self |
|
144 | 1527 |
! |
1528 |
||
244 | 1529 |
readFromFile:fileName directory:dirName |
1530 |
"read definitions from a file in a directory" |
|
1531 |
||
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1532 |
|triedFilename inStream ok| |
244 | 1533 |
|
686 | 1534 |
fileReadFailed := false. |
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1535 |
"/ 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
|
1536 |
"/ (happens when da.rs is not present in libbasic/resources.rs) |
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1537 |
ExternalStream openErrorSignal handle:[:ex | |
8462 | 1538 |
Transcript showCR:'ResourcePack: failed to open file: ',fileName asString,' in ',dirName asString. |
1539 |
inStream := nil. |
|
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1540 |
] do:[ |
8462 | 1541 |
dirName = 'resources' ifTrue:[ |
1542 |
inStream := Smalltalk resourceFileStreamFor:fileName |
|
1543 |
] ifFalse:[ |
|
1544 |
inStream := Smalltalk systemFileStreamFor: |
|
1545 |
(dirName isNil |
|
1546 |
ifTrue:[fileName] |
|
1547 |
ifFalse:[dirName asFilename construct:fileName]). |
|
1548 |
]. |
|
244 | 1549 |
]. |
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1550 |
|
8515 | 1551 |
"/ '7) inStream ' print. inStream printCR. |
8512 | 1552 |
|
244 | 1553 |
inStream isNil ifTrue:[ |
8462 | 1554 |
" |
1555 |
an empty pack |
|
1556 |
" |
|
1557 |
^ self nonexistingFileRead |
|
244 | 1558 |
]. |
2996 | 1559 |
|
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1560 |
triedFilename := inStream pathName. |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1561 |
[ |
8462 | 1562 |
ok := self readFromResourceStream:inStream in:(triedFilename asFilename directoryName). |
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1563 |
] ensure:[ |
8462 | 1564 |
inStream close. |
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1565 |
]. |
686 | 1566 |
|
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1567 |
ok ifTrue:[ |
8462 | 1568 |
packsFileName := triedFilename |
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1569 |
] ifFalse:[ |
8462 | 1570 |
fileReadFailed := true. |
684 | 1571 |
|
8462 | 1572 |
('ResourcePack [warning]: "' , triedFilename , '" contains error(s) - data may be incomplete.') errorPrintCR. |
244 | 1573 |
]. |
1574 |
||
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1575 |
"Modified: / 20-08-2011 / 17:10:02 / cg" |
244 | 1576 |
! |
1577 |
||
72 | 1578 |
readFromResourceStream:inStream in:dirName |
4848 | 1579 |
"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
|
1580 |
specify where #include files are searched for. |
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1581 |
Return true, if the style sheet could be read without errors, false otherwise." |
145 | 1582 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1583 |
|lineString l lineNumber rest value ifLevel skipping first ok encoding decoder pack errorHandler |
4947 | 1584 |
printError fileName pushedSkipValues| |
4058 | 1585 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1586 |
fileName := (inStream isFileStream |
6992 | 1587 |
ifTrue:[inStream pathName asFilename baseName] |
1588 |
ifFalse:['---']). |
|
4058 | 1589 |
|
1590 |
printError := [:message | |
|
6992 | 1591 |
'ResourcePack [warning]: ' errorPrint. |
1592 |
message errorPrint. |
|
1593 |
' in file:' errorPrint. |
|
1594 |
fileName errorPrint. |
|
1595 |
' line: ' errorPrint. |
|
1596 |
lineNumber errorPrintCR |
|
1597 |
]. |
|
4058 | 1598 |
|
1599 |
printError := [:message | ]. |
|
462
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1600 |
|
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1601 |
encoding := nil. |
0 | 1602 |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1603 |
ok := true. |
0 | 1604 |
ifLevel := 0. |
1605 |
skipping := false. |
|
4058 | 1606 |
lineNumber := 0. |
4947 | 1607 |
pushedSkipValues := OrderedCollection new. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1608 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1609 |
errorHandler := [:ex | |
6992 | 1610 |
|con| |
4947 | 1611 |
|
6992 | 1612 |
Transcript showCR:('ResourcePack [warning]: ''' , ex description , '''') "errorPrintCR". |
1613 |
Transcript showCR:('ResourcePack [info]: file: ' , inStream pathName printString , ' line: ' , lineNumber printString , ': ''' , lineString , '''') "errorPrintCR". |
|
1614 |
con := ex suspendedContext. |
|
1615 |
Transcript showCR:('ResourcePack [info]: in: ' , con fullPrintString) "errorPrintCR". |
|
1616 |
con := con sender. |
|
1617 |
Transcript showCR:('ResourcePack [info]: : ' , con fullPrintString) "errorPrintCR". |
|
1618 |
20 timesRepeat:[ |
|
1619 |
con notNil ifTrue:[ |
|
1620 |
con := con sender. |
|
1621 |
Transcript showCR:('ResourcePack [info]: : ' , con fullPrintString) "errorPrintCR". |
|
1622 |
]. |
|
1623 |
]. |
|
1624 |
value := nil. |
|
1625 |
ok := false. |
|
1626 |
]. |
|
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1627 |
|
0 | 1628 |
[inStream atEnd] whileFalse:[ |
6992 | 1629 |
lineString := inStream nextLine. lineNumber := lineNumber + 1. |
1630 |
[lineString notNil and:[lineString endsWith:$\]] whileTrue:[ |
|
1631 |
lineString := lineString copyButLast:1. |
|
1632 |
l := inStream nextLine. lineNumber := lineNumber + 1. |
|
1633 |
l notNil ifTrue:[ |
|
1634 |
lineString := lineString , l. |
|
1635 |
]. |
|
1636 |
]. |
|
177 | 1637 |
|
6992 | 1638 |
(lineString size > 0) ifTrue:[ |
1639 |
first := lineString at:1. |
|
1640 |
"/ |
|
1641 |
"/ for your convenience: treat both ';' AND '"/' as comment-line |
|
1642 |
"/ |
|
1643 |
((first == $;) or:[lineString startsWith:'"/']) ifFalse:[ |
|
1644 |
((first == $#) and:[(lineString startsWith:'#(') not]) ifTrue:[ |
|
1645 |
"/ a directive |
|
1646 |
lineString := (lineString copyFrom:2) withoutSpaces. |
|
72 | 1647 |
|
6992 | 1648 |
(lineString startsWith:'if') ifTrue:[ |
1649 |
pushedSkipValues add:skipping. |
|
1650 |
skipping ifFalse:[ |
|
1651 |
rest := lineString copyFrom:3. |
|
1652 |
Error, UserInformation |
|
1653 |
handle:errorHandler |
|
1654 |
do:[ |
|
1655 |
value := Compiler evaluate:rest compile:false. |
|
1656 |
]. |
|
1657 |
(value == #Error) ifTrue:[ |
|
1658 |
printError value:('error in resource:' , lineString). |
|
1659 |
]. |
|
1660 |
(value == false) ifTrue:[ |
|
1661 |
skipping := true |
|
1662 |
] |
|
1663 |
]. |
|
1664 |
ifLevel := ifLevel + 1 |
|
1665 |
] ifFalse:[ |
|
1666 |
(lineString startsWith:'endif') ifTrue:[ |
|
1667 |
ifLevel == 0 ifTrue:[ |
|
1668 |
printError value:('if/endif nesting error'). |
|
1669 |
] ifFalse:[ |
|
1670 |
ifLevel := ifLevel - 1. |
|
1671 |
skipping := pushedSkipValues removeLast. |
|
1672 |
] |
|
1673 |
] ifFalse:[ |
|
1674 |
(lineString startsWith:'else') ifTrue:[ |
|
1675 |
(pushedSkipValues includes:true) ifFalse:[ |
|
1676 |
skipping := skipping not |
|
1677 |
] |
|
1678 |
] ifFalse:[ |
|
1679 |
skipping ifFalse:[ |
|
1680 |
(lineString startsWith:'superpack') ifTrue:[ |
|
1681 |
rest := lineString copyFrom:('superpack' size + 1). |
|
1682 |
value := Compiler evaluate:rest compile:false. |
|
1683 |
(value isKindOf:ResourcePack) ifTrue:[ |
|
8517 | 1684 |
self addSuperPack:value. |
6992 | 1685 |
] |
1686 |
] ifFalse:[ |
|
1687 |
(lineString startsWith:'include') ifTrue:[ |
|
1688 |
(lineString startsWith:'includeResourcesFor') ifTrue:[ |
|
1689 |
"/ include those resources ... |
|
1690 |
rest := lineString copyFrom:('includeResourcesFor' size + 1). |
|
1691 |
value := Compiler evaluate:rest compile:false. |
|
1692 |
value isBehavior ifTrue:[ |
|
1693 |
pack := self class for:value. |
|
1694 |
pack notNil ifTrue:[ |
|
1695 |
self addAll:pack. |
|
1696 |
] |
|
1697 |
] |
|
1698 |
] ifFalse:[ |
|
1699 |
rest := lineString copyFrom:('include' size + 1). |
|
1700 |
value := Compiler evaluate:rest compile:false. |
|
1701 |
value isString ifFalse:[ |
|
1702 |
printError value:('bad include filename: ' , value printString, ' "',lineString,'"'). |
|
1703 |
] ifTrue:[ |
|
1704 |
self readFromFile:value directory:dirName |
|
1705 |
] |
|
1706 |
] |
|
1707 |
] ifFalse:[ |
|
1708 |
(lineString startsWith:'encoding') ifTrue:[ |
|
4848 | 1709 |
"/decoder notNil ifTrue:[self halt:'oops - encoding change in file']. |
6992 | 1710 |
encoding := self class extractEncodingFromLine:lineString. |
1711 |
decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil. |
|
1712 |
] |
|
1713 |
] |
|
1714 |
] |
|
1715 |
] |
|
1716 |
] |
|
1717 |
] |
|
1718 |
]. |
|
1719 |
] ifFalse:[ |
|
1720 |
skipping ifFalse:[ |
|
1721 |
Error, UserInformation |
|
1722 |
handle:errorHandler |
|
1723 |
do:[ |
|
1724 |
(lineString at:1) == $!! ifTrue:[ |
|
1725 |
"/ evaluate the rest |
|
1726 |
Compiler evaluate:(lineString copyFrom:2) |
|
1727 |
receiver:self |
|
1728 |
notifying:nil |
|
1729 |
compile:false. |
|
1730 |
] ifFalse:[ |
|
1731 |
"/ process as resource |
|
1732 |
self |
|
1733 |
processLine:lineString |
|
1734 |
encoding:decoder |
|
1735 |
file:(inStream isFileStream |
|
1736 |
ifTrue:[inStream pathName] |
|
1737 |
ifFalse:['---']) |
|
1738 |
printErrorWith:printError |
|
1739 |
]] |
|
1740 |
] |
|
1741 |
] |
|
1742 |
] |
|
1743 |
] |
|
0 | 1744 |
]. |
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1745 |
^ ok |
177 | 1746 |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
1747 |
"Modified: / 31-08-1995 / 02:33:45 / claus" |
4619 | 1748 |
"Modified: / 18-09-2006 / 20:35:37 / cg" |
8496 | 1749 |
"Modified: / 10-10-2018 / 14:14:00 / sr" |
0 | 1750 |
! ! |
1751 |
||
8509 | 1752 |
|
4093 | 1753 |
!ResourcePack methodsFor:'printing & storing'! |
1754 |
||
5603
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1755 |
displayOn:aGCOrStream |
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1756 |
|
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1757 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
7931 | 1758 |
"/ old ST80 means: draw-yourself on a GC. |
1759 |
(aGCOrStream isStream) ifFalse:[ |
|
1760 |
^ super displayOn:aGCOrStream |
|
5603
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1761 |
]. |
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1762 |
|
7931 | 1763 |
aGCOrStream nextPutAll:'ResourcePack for: '. |
1764 |
packsClassName printOn:aGCOrStream. |
|
1765 |
||
1766 |
"Modified: / 22-02-2017 / 17:00:31 / cg" |
|
4093 | 1767 |
! ! |
1768 |
||
8461 | 1769 |
!ResourcePack methodsFor:'statistics'! |
1770 |
||
1771 |
forgetUsedKeys |
|
1772 |
"stop keeping a statistic on which keys are actually used" |
|
1773 |
||
1774 |
usedKeys := nil. |
|
1775 |
||
1776 |
"Modified (comment): / 12-09-2018 / 18:23:27 / Claus Gittinger" |
|
1777 |
! |
|
1778 |
||
1779 |
rememberUsedKeys |
|
1780 |
"start keeping a statistic on which keys are actually used" |
|
1781 |
||
1782 |
usedKeys := Set new. |
|
1783 |
||
1784 |
"Modified (comment): / 12-09-2018 / 18:23:22 / Claus Gittinger" |
|
1785 |
! |
|
1786 |
||
1787 |
usedKeys |
|
1788 |
"get keys which were actually used. |
|
1789 |
(must call #rememberUsedKeys before)" |
|
1790 |
||
1791 |
^ usedKeys |
|
1792 |
||
1793 |
"Created: / 12-09-2018 / 18:24:26 / Claus Gittinger" |
|
1794 |
! ! |
|
1795 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
1796 |
!ResourcePack class methodsFor:'documentation'! |
251 | 1797 |
|
1798 |
version |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1799 |
^ '$Header$' |
5357 | 1800 |
! |
1801 |
||
1802 |
version_CVS |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1803 |
^ '$Header$' |
251 | 1804 |
! ! |
3769 | 1805 |
|
6051
f01078ce8c2c
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
5951
diff
changeset
|
1806 |
|
0 | 1807 |
ResourcePack initialize! |