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