author | Stefan Vogel <sv@exept.de> |
Tue, 12 Feb 2019 20:50:10 +0100 | |
changeset 8625 | beec97e88a69 |
parent 8599 | da233078d5a1 |
child 8627 | 13114f8fe406 |
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 |
||
8599 | 340 |
|pack lang territory| |
341 |
||
342 |
pack := self forPackage:package resourceFileName:'resources.rs' cached:cached defaultIfAbsent:false. |
|
343 |
pack isNil ifTrue:[ |
|
344 |
lang := Smalltalk language. |
|
345 |
territory := Smalltalk languageTerritory. |
|
346 |
pack := self forPackage:package resourceFileName:(lang,'_',territory,'.rs') cached:cached defaultIfAbsent:false. |
|
347 |
pack isNil ifTrue:[ |
|
348 |
pack := self forPackage:package resourceFileName:(lang,'.rs') cached:cached defaultIfAbsent:false. |
|
349 |
pack isNil ifTrue:[ |
|
350 |
pack := self newDefaultResourcePackForPackage:package. |
|
351 |
self addAdditionalSuperPacksForPackage:package to:pack. |
|
352 |
]. |
|
353 |
] |
|
354 |
]. |
|
355 |
^ pack |
|
356 |
||
4673 | 357 |
" |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
358 |
ResourcePack forPackage:'stx:libbasic' cached:false |
8599 | 359 |
ResourcePack forPackage:'exept:expecco/plugin/windowsAutomation2' cached:false |
4673 | 360 |
" |
361 |
||
362 |
"Modified: / 19-10-2006 / 23:18:28 / cg" |
|
8599 | 363 |
"Modified: / 13-12-2018 / 13:24:56 / Claus Gittinger" |
4673 | 364 |
! |
365 |
||
366 |
forPackage:package resourceFileName:resourceFileName cached:cached |
|
367 |
"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
|
368 |
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
|
369 |
Remember failed packs, to avoid retrying reading the file again and again" |
4673 | 370 |
|
8599 | 371 |
^ self |
372 |
forPackage:package |
|
373 |
resourceFileName:resourceFileName |
|
374 |
cached:cached |
|
375 |
defaultIfAbsent:true |
|
376 |
||
377 |
" |
|
378 |
ResourcePack flushCachedResourcePacks. |
|
379 |
||
380 |
ResourcePack |
|
381 |
forPackage:'stx:libbasic' |
|
382 |
resourceFileName:'resources.rs' |
|
383 |
cached:false |
|
384 |
" |
|
385 |
||
386 |
"Modified: / 28-09-2011 / 15:55:30 / cg" |
|
387 |
"Modified: / 13-12-2018 / 13:17:00 / Claus Gittinger" |
|
388 |
! |
|
389 |
||
390 |
forPackage:package resourceFileName:resourceFileName cached:cached defaultIfAbsent:defaultIfAbsentBoolean |
|
391 |
"get the full resource definitions given a package id (such as stx:libbasic'). |
|
392 |
Also optionally leave the resulting pack in the cache for faster access next time. |
|
393 |
Remember failed packs, to avoid retrying reading the file again and again" |
|
394 |
||
4428 | 395 |
|fullName pack rsrcDir file| |
4078 | 396 |
|
8517 | 397 |
package isNil ifTrue:[ |
398 |
'[ResourcePack] warning: nil package asking for resource file'. |
|
8599 | 399 |
defaultIfAbsentBoolean ifFalse:[^ nil]. |
8544 | 400 |
^ self newDefaultResourcePackForPackage:package |
8517 | 401 |
]. |
402 |
||
8510 | 403 |
fullName := (package copyReplaceAll:$: with:$/),'/resources/',resourceFileName. |
4078 | 404 |
|
405 |
cached ifTrue:[ |
|
8462 | 406 |
pack := self searchCacheFor:fullName. |
407 |
pack notNil ifTrue:[^ pack]. |
|
8520 | 408 |
|
8517 | 409 |
(FailedToLoadPacks includes:fullName) ifTrue:[ |
8520 | 410 |
"/ it already failed to load - do not try again |
8599 | 411 |
defaultIfAbsentBoolean ifFalse:[^ nil]. |
8544 | 412 |
pack := self newDefaultResourcePackForPackage:package. |
8520 | 413 |
self addAdditionalSuperPacksForPackage:package to:pack. |
414 |
^ pack |
|
8517 | 415 |
]. |
4078 | 416 |
]. |
417 |
||
8510 | 418 |
"/ Smalltalk projectDirectoryForPackage:'stx:libview' |
4078 | 419 |
rsrcDir := Smalltalk projectDirectoryForPackage:package. |
8514 | 420 |
"/ '1) projectDirectoryForPackage -> ' print. |
421 |
"/ rsrcDir printCR. |
|
8517 | 422 |
rsrcDir notNil ifTrue:[ |
423 |
rsrcDir := rsrcDir asFilename / 'resources'. |
|
8514 | 424 |
"/ '3) rsrcDir -> ' print. |
425 |
"/ rsrcDir printCR. |
|
8517 | 426 |
rsrcDir exists ifTrue:[ |
8599 | 427 |
(rsrcDir / resourceFileName) exists ifTrue:[ |
428 |
pack := self fromFile:resourceFileName directory:rsrcDir cached:cached. |
|
429 |
pack packsPackage:package. |
|
430 |
self addAdditionalSuperPacksForPackage:package to:pack. |
|
431 |
^ pack |
|
432 |
]. |
|
8462 | 433 |
]. |
8517 | 434 |
]. |
435 |
||
436 |
file := Smalltalk getResourceFileName:resourceFileName forPackage:package. |
|
8519 | 437 |
(file notNil and:[(file := file asFilename) exists]) ifTrue:[ |
438 |
rsrcDir := file directory. |
|
8517 | 439 |
pack := self fromFile:resourceFileName directory:rsrcDir cached:cached. |
440 |
pack packsPackage:package. |
|
8520 | 441 |
self addAdditionalSuperPacksForPackage:package to:pack. |
8517 | 442 |
^ pack |
4428 | 443 |
]. |
8517 | 444 |
|
445 |
FailedToLoadPacks add:fullName. |
|
8599 | 446 |
defaultIfAbsentBoolean ifFalse:[^ nil]. |
8544 | 447 |
pack := self newDefaultResourcePackForPackage:package. |
8520 | 448 |
self addAdditionalSuperPacksForPackage:package to:pack. |
449 |
^ pack |
|
4078 | 450 |
|
451 |
" |
|
8517 | 452 |
ResourcePack flushCachedResourcePacks. |
453 |
||
8510 | 454 |
ResourcePack |
455 |
forPackage:'stx:libbasic' |
|
456 |
resourceFileName:'resources.rs' |
|
457 |
cached:false |
|
4078 | 458 |
" |
4656 | 459 |
|
8599 | 460 |
"Created: / 13-12-2018 / 13:16:36 / Claus Gittinger" |
4078 | 461 |
! |
462 |
||
244 | 463 |
fromFile:aFileName |
4611 | 464 |
"get the resource definitions from a file in the default directory." |
244 | 465 |
|
466 |
^ self fromFile:aFileName directory:'resources' |
|
467 |
||
468 |
" |
|
469 |
ResourcePack fromFile:'SBrowser.rs' |
|
470 |
ResourcePack fromFile:'FBrowser.rs' |
|
471 |
ResourcePack fromFile:'Smalltalk.rs' |
|
3678 | 472 |
ResourcePack fromFile:'Smalltalk.rs' asFilename |
3983 | 473 |
ResourcePack fromFile:'../../libtool/resources/AboutBox_ru.rs' asFilename |
244 | 474 |
" |
475 |
! |
|
476 |
||
477 |
fromFile:aFileName directory:dirName |
|
4611 | 478 |
"get the resource definitions from a file in a directory." |
479 |
||
480 |
^ self fromFile:aFileName directory:dirName cached:false |
|
481 |
! |
|
482 |
||
483 |
fromFile:aFileName directory:dirName cached:cached |
|
244 | 484 |
"get the resource definitions from a file in a directory. |
485 |
Uncached low-level entry." |
|
486 |
||
8483 | 487 |
|cachedPack newPack fn| |
244 | 488 |
|
8483 | 489 |
fn := (dirName asFilename / aFileName) pathName. |
490 |
cachedPack := Packs detect:[:p | p notNil and:[p isInteger not and:[p packsFileName = fn]]] ifNone:nil. |
|
491 |
cachedPack notNil ifTrue:[ |
|
492 |
"/ Transcript showCR:'cached pack: ',fn asString. |
|
493 |
^ cachedPack |
|
494 |
]. |
|
495 |
||
244 | 496 |
newPack := self new. |
7388 | 497 |
KeepStatisticsOnUsedKeys == true ifTrue:[ |
498 |
newPack rememberUsedKeys. |
|
499 |
]. |
|
8514 | 500 |
"/ '5) file ' print. aFileName print. |
501 |
"/ ' in ' print. dirName printCR. |
|
244 | 502 |
newPack readFromFile:aFileName directory:dirName. |
4611 | 503 |
cached ifTrue:[ |
7388 | 504 |
self addToCache:newPack. |
4611 | 505 |
]. |
244 | 506 |
^ newPack |
8483 | 507 |
|
508 |
"Modified: / 25-09-2018 / 09:57:42 / Claus Gittinger" |
|
8520 | 509 |
! |
510 |
||
8546 | 511 |
newDefaultResourcePackForPackage:package |
8548 | 512 |
|rsrcs superPack| |
8520 | 513 |
|
514 |
rsrcs := ResourcePack new. |
|
8546 | 515 |
|
8548 | 516 |
package = 'stx:libtool' ifTrue:[ |
517 |
superPack := self forPackage:'stx:libview'. |
|
518 |
superPack notNil ifTrue:[ rsrcs addSuperPack:superPack ]. |
|
8544 | 519 |
]. |
520 |
^ rsrcs |
|
521 |
||
522 |
"Created: / 24-10-2018 / 18:07:25 / Claus Gittinger" |
|
8548 | 523 |
"Modified: / 25-10-2018 / 02:36:04 / Claus Gittinger" |
0 | 524 |
! ! |
525 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
526 |
!ResourcePack class methodsFor:'private'! |
54 | 527 |
|
528 |
addToCache:aPack |
|
529 |
|idx| |
|
0 | 530 |
|
4084 | 531 |
Packs isNil ifTrue:[ |
8462 | 532 |
self initialize. |
4084 | 533 |
]. |
534 |
||
54 | 535 |
idx := Packs identityIndexOf:nil. |
536 |
idx == 0 ifTrue:[ |
|
8462 | 537 |
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
|
538 |
]. |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
539 |
idx == 0 ifTrue:[ |
8462 | 540 |
" |
541 |
throw away oldest |
|
542 |
" |
|
543 |
idx := Packs size. |
|
544 |
Packs replaceFrom:1 to:idx-1 with:Packs startingAt:2. |
|
54 | 545 |
]. |
5357 | 546 |
aPack at:'__language__' put:(UserPreferences current language,'_',UserPreferences current languageTerritory). |
4619 | 547 |
Packs at:idx put:aPack. |
548 |
||
549 |
"Modified: / 18-09-2006 / 19:12:12 / cg" |
|
54 | 550 |
! |
0 | 551 |
|
8517 | 552 |
searchCacheFor:aPackageName |
4619 | 553 |
|sz "{ Class: SmallInteger }" lang| |
0 | 554 |
|
24 | 555 |
Packs isNil ifTrue:[ |
8462 | 556 |
self initialize. |
557 |
^ nil |
|
0 | 558 |
]. |
54 | 559 |
|
5357 | 560 |
lang := (UserPreferences current language,'_',UserPreferences current languageTerritory). |
4619 | 561 |
|
54 | 562 |
sz := Packs size. |
563 |
1 to:sz do:[:idx | |
|
8462 | 564 |
|aPack| |
54 | 565 |
|
8462 | 566 |
aPack := Packs at:idx. |
567 |
(aPack notNil and:[aPack class ~~ SmallInteger]) ifTrue:[ |
|
568 |
(aPack at:'__language__' ifAbsent:nil) = lang ifTrue:[ |
|
8517 | 569 |
aPackageName = aPack packsPackage ifTrue:[ |
8462 | 570 |
" |
571 |
bring to front for LRU |
|
572 |
" |
|
573 |
idx ~~ 1 ifTrue:[ |
|
574 |
Packs replaceFrom:2 to:idx with:Packs startingAt:1. |
|
575 |
Packs at:1 put:aPack. |
|
576 |
]. |
|
577 |
^ aPack |
|
578 |
] |
|
579 |
] |
|
580 |
] |
|
0 | 581 |
]. |
54 | 582 |
^ nil |
123 | 583 |
|
584 |
" |
|
8517 | 585 |
ResourcePack searchCacheFor:'stx:libview' |
123 | 586 |
" |
4619 | 587 |
|
588 |
"Modified: / 18-09-2006 / 19:13:13 / cg" |
|
54 | 589 |
! ! |
590 |
||
4509 | 591 |
!ResourcePack class methodsFor:'utilities'! |
592 |
||
593 |
extractEncodingFromLine:lineString |
|
594 |
|rest encoding| |
|
595 |
||
596 |
(lineString startsWith:'encoding') ifFalse:[^ nil]. |
|
597 |
||
598 |
rest := lineString copyFrom:9. |
|
599 |
rest := rest withoutSeparators. |
|
600 |
(rest startsWith:'#') ifTrue:[ |
|
8462 | 601 |
rest := rest copyFrom:2. |
4509 | 602 |
]. |
603 |
(rest startsWith:'''') ifTrue:[ |
|
8462 | 604 |
rest := rest copyFrom:2. |
605 |
(rest endsWith:'''') ifTrue:[ |
|
606 |
rest := rest copyButLast:1. |
|
607 |
]. |
|
4509 | 608 |
]. |
609 |
encoding := rest asSymbol. |
|
610 |
^ encoding. |
|
611 |
! |
|
612 |
||
613 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack |
|
614 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
|
615 |
||
4510 | 616 |
self |
8462 | 617 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack |
618 |
keepUselessTranslations:false. |
|
4510 | 619 |
! |
620 |
||
621 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack keepUselessTranslations:keepUselessTranslations |
|
622 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
|
623 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
624 |
|name lineStream idx rest macroName value |
4670 | 625 |
conditional hasError decoder oldValue ignoreTranslation indirect| |
4509 | 626 |
|
6250 | 627 |
"/ Transcript showCR:lineString. |
4531 | 628 |
encodingSymbolOrEncoder notNil ifTrue:[ |
8462 | 629 |
encodingSymbolOrEncoder isSymbol ifTrue:[ |
630 |
decoder := CharacterEncoder encoderFor:encodingSymbolOrEncoder ifAbsent:nil. |
|
631 |
decoder isNil ifTrue:[ decoder := CharacterEncoder nullEncoderInstance ]. |
|
632 |
] ifFalse:[ |
|
633 |
decoder := encodingSymbolOrEncoder |
|
634 |
]. |
|
4531 | 635 |
]. |
636 |
||
637 |
decoder notNil ifTrue:[ |
|
8462 | 638 |
lineStream := (decoder decodeString:lineString) readStream. |
4531 | 639 |
] ifFalse:[ |
8462 | 640 |
lineStream := lineString readStream. |
4531 | 641 |
]. |
4509 | 642 |
lineStream signalAtEnd:false. |
643 |
lineStream skipSeparators. |
|
5080 | 644 |
|
4509 | 645 |
lineStream peek == $# ifTrue:[ |
8462 | 646 |
name := Array |
647 |
readFrom:lineStream |
|
648 |
onError:[ |
|
649 |
printError value:('invalid line <' , lineString , '>'). |
|
650 |
nil |
|
651 |
]. |
|
4509 | 652 |
] ifFalse:[ |
8462 | 653 |
lineStream peek == $' ifTrue:[ |
654 |
name := String |
|
655 |
readSmalltalkStringFrom:lineStream |
|
656 |
onError:[ |
|
657 |
printError value:('invalid line <' , lineString , '>'). |
|
658 |
nil |
|
659 |
]. |
|
660 |
] ifFalse:[ |
|
661 |
name := lineStream upToSeparator. |
|
662 |
]. |
|
4509 | 663 |
]. |
664 |
||
4510 | 665 |
name isNil ifTrue:[^ self ]. |
666 |
||
667 |
ignoreTranslation := false. |
|
668 |
hasError := false. |
|
4509 | 669 |
|
4510 | 670 |
lineStream skipSeparators. |
6113 | 671 |
idx := lineStream position + 1 + 1. |
4510 | 672 |
|
673 |
lineStream peek == $< ifTrue:[ |
|
8462 | 674 |
" |
675 |
skip <type> if present |
|
676 |
" |
|
677 |
lineStream skipThrough:$>. |
|
678 |
lineStream skipSeparators. |
|
679 |
idx := lineStream position + 2. |
|
4510 | 680 |
]. |
4509 | 681 |
|
4670 | 682 |
conditional := indirect := false. |
4510 | 683 |
lineStream peek == $? ifTrue:[ |
8462 | 684 |
conditional := true. |
685 |
lineStream next. |
|
686 |
lineStream skipSeparators. |
|
4670 | 687 |
]. |
688 |
||
689 |
lineStream peek == $@ ifTrue:[ |
|
8462 | 690 |
indirect := true. |
691 |
lineStream next. |
|
692 |
lineStream skipSeparators. |
|
4510 | 693 |
]. |
4509 | 694 |
|
4510 | 695 |
lineStream peek == $= ifTrue:[ |
8462 | 696 |
lineStream next. |
4510 | 697 |
|
8462 | 698 |
macroName := lineStream nextAlphaNumericWord. |
699 |
[lineStream peek == $.] whileTrue:[ |
|
700 |
lineStream next. |
|
701 |
lineStream peek notNil ifTrue:[ |
|
702 |
macroName := macroName , '.' , (lineStream nextAlphaNumericWord) |
|
703 |
] |
|
704 |
]. |
|
705 |
rest := lineStream upToEnd. |
|
706 |
value := aResourcePack at:macroName ifAbsent:nil. |
|
707 |
(value isNil) ifTrue:[ |
|
708 |
hasError := true. |
|
709 |
printError value:('bad (nil-valued) macro: ' , macroName). |
|
710 |
]. |
|
4678
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
711 |
"/ value isBlock ifTrue:[ |
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
712 |
"/ value := value value |
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
713 |
"/ ]. |
8462 | 714 |
rest isBlank ifFalse:[ |
715 |
value := Compiler evaluate:('self ' , rest) |
|
716 |
receiver:value |
|
717 |
notifying:nil |
|
718 |
compile:false. |
|
719 |
(value == #Error) ifTrue:[ |
|
720 |
hasError := true. |
|
721 |
printError value:('error in: "self ' , rest , '"'). |
|
722 |
]. |
|
723 |
"/ 'self ' print. rest print. ' -> ' print. value printCR. |
|
724 |
] |
|
4510 | 725 |
] ifFalse:[ |
8462 | 726 |
lineStream peek == $' ifTrue:[ |
727 |
value := String |
|
728 |
readSmalltalkStringFrom:lineStream |
|
729 |
onError:[ |
|
730 |
printError value:('invalid line <' , lineString , '>'). |
|
731 |
nil |
|
732 |
]. |
|
733 |
"/ ' -> ' print. value printCR. |
|
734 |
] ifFalse:[ |
|
735 |
rest := lineStream upToEnd. |
|
736 |
[ |
|
737 |
value := Compiler evaluate:rest compile:"true" false. |
|
738 |
] on:Error do:[ |
|
8476 | 739 |
printError value:('invalid line <' , lineString , '>'). |
8462 | 740 |
"/ value := rest |
741 |
]. |
|
742 |
"/ rest print. ' -> ' print. value printCR. |
|
743 |
]. |
|
744 |
(value == #Error) ifTrue:[ |
|
745 |
hasError := true. |
|
746 |
printError value:('error in: "' , rest , '"'). |
|
747 |
] ifFalse:[ |
|
4531 | 748 |
"/ value isString ifTrue:[ |
749 |
"/ decoder notNil ifTrue:[ |
|
750 |
"/ value := decoder decodeString:value |
|
751 |
"/ ] |
|
752 |
"/ ] |
|
8462 | 753 |
] |
4510 | 754 |
]. |
755 |
||
5430
128e9b37fd8a
comment/format in: #processResourceLine:encoding:file:printErrorWith:for:
sr
parents:
5370
diff
changeset
|
756 |
"/ Transcript show:name; show:' -> '; showCR:value. |
128e9b37fd8a
comment/format in: #processResourceLine:encoding:file:printErrorWith:for:
sr
parents:
5370
diff
changeset
|
757 |
|
4510 | 758 |
hasError ifFalse:[ |
8462 | 759 |
(conditional not |
760 |
or:[(aResourcePack includesKey:name) not]) ifTrue:[ |
|
761 |
name = value ifTrue:[ |
|
762 |
keepUselessTranslations ifFalse:[ |
|
763 |
printError value:('useless resource: "' , name , '"'). |
|
764 |
ignoreTranslation := true |
|
765 |
]. |
|
766 |
]. |
|
767 |
ignoreTranslation ifFalse:[ |
|
768 |
oldValue := aResourcePack at:name ifAbsent:nil. |
|
769 |
oldValue notNil ifTrue:[ |
|
770 |
oldValue ~= value ifTrue:[ |
|
771 |
printError value:('conflicting resource: "' , name , '"'). |
|
8537 | 772 |
printError value:(' oldValue: ' , oldValue printString). |
773 |
printError value:(' newValue: ' , value printString). |
|
8462 | 774 |
] ifFalse:[ |
775 |
printError value:('duplicate resource: "' , name , '"'). |
|
776 |
]. |
|
777 |
]. |
|
778 |
indirect ifTrue:[ |
|
779 |
value := aResourcePack string:value. |
|
780 |
]. |
|
5431 | 781 |
|
8462 | 782 |
DebugModifications == true ifTrue:[ |
783 |
"/ for debugging only !! (not all primitive code is ready for immutableStrings) |
|
784 |
value class == String ifTrue:[ |
|
785 |
value := value asImmutableString. |
|
786 |
]. |
|
787 |
]. |
|
5431 | 788 |
|
8462 | 789 |
aResourcePack at:name put:value. |
790 |
] |
|
791 |
] |
|
4509 | 792 |
] |
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
793 |
|
6250 | 794 |
"Modified: / 06-02-2014 / 15:33:03 / cg" |
8537 | 795 |
"Modified: / 23-10-2018 / 15:43:38 / Claus Gittinger" |
6661 | 796 |
! |
797 |
||
798 |
resourceFileEntryFor:keyString to:nationalString |
|
799 |
"generate a line for a translation file, which defines a translation |
|
800 |
from keyString to nationalString. |
|
801 |
Naivly, this could be a simple line containing the two storeStrings |
|
802 |
separated by a space. However, it is better to first cut of any leading |
|
803 |
and trailing spaces and special characters, such as ':*.,' etc." |
|
804 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
805 |
^ (self resourceFileStringFor:keyString),' ',(self resourceFileStringFor:nationalString) |
6661 | 806 |
! |
807 |
||
808 |
resourceFileStringFor:aString |
|
809 |
"generate a key or value entry for a translation file, for aString. |
|
810 |
Naivly, this could be a simple the storeString. |
|
811 |
However, it is better to first cut of any leading |
|
812 |
and trailing spaces and special characters, sch as ':*.,' etc." |
|
813 |
||
814 |
^ (self shortenedKeyFor:aString) storeString |
|
815 |
||
816 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
817 |
self resourceFileStringFor:' foo: ' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
818 |
self resourceFileStringFor:' foo bar: ' |
6661 | 819 |
" |
820 |
! |
|
821 |
||
822 |
shortenedKeyFor:aKey |
|
823 |
"if |
|
8462 | 824 |
aKey is '(...)', then return '...' |
825 |
if aKey is '[...]', then return '...' |
|
826 |
if aKey is '{...}', then return '...' |
|
827 |
if aKey starts or ends with any of '\:=.,?!! ', then return aKey without it |
|
6661 | 828 |
|
829 |
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
|
830 |
things like |
8462 | 831 |
'search' |
832 |
'search:' |
|
833 |
'search...' |
|
6661 | 834 |
" |
835 |
||
836 |
|idx idx1 idx2 first last keySize| |
|
837 |
||
838 |
first := aKey first. |
|
839 |
last := aKey last. |
|
840 |
keySize := aKey size. |
|
841 |
||
842 |
((first == $( and:[last == $) ]) |
|
843 |
or:[ (first == $[ and:[last == $] ]) |
|
844 |
or:[ (first == ${ and:[last == $} ]) ]]) ifTrue:[ |
|
8462 | 845 |
^ self shortenedKeyFor:(aKey copyFrom:2 to:keySize-1). |
6661 | 846 |
]. |
847 |
||
848 |
idx1 := aKey findFirst:[:ch | ch isSeparator not]. |
|
849 |
idx2 := aKey findLast:[:ch | ch isSeparator not] ifNone:keySize. |
|
850 |
(idx1 > 1 or:[idx2 < keySize]) ifTrue:[ |
|
8462 | 851 |
^ self shortenedKeyFor:(aKey copyFrom:idx1 to:idx2) |
6661 | 852 |
]. |
853 |
||
854 |
idx1 := aKey findFirst:[:ch | ('*:=.?!!,-><\' includes:ch) not]. |
|
855 |
idx2 := aKey findLast:[:ch | ('*:=.?!!,-><\' includes:ch) not] ifNone:keySize. |
|
856 |
(idx1 > 1 or:[idx2 < keySize]) ifTrue:[ |
|
8462 | 857 |
^ self shortenedKeyFor:(aKey copyFrom:idx1 to:idx2) |
6661 | 858 |
]. |
859 |
||
860 |
"/ change duplicated &'s to single |
|
861 |
(idx := aKey indexOf:$&) ~~ 0 ifTrue:[ |
|
8462 | 862 |
(aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[ |
863 |
^ self shortenedKeyFor:(aKey copyTo:idx-1),(aKey copyFrom:idx+1). |
|
864 |
]. |
|
6661 | 865 |
]. |
866 |
^ aKey. |
|
867 |
||
868 |
" |
|
869 |
'abcde' findFirst:[:ch | 'bcd' includes:ch] |
|
870 |
'abcde' indexOfAny:'bcd' |
|
871 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
872 |
self shortenedKeyFor:'abc' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
873 |
self shortenedKeyFor:' abc ' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
874 |
self shortenedKeyFor:'(abc)' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
875 |
self shortenedKeyFor:'abc...' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
876 |
self shortenedKeyFor:'(abc...)' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
877 |
self shortenedKeyFor:'abc:*' |
6661 | 878 |
" |
4509 | 879 |
! ! |
880 |
||
0 | 881 |
!ResourcePack methodsFor:'accessing'! |
882 |
||
244 | 883 |
array:anArray |
884 |
"translate a collection of strings" |
|
0 | 885 |
|
244 | 886 |
^ anArray collect:[:r | self at:r default:r] |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
887 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
888 |
" |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
889 |
Launcher classResources array:#('file' 'classes') |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
890 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
891 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
892 |
"Modified: / 29.1.1998 / 22:44:22 / cg" |
0 | 893 |
! |
894 |
||
2 | 895 |
at:aKey |
123 | 896 |
"translate a string" |
897 |
||
72 | 898 |
^ self at:aKey ifAbsent:aKey |
0 | 899 |
! |
900 |
||
901 |
at:aKey default:default |
|
123 | 902 |
"translate a string" |
903 |
||
72 | 904 |
^ self at:aKey ifAbsent:default |
0 | 905 |
! |
906 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
907 |
at:aKey ifAbsent:defaultValue |
4617 | 908 |
"translate a string; search here, in my projects pack and in my superpack(s)" |
909 |
||
8516 | 910 |
|val pack projectPack alreadySearched toSearch more| |
4617 | 911 |
|
912 |
aKey isNil ifTrue:[ ^ defaultValue value ]. |
|
913 |
||
8517 | 914 |
usedKeys notNil ifTrue:[usedKeys add:aKey]. |
915 |
||
4617 | 916 |
val := self localAt:aKey. |
917 |
val notNil ifTrue:[^ val]. |
|
918 |
||
8461 | 919 |
cache isNil ifTrue:[ cache := CacheDictionary new:1000 ]. |
920 |
(val := cache at:aKey ifAbsent:nil) notNil ifTrue:[ |
|
921 |
^ val |
|
922 |
]. |
|
923 |
||
8516 | 924 |
superPacks notEmptyOrNil ifTrue:[ |
8510 | 925 |
alreadySearched := Set new. |
926 |
toSearch := OrderedCollection withAll:superPacks. |
|
927 |
[toSearch notEmpty] whileTrue:[ |
|
928 |
pack := toSearch removeFirst. |
|
8556 | 929 |
(alreadySearched includes:pack packsFileName) ifFalse:[ |
8510 | 930 |
val := pack localAt:aKey. |
8461 | 931 |
val notNil ifTrue:[ |
932 |
cache at:aKey put:val. |
|
933 |
^ val |
|
934 |
]. |
|
8556 | 935 |
alreadySearched add:pack packsFileName. |
8516 | 936 |
(more := pack superPacks) notEmptyOrNil ifTrue:[ |
937 |
self assert:(more conform:[:each | each isNil or:[pack isKindOf:ResourcePack]]). |
|
938 |
toSearch addAll:more. |
|
939 |
]. |
|
8461 | 940 |
]. |
941 |
]. |
|
4617 | 942 |
]. |
8510 | 943 |
^ defaultValue value. |
4618 | 944 |
|
8510 | 945 |
"/ (projectPack := self projectPack) notNil ifTrue:[ |
946 |
"/ val := projectPack localAt:aKey. |
|
947 |
"/ val notNil ifTrue:[ |
|
948 |
"/ cache at:aKey put:val. |
|
949 |
"/ ^ val |
|
950 |
"/ ]. |
|
951 |
"/ ]. |
|
952 |
"/ alreadySearched := IdentitySet new. |
|
953 |
"/ projectPack notNil ifTrue:[ alreadySearched add:projectPack ]. |
|
954 |
"/ |
|
955 |
"/ pack := self superPack. |
|
956 |
"/ [ pack notNil ] whileTrue:[ |
|
957 |
"/ val := pack localAt:aKey. |
|
958 |
"/ val notNil ifTrue:[ |
|
959 |
"/ cache at:aKey put:val. |
|
960 |
"/ ^ val |
|
961 |
"/ ]. |
|
962 |
"/ |
|
963 |
"/ (projectPack := pack projectPack) notNil ifTrue:[ |
|
964 |
"/ (alreadySearched includes:projectPack) ifFalse:[ |
|
965 |
"/ val := projectPack localAt:aKey. |
|
966 |
"/ val notNil ifTrue:[ |
|
967 |
"/ cache at:aKey put:val. |
|
968 |
"/ ^ val |
|
969 |
"/ ]. |
|
970 |
"/ alreadySearched add:projectPack. |
|
971 |
"/ ]. |
|
972 |
"/ ]. |
|
973 |
"/ pack := pack superPack |
|
974 |
"/ ]. |
|
975 |
"/ |
|
976 |
"/ alreadySearched copy do:[:projectPack | |
|
977 |
"/ |p| |
|
978 |
"/ |
|
979 |
"/ p := projectPack superPack. |
|
980 |
"/ [p notNil and:[(alreadySearched includes:p) not]] whileTrue:[ |
|
981 |
"/ val := p localAt:aKey. |
|
982 |
"/ val notNil ifTrue:[ |
|
983 |
"/ cache at:aKey put:val. |
|
984 |
"/ ^ val |
|
985 |
"/ ]. |
|
986 |
"/ alreadySearched add:p. |
|
987 |
"/ p := p superPack. |
|
988 |
"/ ]. |
|
989 |
"/ ]. |
|
990 |
"/ |
|
991 |
"/ val := defaultValue value. |
|
992 |
"/ cache at:aKey put:val. |
|
993 |
"/ ^ val |
|
4617 | 994 |
|
4618 | 995 |
"Modified: / 18-09-2006 / 18:50:52 / cg" |
8556 | 996 |
"Modified: / 26-10-2018 / 21:16:15 / Claus Gittinger" |
4617 | 997 |
! |
998 |
||
999 |
localAt:aKey |
|
4035 | 1000 |
"translate a string. |
1001 |
Some special 'intelligence' has been added: |
|
8226 | 1002 |
if no value for aKey is found, |
8565 | 1003 |
lookup aKey with first character caseChanged and change the result's first characters case. |
1004 |
lookup aKey all lowercase and change the result's first characters case. |
|
8226 | 1005 |
or aKey is '(...)', then lookup ... wrap () around the result. |
1006 |
or aKey is '[...]', then lookup ... wrap [] around the result. |
|
1007 |
or aKey is '{...}', then lookup ... wrap {} around the result. |
|
1008 |
or aKey starts with a '\', then lookup aKey without '\' and prepend '\' to the result. |
|
1009 |
or aKey starts with a '*', then lookup aKey without '*' and prepend '*' to the result. |
|
8563 | 1010 |
or aKey starts with a '<', then lookup aKey without '<' and prepend '<' to the result. |
1011 |
or aKey ends with a '>', then lookup aKey without '>' and prepend '>' to the result. |
|
8226 | 1012 |
or aKey ends with a '\', then lookup aKey without '\' and append '\' to the result. |
1013 |
or aKey ends with a ':', then lookup aKey without ':' and append ':' to the result. |
|
1014 |
or aKey ends with a '=', then lookup aKey without '=' and append '=' to the result. |
|
1015 |
or aKey ends with a '.', then lookup aKey without '.' and append '.' to the result. |
|
1016 |
or aKey ends with a ',', then lookup aKey without ',' and append ',' to the result. |
|
1017 |
or aKey ends with a '?', then lookup aKey without '?' and append '?' to the result. |
|
1018 |
or aKey ends with a '!!', then lookup aKey without '!!' and append '!!' to the result. |
|
1019 |
or aKey ends with a '*', then lookup aKey without '*' and append '*' to the result. |
|
1020 |
or aKey ends with a ' ', then lookup aKey without ' ' and append ' ' to the result. |
|
1021 |
or aKey ends with a ' ...', then lookup aKey without ' ...' and append '...' to the result. |
|
1022 |
or aKey ends with a '...', then lookup aKey without '...' and append '...' to the result. |
|
1023 |
or aKey includes '&', then lookup aKey without '&'. |
|
4035 | 1024 |
|
1025 |
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
|
1026 |
things like |
8226 | 1027 |
'search' |
1028 |
'search:' |
|
1029 |
'search...' |
|
4035 | 1030 |
" |
123 | 1031 |
|
5573 | 1032 |
|val alternativeKey usedKey idx first last| |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1033 |
|
4617 | 1034 |
val := super at:aKey ifAbsent:nil. |
4678
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
1035 |
val notNil ifTrue:[ |
8226 | 1036 |
^ val value |
4678
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
1037 |
]. |
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
1038 |
|
4848 | 1039 |
(aKey isString and:[aKey notEmpty]) ifTrue:[ |
8226 | 1040 |
first := aKey first. |
1041 |
last := aKey last. |
|
5573 | 1042 |
|
8226 | 1043 |
"/ try with case-first swapped... |
1044 |
first isLetter ifTrue:[ |
|
1045 |
alternativeKey := first isUppercase |
|
1046 |
ifTrue:[aKey asLowercaseFirst] |
|
1047 |
ifFalse:[aKey asUppercaseFirst]. |
|
1048 |
val := super at:alternativeKey ifAbsent:nil. |
|
1049 |
val notNil ifTrue:[ |
|
1050 |
first isUppercase ifTrue:[ |
|
1051 |
^ val asUppercaseFirst |
|
1052 |
]. |
|
1053 |
^ val asLowercaseFirst. |
|
1054 |
]. |
|
8565 | 1055 |
alternativeKey := aKey asLowercase. |
1056 |
val := super at:alternativeKey ifAbsent:nil. |
|
1057 |
val notNil ifTrue:[ |
|
1058 |
val first isUppercase ifTrue:[^ val]. |
|
1059 |
first isUppercase ifTrue:[ |
|
1060 |
^ val asUppercaseFirst |
|
1061 |
]. |
|
1062 |
^ val asLowercaseFirst. |
|
1063 |
]. |
|
8226 | 1064 |
]. |
4617 | 1065 |
|
8226 | 1066 |
((first == $( and:[last == $) ]) |
1067 |
or:[ (first == $[ and:[last == $] ]) |
|
1068 |
or:[ (first == ${ and:[last == $} ]) ]]) ifTrue:[ |
|
1069 |
usedKey := aKey copyFrom:2 to:aKey size-1. |
|
5593 | 1070 |
|
8226 | 1071 |
val := self localAt:usedKey. "/ recursion |
1072 |
val notNil ifTrue:[^ first asString,val,last asString]. |
|
1073 |
]. |
|
8498 | 1074 |
last == $… ifTrue:[ |
1075 |
usedKey := aKey copyButLast:1. |
|
5593 | 1076 |
|
8498 | 1077 |
val := self localAt:usedKey. "/ recursion |
1078 |
val notNil ifTrue:[^ val , '…']. |
|
1079 |
]. |
|
1080 |
||
8226 | 1081 |
last == $. ifTrue:[ |
1082 |
(aKey endsWith:' ...') ifTrue:[ |
|
1083 |
usedKey := aKey copyButLast:4. |
|
5573 | 1084 |
|
8226 | 1085 |
val := self localAt:usedKey. "/ recursion |
8498 | 1086 |
val notNil ifTrue:[^ val , '...']. |
8226 | 1087 |
]. |
1088 |
(aKey endsWith:'...') ifTrue:[ |
|
1089 |
usedKey := aKey copyButLast:3. |
|
5573 | 1090 |
|
8226 | 1091 |
val := self localAt:usedKey. "/ recursion |
1092 |
val notNil ifTrue:[^ val , '...']. |
|
1093 |
]. |
|
1094 |
]. |
|
5573 | 1095 |
|
8226 | 1096 |
first isSeparator ifTrue:[ |
1097 |
usedKey := aKey withoutLeadingSeparators. |
|
4634 | 1098 |
|
8226 | 1099 |
val := self localAt:usedKey. "/ recursion |
1100 |
val notNil ifTrue:[^ (aKey copyTo:(aKey size - usedKey size)), val]. "/ prepend the stripped separators |
|
1101 |
]. |
|
1102 |
last isSeparator ifTrue:[ |
|
1103 |
usedKey := aKey withoutTrailingSeparators. |
|
4634 | 1104 |
|
8226 | 1105 |
val := self localAt:usedKey. "/ recursion |
1106 |
val notNil ifTrue:[^ val, (aKey copyFrom:usedKey size + 1)]. "/ append the stripped separators |
|
1107 |
]. |
|
4634 | 1108 |
|
8558 | 1109 |
(';*:=.?!!,-><\/' includes:last) ifTrue:[ |
8226 | 1110 |
aKey size >= 2 ifTrue:[ |
1111 |
usedKey := aKey copyButLast:1. |
|
4617 | 1112 |
|
8226 | 1113 |
val := self localAt:usedKey. "/ recursion |
1114 |
val notNil ifTrue:[^ val copyWith:last]. |
|
1115 |
]. |
|
1116 |
]. |
|
8558 | 1117 |
(';*:=.?!!-><\/' includes:first) ifTrue:[ |
8226 | 1118 |
aKey size >= 2 ifTrue:[ |
1119 |
usedKey := aKey copyButFirst:1. |
|
4634 | 1120 |
|
8226 | 1121 |
val := self localAt:usedKey. "/ recursion |
1122 |
val notNil ifTrue:[^ first asString , val]. |
|
1123 |
]. |
|
1124 |
]. |
|
4028 | 1125 |
|
8226 | 1126 |
(first == $( and:[last == $)]) ifTrue:[ |
1127 |
usedKey := aKey copyFrom:2 to:(aKey size - 1). |
|
4028 | 1128 |
|
8226 | 1129 |
val := self localAt:usedKey. "/ recursion |
1130 |
val notNil ifTrue:[^ '(' , val , ')']. |
|
1131 |
]. |
|
4017 | 1132 |
|
8226 | 1133 |
(idx := aKey indexOf:$&) ~~ 0 ifTrue:[ |
1134 |
(aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[ |
|
1135 |
usedKey := (aKey copyTo:idx-1) , (aKey copyFrom:idx+1). |
|
1136 |
val := self localAt:usedKey. "/ recursion |
|
1137 |
val notNil ifTrue:[^ val]. |
|
1138 |
]. |
|
1139 |
]. |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1140 |
]. |
4617 | 1141 |
^ nil. |
4580 | 1142 |
|
4617 | 1143 |
"Created: / 18-09-2006 / 17:33:27 / cg" |
5593 | 1144 |
"Modified: / 05-08-2010 / 16:52:32 / sr" |
8226 | 1145 |
"Modified: / 27-11-2017 / 15:33:48 / cg" |
8565 | 1146 |
"Modified: / 04-11-2018 / 12:33:50 / Claus Gittinger" |
2 | 1147 |
! |
1148 |
||
1149 |
name:aKey default:default |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1150 |
"translate a string. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1151 |
Obsolete - use #string:default:" |
123 | 1152 |
|
4844 | 1153 |
<resource: #obsolete> |
1154 |
||
72 | 1155 |
^ self at:aKey ifAbsent:default |
2 | 1156 |
! |
1157 |
||
0 | 1158 |
string:s |
3097 | 1159 |
"translate (retrieve) a string - if not present, return s" |
123 | 1160 |
|
72 | 1161 |
^ self at:s ifAbsent:s |
3097 | 1162 |
|
1163 |
" |
|
1164 |
NewLauncher classResources |
|
8462 | 1165 |
string:'LICENCEFILE' |
3097 | 1166 |
" |
0 | 1167 |
! |
1168 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1169 |
string:s default:defaultString |
3097 | 1170 |
"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
|
1171 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1172 |
^ self at:s ifAbsent:defaultString |
3097 | 1173 |
|
1174 |
" |
|
1175 |
NewLauncher classResources |
|
8462 | 1176 |
string:'fooBar' default:'Hello world' |
3097 | 1177 |
" |
1178 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1179 |
! |
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 |
string:s default:defaultString with:arg |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1182 |
"translate and expand arg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1183 |
|
8445 | 1184 |
^ self string:s default:defaultString withArguments:(Array with:arg) |
3097 | 1185 |
|
1186 |
" |
|
1187 |
NewLauncher classResources |
|
8445 | 1188 |
string:'%1 fooBar' default:'Hello %1' with:'foo' |
3097 | 1189 |
" |
1190 |
||
8445 | 1191 |
"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
|
1192 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1193 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1194 |
string:s default:defaultString with:arg1 with:arg2 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1195 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1196 |
|
8445 | 1197 |
^ self string:s default:defaultString withArguments:(Array with:arg1 with:arg2) |
1198 |
||
1199 |
"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
|
1200 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1201 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1202 |
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
|
1203 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1204 |
|
8445 | 1205 |
^ 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
|
1206 |
|
8445 | 1207 |
"Created: / 09-12-1995 / 19:08:50 / cg" |
1208 |
"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
|
1209 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1210 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1211 |
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
|
1212 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1213 |
|
8445 | 1214 |
^ 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
|
1215 |
|
8445 | 1216 |
"Created: / 09-09-1996 / 18:52:14 / cg" |
1217 |
"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
|
1218 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1219 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1220 |
string:s default:defaultString withArgs:argArray |
8445 | 1221 |
<resource: #obsolete> |
1222 |
"translate and expand args" |
|
1223 |
||
1224 |
^ self string:s default:defaultString withArguments:argArray |
|
1225 |
||
1226 |
"Modified: / 09-08-2018 / 14:55:38 / Claus Gittinger" |
|
1227 |
! |
|
1228 |
||
1229 |
string:s default:defaultString withArguments:argArray |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1230 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1231 |
|
5070 | 1232 |
|template| |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1233 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1234 |
template := self at:s ifAbsent:defaultString. |
5070 | 1235 |
^ template expandPlaceholdersWith:argArray. |
8445 | 1236 |
|
1237 |
"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
|
1238 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1239 |
|
0 | 1240 |
string:s with:arg |
123 | 1241 |
"translate and expand arg" |
1242 |
||
8445 | 1243 |
^ self string:s withArguments:(Array with:arg) |
1244 |
||
1245 |
"Modified: / 09-08-2018 / 14:56:02 / Claus Gittinger" |
|
0 | 1246 |
! |
1247 |
||
1248 |
string:s with:arg1 with:arg2 |
|
123 | 1249 |
"translate and expand args" |
1250 |
||
8445 | 1251 |
^ self string:s withArguments:(Array with:arg1 with:arg2) |
1252 |
||
1253 |
"Modified: / 09-08-2018 / 14:56:04 / Claus Gittinger" |
|
0 | 1254 |
! |
1255 |
||
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1256 |
string:s with:arg1 with:arg2 with:arg3 |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1257 |
"translate and expand args" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1258 |
|
8445 | 1259 |
^ 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
|
1260 |
|
8445 | 1261 |
"Created: / 09-12-1995 / 19:08:50 / cg" |
1262 |
"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
|
1263 |
! |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1264 |
|
1042 | 1265 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 |
1266 |
"translate and expand args" |
|
1267 |
||
8445 | 1268 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
1042 | 1269 |
|
8445 | 1270 |
"Created: / 09-09-1996 / 18:52:14 / cg" |
1271 |
"Modified: / 09-08-2018 / 14:56:09 / Claus Gittinger" |
|
1042 | 1272 |
! |
1273 |
||
3184 | 1274 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
1275 |
"translate and expand args" |
|
1276 |
||
8445 | 1277 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
3184 | 1278 |
|
8445 | 1279 |
"Modified: / 09-08-2018 / 14:56:12 / Claus Gittinger" |
3184 | 1280 |
! |
1281 |
||
5652 | 1282 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
1283 |
"translate and expand args" |
|
1284 |
||
8445 | 1285 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6) |
5652 | 1286 |
|
1287 |
"Created: / 13-11-2010 / 11:35:00 / cg" |
|
8445 | 1288 |
"Modified: / 09-08-2018 / 14:56:14 / Claus Gittinger" |
5652 | 1289 |
! |
1290 |
||
1291 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7 |
|
1292 |
"translate and expand args" |
|
1293 |
||
8445 | 1294 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7) |
5652 | 1295 |
|
1296 |
"Created: / 13-11-2010 / 11:35:07 / cg" |
|
8445 | 1297 |
"Modified: / 09-08-2018 / 14:55:07 / Claus Gittinger" |
5652 | 1298 |
! |
1299 |
||
0 | 1300 |
string:s withArgs:argArray |
8445 | 1301 |
<resource: #obsolete> |
1302 |
"translate and expand args - allow text as arguments" |
|
1303 |
||
1304 |
^ self string:s withArguments:argArray |
|
1305 |
||
1306 |
"Modified: / 09-08-2018 / 14:54:54 / Claus Gittinger" |
|
1307 |
! |
|
1308 |
||
1309 |
string:s withArguments:argArray |
|
4932
b19b928b0026
Allow (and insert) Texts as arguments in #string:with:
Stefan Vogel <sv@exept.de>
parents:
4848
diff
changeset
|
1310 |
"translate and expand args - allow text as arguments" |
123 | 1311 |
|
5069 | 1312 |
|template| |
0 | 1313 |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1314 |
template := self at:s ifAbsent:s. |
5069 | 1315 |
^ template expandPlaceholdersWith:argArray. |
4932
b19b928b0026
Allow (and insert) Texts as arguments in #string:with:
Stefan Vogel <sv@exept.de>
parents:
4848
diff
changeset
|
1316 |
|
8445 | 1317 |
"Created: / 09-08-2018 / 14:54:43 / Claus Gittinger" |
3823 | 1318 |
! |
1319 |
||
4402 | 1320 |
stringWithCRs:s |
8459 | 1321 |
"translate (retrieve) a string - if not present, return s. |
1322 |
replaces \'s with CRs" |
|
4402 | 1323 |
|
8459 | 1324 |
(s startsWith:':c:') ifTrue:[ |
1325 |
^ (self string:(s withoutPrefix:':c:')) withoutCEscapes |
|
1326 |
]. |
|
1327 |
(s startsWith:':st:') ifTrue:[ |
|
1328 |
^ (self string:(s withoutPrefix:':st:')) expandPlaceholdersWith:nil |
|
1329 |
]. |
|
4402 | 1330 |
^ (self string:s) withCRs |
1331 |
||
1332 |
" |
|
1333 |
NewLauncher classResources |
|
8459 | 1334 |
stringWithCRs:'LICENCEFILE' |
4402 | 1335 |
" |
8459 | 1336 |
|
1337 |
"Modified: / 07-09-2018 / 12:43:00 / Claus Gittinger" |
|
4402 | 1338 |
! |
1339 |
||
3823 | 1340 |
stringWithCRs:s with:arg |
1341 |
"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
|
1342 |
CR-replacement is donw before args are inserted |
3823 | 1343 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1344 |
||
8445 | 1345 |
^ self stringWithCRs:s withArguments:(Array with:arg) |
3823 | 1346 |
|
8445 | 1347 |
"Modified: / 21-03-2003 / 14:22:09 / cg" |
1348 |
"Modified: / 09-08-2018 / 14:56:21 / Claus Gittinger" |
|
3823 | 1349 |
! |
1350 |
||
1351 |
stringWithCRs:s with:arg1 with:arg2 |
|
1352 |
"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
|
1353 |
CR-replacement is donw before args are inserted |
3823 | 1354 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1355 |
||
8445 | 1356 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2) |
3823 | 1357 |
|
8445 | 1358 |
"Modified: / 21-03-2003 / 14:22:06 / cg" |
1359 |
"Modified: / 09-08-2018 / 14:56:25 / Claus Gittinger" |
|
3823 | 1360 |
! |
1361 |
||
1362 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 |
|
1363 |
"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
|
1364 |
CR-replacement is donw before args are inserted |
3823 | 1365 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1366 |
||
8445 | 1367 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3) |
3823 | 1368 |
|
8445 | 1369 |
"Created: / 09-12-1995 / 19:08:50 / cg" |
1370 |
"Modified: / 09-08-2018 / 14:56:27 / Claus Gittinger" |
|
3823 | 1371 |
! |
1372 |
||
1373 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 |
|
1374 |
"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
|
1375 |
CR-replacement is donw before args are inserted |
3823 | 1376 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1377 |
||
8445 | 1378 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
3823 | 1379 |
|
8445 | 1380 |
"Modified: / 21-03-2003 / 14:21:48 / cg" |
1381 |
"Modified: / 09-08-2018 / 14:56:30 / Claus Gittinger" |
|
3823 | 1382 |
! |
1383 |
||
1384 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
1385 |
"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
|
1386 |
CR-replacement is donw before args are inserted |
3823 | 1387 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1388 |
||
8445 | 1389 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
3823 | 1390 |
|
8445 | 1391 |
"Modified: / 21-03-2003 / 14:21:55 / cg" |
1392 |
"Modified: / 09-08-2018 / 14:56:32 / Claus Gittinger" |
|
3823 | 1393 |
! |
1394 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1395 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
5652 | 1396 |
"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
|
1397 |
CR-replacement is donw before args are inserted |
5652 | 1398 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1399 |
||
8445 | 1400 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6) |
5652 | 1401 |
|
1402 |
"Created: / 13-11-2010 / 11:35:30 / cg" |
|
8445 | 1403 |
"Modified: / 09-08-2018 / 14:56:35 / Claus Gittinger" |
5652 | 1404 |
! |
1405 |
||
1406 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7 |
|
1407 |
"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
|
1408 |
CR-replacement is donw before args are inserted |
5652 | 1409 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1410 |
||
8445 | 1411 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7) |
5652 | 1412 |
|
1413 |
"Created: / 13-11-2010 / 11:35:20 / cg" |
|
8445 | 1414 |
"Modified: / 09-08-2018 / 14:56:37 / Claus Gittinger" |
5652 | 1415 |
! |
1416 |
||
3823 | 1417 |
stringWithCRs:s withArgs:argArray |
8445 | 1418 |
<resource: #obsolete> |
1419 |
"translate, replace \'s with CRs and finally expand args. |
|
1420 |
CR-replacement is done before args are inserted |
|
1421 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
1422 |
||
1423 |
^ self stringWithCRs:s withArguments:argArray |
|
1424 |
||
1425 |
"Modified: / 09-08-2018 / 14:54:29 / Claus Gittinger" |
|
1426 |
! |
|
1427 |
||
1428 |
stringWithCRs:s withArguments:argArray |
|
3823 | 1429 |
"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
|
1430 |
CR-replacement is done before args are inserted |
3823 | 1431 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1432 |
||
5070 | 1433 |
|template| |
3823 | 1434 |
|
1435 |
template := self at:s ifAbsent:s. |
|
8459 | 1436 |
(s startsWith:':c:') ifTrue:[ |
1437 |
^ (self string:(s withoutPrefix:':c:')) withoutCEscapes expandPlaceholdersWith:argArray |
|
1438 |
]. |
|
1439 |
(s startsWith:':st:') ifTrue:[ |
|
1440 |
^ (self string:(s withoutPrefix:':st:')) expandPlaceholdersWith:argArray |
|
1441 |
]. |
|
5070 | 1442 |
^ template withCRs expandPlaceholdersWith:argArray. |
8445 | 1443 |
|
1444 |
"Created: / 09-08-2018 / 14:54:16 / Claus Gittinger" |
|
8459 | 1445 |
"Modified: / 07-09-2018 / 12:44:06 / Claus Gittinger" |
6174 | 1446 |
! |
1447 |
||
1448 |
whichPackIncludesKey:aKey |
|
1449 |
"for debugging: return the pack (alogn the super-pack chain), which |
|
1450 |
has a translation for a string" |
|
1451 |
||
8510 | 1452 |
|val pack projectPack alreadySearched toSearch| |
6174 | 1453 |
|
1454 |
aKey isNil ifTrue:[ ^ nil ]. |
|
1455 |
||
1456 |
val := self localAt:aKey. |
|
1457 |
val notNil ifTrue:[^ self]. |
|
1458 |
||
8516 | 1459 |
superPacks isEmptyOrNil ifTrue:[^ nil]. |
6174 | 1460 |
|
8510 | 1461 |
alreadySearched := Set new. |
1462 |
toSearch := OrderedCollection withAll:superPacks. |
|
1463 |
[toSearch notEmpty] whileTrue:[ |
|
1464 |
pack := toSearch removeFirst. |
|
1465 |
(alreadySearched includes:pack) ifFalse:[ |
|
1466 |
val := pack localAt:aKey. |
|
1467 |
val notNil ifTrue:[^ pack]. |
|
1468 |
alreadySearched add:pack. |
|
1469 |
toSearch addAll:(pack superPacks). |
|
8462 | 1470 |
]. |
6174 | 1471 |
]. |
8510 | 1472 |
^ nil. |
1473 |
||
1474 |
"/ (projectPack := self projectPack) notNil ifTrue:[ |
|
1475 |
"/ val := projectPack localAt:aKey. |
|
1476 |
"/ val notNil ifTrue:[^ projectPack]. |
|
1477 |
"/ ]. |
|
1478 |
"/ alreadySearched := Set new. |
|
1479 |
"/ projectPack notNil ifTrue:[ alreadySearched add:projectPack ]. |
|
1480 |
"/ |
|
1481 |
"/ pack := self superPack. |
|
1482 |
"/ [ pack notNil ] whileTrue:[ |
|
1483 |
"/ val := pack localAt:aKey. |
|
1484 |
"/ val notNil ifTrue:[^ pack]. |
|
1485 |
"/ |
|
1486 |
"/ (projectPack := pack projectPack) notNil ifTrue:[ |
|
1487 |
"/ (alreadySearched includes:projectPack) ifFalse:[ |
|
1488 |
"/ val := projectPack localAt:aKey. |
|
1489 |
"/ val notNil ifTrue:[^ projectPack]. |
|
1490 |
"/ alreadySearched add:projectPack. |
|
1491 |
"/ ]. |
|
1492 |
"/ ]. |
|
1493 |
"/ pack := pack superPack |
|
1494 |
"/ ]. |
|
1495 |
"/ |
|
1496 |
"/ alreadySearched copy do:[:projectPack | |
|
1497 |
"/ |p| |
|
1498 |
"/ |
|
1499 |
"/ p := projectPack superPack. |
|
1500 |
"/ [p notNil and:[(alreadySearched includes:p) not]] whileTrue:[ |
|
1501 |
"/ val := p localAt:aKey. |
|
1502 |
"/ val notNil ifTrue:[^ p]. |
|
1503 |
"/ alreadySearched add:p. |
|
1504 |
"/ p := p superPack. |
|
1505 |
"/ ]. |
|
1506 |
"/ ]. |
|
1507 |
"/ |
|
1508 |
"/ ^ nil |
|
0 | 1509 |
! ! |
1510 |
||
3317 | 1511 |
!ResourcePack methodsFor:'accessing-internals'! |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1512 |
|
8510 | 1513 |
addSuperPack:anotherResourcePack |
1514 |
(anotherResourcePack == self) ifTrue:[ |
|
1515 |
^ self |
|
1516 |
]. |
|
1517 |
superPacks isNil ifTrue:[ superPacks := OrderedCollection new ]. |
|
1518 |
(superPacks includes:anotherResourcePack) ifFalse:[ |
|
1519 |
self assert:(anotherResourcePack isKindOf:ResourcePack). |
|
1520 |
superPacks add:anotherResourcePack |
|
1521 |
]. |
|
1522 |
! |
|
1523 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1524 |
name:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1525 |
"translate a string" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1526 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1527 |
^ self at:aKey ifAbsent:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1528 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1529 |
|
8517 | 1530 |
packsFileName |
1531 |
^ packsFileName |
|
1532 |
! |
|
1533 |
||
1534 |
packsPackage |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1535 |
^ packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1536 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1537 |
|
8517 | 1538 |
packsPackage:aPackage |
1539 |
packsClassName := aPackage |
|
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1540 |
! |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1541 |
|
4617 | 1542 |
projectPack |
1543 |
^ projectPack |
|
1544 |
||
1545 |
"Created: / 18-09-2006 / 17:38:07 / cg" |
|
1546 |
! |
|
1547 |
||
8510 | 1548 |
superPacks |
1549 |
^ superPacks ? #() |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1550 |
! ! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1551 |
|
0 | 1552 |
!ResourcePack methodsFor:'file reading'! |
1553 |
||
684 | 1554 |
fileReadFailed |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1555 |
"return true, if the pack does not really contain |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1556 |
valid translations, since the fileRead failed. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1557 |
However, all inherited translations are still available |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1558 |
through the receiver" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1559 |
|
687 | 1560 |
^ fileReadFailed ~~ false |
684 | 1561 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1562 |
"Created: / 14.5.1996 / 10:19:26 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1563 |
"Modified: / 29.1.1998 / 22:46:38 / cg" |
684 | 1564 |
! |
1565 |
||
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1566 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1567 |
"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
|
1568 |
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
|
1569 |
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
|
1570 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1571 |
^ nil |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1572 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1573 |
"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
|
1574 |
! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1575 |
|
4332 | 1576 |
processLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError |
145 | 1577 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
1578 |
||
4509 | 1579 |
self class |
8462 | 1580 |
processResourceLine:lineString |
1581 |
encoding:encodingSymbolOrEncoder |
|
1582 |
file:fileName |
|
1583 |
printErrorWith:printError |
|
1584 |
for:self |
|
144 | 1585 |
! |
1586 |
||
244 | 1587 |
readFromFile:fileName directory:dirName |
1588 |
"read definitions from a file in a directory" |
|
1589 |
||
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1590 |
|triedFilename inStream ok| |
244 | 1591 |
|
686 | 1592 |
fileReadFailed := false. |
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1593 |
"/ 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
|
1594 |
"/ (happens when da.rs is not present in libbasic/resources.rs) |
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1595 |
ExternalStream openErrorSignal handle:[:ex | |
8462 | 1596 |
Transcript showCR:'ResourcePack: failed to open file: ',fileName asString,' in ',dirName asString. |
1597 |
inStream := nil. |
|
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1598 |
] do:[ |
8462 | 1599 |
dirName = 'resources' ifTrue:[ |
1600 |
inStream := Smalltalk resourceFileStreamFor:fileName |
|
1601 |
] ifFalse:[ |
|
1602 |
inStream := Smalltalk systemFileStreamFor: |
|
1603 |
(dirName isNil |
|
1604 |
ifTrue:[fileName] |
|
1605 |
ifFalse:[dirName asFilename construct:fileName]). |
|
1606 |
]. |
|
244 | 1607 |
]. |
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1608 |
|
8515 | 1609 |
"/ '7) inStream ' print. inStream printCR. |
8512 | 1610 |
|
244 | 1611 |
inStream isNil ifTrue:[ |
8462 | 1612 |
" |
1613 |
an empty pack |
|
1614 |
" |
|
1615 |
^ self nonexistingFileRead |
|
244 | 1616 |
]. |
2996 | 1617 |
|
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1618 |
triedFilename := inStream pathName. |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1619 |
[ |
8462 | 1620 |
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
|
1621 |
] ensure:[ |
8462 | 1622 |
inStream close. |
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1623 |
]. |
686 | 1624 |
|
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1625 |
ok ifTrue:[ |
8462 | 1626 |
packsFileName := triedFilename |
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1627 |
] ifFalse:[ |
8462 | 1628 |
fileReadFailed := true. |
684 | 1629 |
|
8462 | 1630 |
('ResourcePack [warning]: "' , triedFilename , '" contains error(s) - data may be incomplete.') errorPrintCR. |
244 | 1631 |
]. |
1632 |
||
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1633 |
"Modified: / 20-08-2011 / 17:10:02 / cg" |
244 | 1634 |
! |
1635 |
||
72 | 1636 |
readFromResourceStream:inStream in:dirName |
4848 | 1637 |
"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
|
1638 |
specify where #include files are searched for. |
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1639 |
Return true, if the style sheet could be read without errors, false otherwise." |
145 | 1640 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1641 |
|lineString l lineNumber rest value ifLevel skipping first ok encoding decoder pack errorHandler |
4947 | 1642 |
printError fileName pushedSkipValues| |
4058 | 1643 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1644 |
fileName := (inStream isFileStream |
6992 | 1645 |
ifTrue:[inStream pathName asFilename baseName] |
1646 |
ifFalse:['---']). |
|
4058 | 1647 |
|
1648 |
printError := [:message | |
|
6992 | 1649 |
'ResourcePack [warning]: ' errorPrint. |
1650 |
message errorPrint. |
|
1651 |
' in file:' errorPrint. |
|
1652 |
fileName errorPrint. |
|
1653 |
' line: ' errorPrint. |
|
1654 |
lineNumber errorPrintCR |
|
1655 |
]. |
|
4058 | 1656 |
|
1657 |
printError := [:message | ]. |
|
462
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1658 |
|
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1659 |
encoding := nil. |
0 | 1660 |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1661 |
ok := true. |
0 | 1662 |
ifLevel := 0. |
1663 |
skipping := false. |
|
4058 | 1664 |
lineNumber := 0. |
4947 | 1665 |
pushedSkipValues := OrderedCollection new. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1666 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1667 |
errorHandler := [:ex | |
6992 | 1668 |
|con| |
4947 | 1669 |
|
6992 | 1670 |
Transcript showCR:('ResourcePack [warning]: ''' , ex description , '''') "errorPrintCR". |
1671 |
Transcript showCR:('ResourcePack [info]: file: ' , inStream pathName printString , ' line: ' , lineNumber printString , ': ''' , lineString , '''') "errorPrintCR". |
|
1672 |
con := ex suspendedContext. |
|
1673 |
Transcript showCR:('ResourcePack [info]: in: ' , con fullPrintString) "errorPrintCR". |
|
1674 |
con := con sender. |
|
1675 |
Transcript showCR:('ResourcePack [info]: : ' , con fullPrintString) "errorPrintCR". |
|
1676 |
20 timesRepeat:[ |
|
1677 |
con notNil ifTrue:[ |
|
1678 |
con := con sender. |
|
1679 |
Transcript showCR:('ResourcePack [info]: : ' , con fullPrintString) "errorPrintCR". |
|
1680 |
]. |
|
1681 |
]. |
|
1682 |
value := nil. |
|
1683 |
ok := false. |
|
1684 |
]. |
|
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1685 |
|
0 | 1686 |
[inStream atEnd] whileFalse:[ |
6992 | 1687 |
lineString := inStream nextLine. lineNumber := lineNumber + 1. |
1688 |
[lineString notNil and:[lineString endsWith:$\]] whileTrue:[ |
|
1689 |
lineString := lineString copyButLast:1. |
|
1690 |
l := inStream nextLine. lineNumber := lineNumber + 1. |
|
1691 |
l notNil ifTrue:[ |
|
1692 |
lineString := lineString , l. |
|
1693 |
]. |
|
1694 |
]. |
|
177 | 1695 |
|
6992 | 1696 |
(lineString size > 0) ifTrue:[ |
1697 |
first := lineString at:1. |
|
1698 |
"/ |
|
1699 |
"/ for your convenience: treat both ';' AND '"/' as comment-line |
|
1700 |
"/ |
|
1701 |
((first == $;) or:[lineString startsWith:'"/']) ifFalse:[ |
|
1702 |
((first == $#) and:[(lineString startsWith:'#(') not]) ifTrue:[ |
|
1703 |
"/ a directive |
|
1704 |
lineString := (lineString copyFrom:2) withoutSpaces. |
|
72 | 1705 |
|
6992 | 1706 |
(lineString startsWith:'if') ifTrue:[ |
1707 |
pushedSkipValues add:skipping. |
|
1708 |
skipping ifFalse:[ |
|
1709 |
rest := lineString copyFrom:3. |
|
1710 |
Error, UserInformation |
|
1711 |
handle:errorHandler |
|
1712 |
do:[ |
|
1713 |
value := Compiler evaluate:rest compile:false. |
|
1714 |
]. |
|
1715 |
(value == #Error) ifTrue:[ |
|
1716 |
printError value:('error in resource:' , lineString). |
|
1717 |
]. |
|
1718 |
(value == false) ifTrue:[ |
|
1719 |
skipping := true |
|
1720 |
] |
|
1721 |
]. |
|
1722 |
ifLevel := ifLevel + 1 |
|
1723 |
] ifFalse:[ |
|
1724 |
(lineString startsWith:'endif') ifTrue:[ |
|
1725 |
ifLevel == 0 ifTrue:[ |
|
1726 |
printError value:('if/endif nesting error'). |
|
1727 |
] ifFalse:[ |
|
1728 |
ifLevel := ifLevel - 1. |
|
1729 |
skipping := pushedSkipValues removeLast. |
|
1730 |
] |
|
1731 |
] ifFalse:[ |
|
1732 |
(lineString startsWith:'else') ifTrue:[ |
|
1733 |
(pushedSkipValues includes:true) ifFalse:[ |
|
1734 |
skipping := skipping not |
|
1735 |
] |
|
1736 |
] ifFalse:[ |
|
1737 |
skipping ifFalse:[ |
|
1738 |
(lineString startsWith:'superpack') ifTrue:[ |
|
1739 |
rest := lineString copyFrom:('superpack' size + 1). |
|
1740 |
value := Compiler evaluate:rest compile:false. |
|
1741 |
(value isKindOf:ResourcePack) ifTrue:[ |
|
8517 | 1742 |
self addSuperPack:value. |
6992 | 1743 |
] |
1744 |
] ifFalse:[ |
|
1745 |
(lineString startsWith:'include') ifTrue:[ |
|
1746 |
(lineString startsWith:'includeResourcesFor') ifTrue:[ |
|
1747 |
"/ include those resources ... |
|
1748 |
rest := lineString copyFrom:('includeResourcesFor' size + 1). |
|
1749 |
value := Compiler evaluate:rest compile:false. |
|
1750 |
value isBehavior ifTrue:[ |
|
1751 |
pack := self class for:value. |
|
1752 |
pack notNil ifTrue:[ |
|
1753 |
self addAll:pack. |
|
1754 |
] |
|
1755 |
] |
|
1756 |
] ifFalse:[ |
|
1757 |
rest := lineString copyFrom:('include' size + 1). |
|
1758 |
value := Compiler evaluate:rest compile:false. |
|
1759 |
value isString ifFalse:[ |
|
1760 |
printError value:('bad include filename: ' , value printString, ' "',lineString,'"'). |
|
1761 |
] ifTrue:[ |
|
1762 |
self readFromFile:value directory:dirName |
|
1763 |
] |
|
1764 |
] |
|
1765 |
] ifFalse:[ |
|
1766 |
(lineString startsWith:'encoding') ifTrue:[ |
|
4848 | 1767 |
"/decoder notNil ifTrue:[self halt:'oops - encoding change in file']. |
6992 | 1768 |
encoding := self class extractEncodingFromLine:lineString. |
1769 |
decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil. |
|
1770 |
] |
|
1771 |
] |
|
1772 |
] |
|
1773 |
] |
|
1774 |
] |
|
1775 |
] |
|
1776 |
]. |
|
1777 |
] ifFalse:[ |
|
1778 |
skipping ifFalse:[ |
|
1779 |
Error, UserInformation |
|
1780 |
handle:errorHandler |
|
1781 |
do:[ |
|
1782 |
(lineString at:1) == $!! ifTrue:[ |
|
1783 |
"/ evaluate the rest |
|
1784 |
Compiler evaluate:(lineString copyFrom:2) |
|
1785 |
receiver:self |
|
1786 |
notifying:nil |
|
1787 |
compile:false. |
|
1788 |
] ifFalse:[ |
|
1789 |
"/ process as resource |
|
1790 |
self |
|
1791 |
processLine:lineString |
|
1792 |
encoding:decoder |
|
1793 |
file:(inStream isFileStream |
|
1794 |
ifTrue:[inStream pathName] |
|
1795 |
ifFalse:['---']) |
|
1796 |
printErrorWith:printError |
|
1797 |
]] |
|
1798 |
] |
|
1799 |
] |
|
1800 |
] |
|
1801 |
] |
|
0 | 1802 |
]. |
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1803 |
^ ok |
177 | 1804 |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
1805 |
"Modified: / 31-08-1995 / 02:33:45 / claus" |
4619 | 1806 |
"Modified: / 18-09-2006 / 20:35:37 / cg" |
8496 | 1807 |
"Modified: / 10-10-2018 / 14:14:00 / sr" |
0 | 1808 |
! ! |
1809 |
||
8509 | 1810 |
|
4093 | 1811 |
!ResourcePack methodsFor:'printing & storing'! |
1812 |
||
5603
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1813 |
displayOn:aGCOrStream |
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1814 |
|
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1815 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
7931 | 1816 |
"/ old ST80 means: draw-yourself on a GC. |
1817 |
(aGCOrStream isStream) ifFalse:[ |
|
1818 |
^ super displayOn:aGCOrStream |
|
5603
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1819 |
]. |
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1820 |
|
7931 | 1821 |
aGCOrStream nextPutAll:'ResourcePack for: '. |
1822 |
packsClassName printOn:aGCOrStream. |
|
1823 |
||
1824 |
"Modified: / 22-02-2017 / 17:00:31 / cg" |
|
4093 | 1825 |
! ! |
1826 |
||
8461 | 1827 |
!ResourcePack methodsFor:'statistics'! |
1828 |
||
1829 |
forgetUsedKeys |
|
1830 |
"stop keeping a statistic on which keys are actually used" |
|
1831 |
||
1832 |
usedKeys := nil. |
|
1833 |
||
1834 |
"Modified (comment): / 12-09-2018 / 18:23:27 / Claus Gittinger" |
|
1835 |
! |
|
1836 |
||
1837 |
rememberUsedKeys |
|
1838 |
"start keeping a statistic on which keys are actually used" |
|
1839 |
||
1840 |
usedKeys := Set new. |
|
1841 |
||
1842 |
"Modified (comment): / 12-09-2018 / 18:23:22 / Claus Gittinger" |
|
1843 |
! |
|
1844 |
||
1845 |
usedKeys |
|
1846 |
"get keys which were actually used. |
|
1847 |
(must call #rememberUsedKeys before)" |
|
1848 |
||
1849 |
^ usedKeys |
|
1850 |
||
1851 |
"Created: / 12-09-2018 / 18:24:26 / Claus Gittinger" |
|
1852 |
! ! |
|
1853 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
1854 |
!ResourcePack class methodsFor:'documentation'! |
251 | 1855 |
|
1856 |
version |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1857 |
^ '$Header$' |
5357 | 1858 |
! |
1859 |
||
1860 |
version_CVS |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1861 |
^ '$Header$' |
251 | 1862 |
! ! |
3769 | 1863 |
|
6051
f01078ce8c2c
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
5951
diff
changeset
|
1864 |
|
0 | 1865 |
ResourcePack initialize! |