author | Claus Gittinger <cg@exept.de> |
Mon, 04 May 2020 19:15:18 +0200 | |
changeset 9041 | b3621d52dd8c |
parent 9002 | 0c1d599727eb |
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:[ |
9002 | 764 |
((lineString startsWith:'c''') or:[lineStream peek == $']) ifTrue:[ |
8462 | 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 |
|
9002 | 919 |
" |
920 |
|p| |
|
921 |
p := ResourcePack new. |
|
922 |
self processResourceLine:'''foo'' ''xlation_of_foo''' encoding:nil file:'dummy.rc' printErrorWith:[:err | Logger warn:err] for:p keepUselessTranslations:false. |
|
923 |
p inspect. |
|
924 |
" |
|
925 |
||
6250 | 926 |
"Modified: / 06-02-2014 / 15:33:03 / cg" |
8667 | 927 |
"Modified: / 27-03-2019 / 11:59:49 / Claus Gittinger" |
8815 | 928 |
"Modified: / 28-09-2019 / 15:20:38 / Stefan Vogel" |
6661 | 929 |
! |
930 |
||
931 |
resourceFileEntryFor:keyString to:nationalString |
|
932 |
"generate a line for a translation file, which defines a translation |
|
933 |
from keyString to nationalString. |
|
934 |
Naivly, this could be a simple line containing the two storeStrings |
|
935 |
separated by a space. However, it is better to first cut of any leading |
|
936 |
and trailing spaces and special characters, such as ':*.,' etc." |
|
937 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
938 |
^ (self resourceFileStringFor:keyString),' ',(self resourceFileStringFor:nationalString) |
6661 | 939 |
! |
940 |
||
941 |
resourceFileStringFor:aString |
|
942 |
"generate a key or value entry for a translation file, for aString. |
|
943 |
Naivly, this could be a simple the storeString. |
|
944 |
However, it is better to first cut of any leading |
|
945 |
and trailing spaces and special characters, sch as ':*.,' etc." |
|
946 |
||
947 |
^ (self shortenedKeyFor:aString) storeString |
|
948 |
||
949 |
" |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
950 |
self resourceFileStringFor:' foo: ' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
951 |
self resourceFileStringFor:' foo bar: ' |
6661 | 952 |
" |
953 |
! |
|
954 |
||
955 |
shortenedKeyFor:aKey |
|
956 |
"if |
|
8462 | 957 |
aKey is '(...)', then return '...' |
958 |
if aKey is '[...]', then return '...' |
|
959 |
if aKey is '{...}', then return '...' |
|
960 |
if aKey starts or ends with any of '\:=.,?!! ', then return aKey without it |
|
6661 | 961 |
|
962 |
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
|
963 |
things like |
8462 | 964 |
'search' |
965 |
'search:' |
|
966 |
'search...' |
|
6661 | 967 |
" |
968 |
||
969 |
|idx idx1 idx2 first last keySize| |
|
970 |
||
971 |
first := aKey first. |
|
972 |
last := aKey last. |
|
973 |
keySize := aKey size. |
|
974 |
||
975 |
((first == $( and:[last == $) ]) |
|
976 |
or:[ (first == $[ and:[last == $] ]) |
|
977 |
or:[ (first == ${ and:[last == $} ]) ]]) ifTrue:[ |
|
8462 | 978 |
^ self shortenedKeyFor:(aKey copyFrom:2 to:keySize-1). |
6661 | 979 |
]. |
980 |
||
981 |
idx1 := aKey findFirst:[:ch | ch isSeparator not]. |
|
982 |
idx2 := aKey findLast:[:ch | ch isSeparator not] ifNone:keySize. |
|
983 |
(idx1 > 1 or:[idx2 < keySize]) ifTrue:[ |
|
8462 | 984 |
^ self shortenedKeyFor:(aKey copyFrom:idx1 to:idx2) |
6661 | 985 |
]. |
986 |
||
987 |
idx1 := aKey findFirst:[:ch | ('*:=.?!!,-><\' includes:ch) not]. |
|
988 |
idx2 := aKey findLast:[:ch | ('*:=.?!!,-><\' includes:ch) not] ifNone:keySize. |
|
989 |
(idx1 > 1 or:[idx2 < keySize]) ifTrue:[ |
|
8462 | 990 |
^ self shortenedKeyFor:(aKey copyFrom:idx1 to:idx2) |
6661 | 991 |
]. |
992 |
||
993 |
"/ change duplicated &'s to single |
|
994 |
(idx := aKey indexOf:$&) ~~ 0 ifTrue:[ |
|
8462 | 995 |
(aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[ |
996 |
^ self shortenedKeyFor:(aKey copyTo:idx-1),(aKey copyFrom:idx+1). |
|
997 |
]. |
|
6661 | 998 |
]. |
999 |
^ aKey. |
|
1000 |
||
1001 |
" |
|
1002 |
'abcde' findFirst:[:ch | 'bcd' includes:ch] |
|
1003 |
'abcde' indexOfAny:'bcd' |
|
1004 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1005 |
self shortenedKeyFor:'abc' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1006 |
self shortenedKeyFor:' abc ' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1007 |
self shortenedKeyFor:'(abc)' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1008 |
self shortenedKeyFor:'abc...' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1009 |
self shortenedKeyFor:'(abc...)' |
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1010 |
self shortenedKeyFor:'abc:*' |
6661 | 1011 |
" |
4509 | 1012 |
! ! |
1013 |
||
0 | 1014 |
!ResourcePack methodsFor:'accessing'! |
1015 |
||
244 | 1016 |
array:anArray |
1017 |
"translate a collection of strings" |
|
0 | 1018 |
|
244 | 1019 |
^ anArray collect:[:r | self at:r default:r] |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1020 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1021 |
" |
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1022 |
Launcher classResources array:#('file' 'classes') |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1023 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1024 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1025 |
"Modified: / 29.1.1998 / 22:44:22 / cg" |
0 | 1026 |
! |
1027 |
||
2 | 1028 |
at:aKey |
123 | 1029 |
"translate a string" |
1030 |
||
72 | 1031 |
^ self at:aKey ifAbsent:aKey |
0 | 1032 |
! |
1033 |
||
1034 |
at:aKey default:default |
|
123 | 1035 |
"translate a string" |
1036 |
||
72 | 1037 |
^ self at:aKey ifAbsent:default |
0 | 1038 |
! |
1039 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1040 |
at:aKey ifAbsent:defaultValue |
8630 | 1041 |
"translate a string; |
1042 |
search here, in my projects pack and in my superpack(s)" |
|
4617 | 1043 |
|
8630 | 1044 |
|val| |
4617 | 1045 |
|
1046 |
aKey isNil ifTrue:[ ^ defaultValue value ]. |
|
1047 |
||
8630 | 1048 |
"/ optional statistics on key usage |
8517 | 1049 |
usedKeys notNil ifTrue:[usedKeys add:aKey]. |
1050 |
||
4617 | 1051 |
val := self localAt:aKey. |
1052 |
val notNil ifTrue:[^ val]. |
|
1053 |
||
8461 | 1054 |
cache isNil ifTrue:[ cache := CacheDictionary new:1000 ]. |
1055 |
(val := cache at:aKey ifAbsent:nil) notNil ifTrue:[ |
|
1056 |
^ val |
|
1057 |
]. |
|
8630 | 1058 |
|
1059 |
self superPackHierarchyDo:[:eachPack | |
|
1060 |
val := eachPack localAt:aKey. |
|
1061 |
val notNil ifTrue:[ |
|
1062 |
cache at:aKey put:val. |
|
1063 |
^ val |
|
8461 | 1064 |
]. |
4617 | 1065 |
]. |
8510 | 1066 |
^ defaultValue value. |
4618 | 1067 |
|
1068 |
"Modified: / 18-09-2006 / 18:50:52 / cg" |
|
8630 | 1069 |
"Modified: / 20-02-2019 / 12:51:01 / Claus Gittinger" |
4617 | 1070 |
! |
1071 |
||
1072 |
localAt:aKey |
|
8630 | 1073 |
"translate a string from the local resourcePack; return nil if there is no xlation. |
4035 | 1074 |
Some special 'intelligence' has been added: |
8226 | 1075 |
if no value for aKey is found, |
8565 | 1076 |
lookup aKey with first character caseChanged and change the result's first characters case. |
1077 |
lookup aKey all lowercase and change the result's first characters case. |
|
8226 | 1078 |
or aKey is '(...)', then lookup ... wrap () around the result. |
1079 |
or aKey is '[...]', then lookup ... wrap [] around the result. |
|
1080 |
or aKey is '{...}', then lookup ... wrap {} around the result. |
|
8949 | 1081 |
or aKey starts with any of '\*<« ', then lookup aKey without the prefix and prepend prefix to the result. |
8639 | 1082 |
or aKey ends with ''%1'' , then lookup aKey without ''%1'' and append ''%1'' to the result. |
8949 | 1083 |
or aKey ends with any of '>»\:=.,?!!* ', then lookup aKey without the suffix and append suffix to the result. |
8226 | 1084 |
or aKey ends with a ' ...', then lookup aKey without ' ...' and append '...' to the result. |
1085 |
or aKey ends with a '...', then lookup aKey without '...' and append '...' to the result. |
|
1086 |
or aKey includes '&', then lookup aKey without '&'. |
|
4035 | 1087 |
|
1088 |
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
|
1089 |
things like |
8226 | 1090 |
'search' |
1091 |
'search:' |
|
1092 |
'search...' |
|
4035 | 1093 |
" |
123 | 1094 |
|
8949 | 1095 |
|val alternativeKey usedKey idx first last cutOff| |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1096 |
|
4617 | 1097 |
val := super at:aKey ifAbsent:nil. |
4678
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
1098 |
val notNil ifTrue:[ |
8226 | 1099 |
^ val value |
4678
0d83cc874dc3
block value handling changed
Claus Gittinger <cg@exept.de>
parents:
4673
diff
changeset
|
1100 |
]. |
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
1101 |
|
4848 | 1102 |
(aKey isString and:[aKey notEmpty]) ifTrue:[ |
8226 | 1103 |
first := aKey first. |
1104 |
last := aKey last. |
|
5573 | 1105 |
|
8226 | 1106 |
"/ try with case-first swapped... |
1107 |
first isLetter ifTrue:[ |
|
1108 |
alternativeKey := first isUppercase |
|
1109 |
ifTrue:[aKey asLowercaseFirst] |
|
1110 |
ifFalse:[aKey asUppercaseFirst]. |
|
1111 |
val := super at:alternativeKey ifAbsent:nil. |
|
1112 |
val notNil ifTrue:[ |
|
1113 |
first isUppercase ifTrue:[ |
|
1114 |
^ val asUppercaseFirst |
|
1115 |
]. |
|
1116 |
^ val asLowercaseFirst. |
|
1117 |
]. |
|
8565 | 1118 |
alternativeKey := aKey asLowercase. |
1119 |
val := super at:alternativeKey ifAbsent:nil. |
|
1120 |
val notNil ifTrue:[ |
|
1121 |
val first isUppercase ifTrue:[^ val]. |
|
1122 |
first isUppercase ifTrue:[ |
|
1123 |
^ val asUppercaseFirst |
|
1124 |
]. |
|
1125 |
^ val asLowercaseFirst. |
|
1126 |
]. |
|
8226 | 1127 |
]. |
4617 | 1128 |
|
8226 | 1129 |
((first == $( and:[last == $) ]) |
1130 |
or:[ (first == $[ and:[last == $] ]) |
|
1131 |
or:[ (first == ${ and:[last == $} ]) ]]) ifTrue:[ |
|
9001 | 1132 |
usedKey := aKey copyButFirstAndLast. |
5593 | 1133 |
|
8226 | 1134 |
val := self localAt:usedKey. "/ recursion |
1135 |
val notNil ifTrue:[^ first asString,val,last asString]. |
|
1136 |
]. |
|
8498 | 1137 |
last == $… ifTrue:[ |
1138 |
usedKey := aKey copyButLast:1. |
|
5593 | 1139 |
|
8498 | 1140 |
val := self localAt:usedKey. "/ recursion |
1141 |
val notNil ifTrue:[^ val , '…']. |
|
1142 |
]. |
|
1143 |
||
8226 | 1144 |
last == $. ifTrue:[ |
1145 |
(aKey endsWith:' ...') ifTrue:[ |
|
1146 |
usedKey := aKey copyButLast:4. |
|
5573 | 1147 |
|
8226 | 1148 |
val := self localAt:usedKey. "/ recursion |
8498 | 1149 |
val notNil ifTrue:[^ val , '...']. |
8226 | 1150 |
]. |
1151 |
(aKey endsWith:'...') ifTrue:[ |
|
1152 |
usedKey := aKey copyButLast:3. |
|
5573 | 1153 |
|
8226 | 1154 |
val := self localAt:usedKey. "/ recursion |
1155 |
val notNil ifTrue:[^ val , '...']. |
|
1156 |
]. |
|
1157 |
]. |
|
5573 | 1158 |
|
8226 | 1159 |
first isSeparator ifTrue:[ |
1160 |
usedKey := aKey withoutLeadingSeparators. |
|
4634 | 1161 |
|
8226 | 1162 |
val := self localAt:usedKey. "/ recursion |
1163 |
val notNil ifTrue:[^ (aKey copyTo:(aKey size - usedKey size)), val]. "/ prepend the stripped separators |
|
1164 |
]. |
|
1165 |
last isSeparator ifTrue:[ |
|
1166 |
usedKey := aKey withoutTrailingSeparators. |
|
4634 | 1167 |
|
8226 | 1168 |
val := self localAt:usedKey. "/ recursion |
1169 |
val notNil ifTrue:[^ val, (aKey copyFrom:usedKey size + 1)]. "/ append the stripped separators |
|
1170 |
]. |
|
4634 | 1171 |
|
8639 | 1172 |
(aKey endsWith:'"%1"') ifTrue:[ |
1173 |
usedKey := aKey withoutSuffix:'"%1"'. |
|
1174 |
val := self localAt:usedKey. "/ recursion |
|
1175 |
val notNil ifTrue:[^ val , '"%1"']. |
|
1176 |
]. |
|
8984 | 1177 |
(aKey endsWith:'%1') ifTrue:[ |
1178 |
usedKey := aKey withoutSuffix:'%1'. |
|
1179 |
val := self localAt:usedKey. "/ recursion |
|
1180 |
val notNil ifTrue:[^ val , '%1']. |
|
1181 |
]. |
|
1182 |
||
8719 | 1183 |
(';*:=.?!!,-><\/«»' includes:last) ifTrue:[ |
8226 | 1184 |
aKey size >= 2 ifTrue:[ |
8949 | 1185 |
idx := aKey findLast:[:ch | (';*:=.?!!,-><\/«»' includes:ch) not]. |
1186 |
idx ~~ 0 ifTrue:[ |
|
1187 |
cutOff := aKey copyFrom:idx+1. |
|
1188 |
usedKey := aKey copyTo:idx. |
|
1189 |
val := self localAt:usedKey. "/ recursion |
|
1190 |
val notNil ifTrue:[^ val , cutOff]. |
|
1191 |
^ nil |
|
1192 |
]. |
|
8226 | 1193 |
]. |
1194 |
]. |
|
8719 | 1195 |
(';*:=.?!!-><\/«»' includes:first) ifTrue:[ |
8226 | 1196 |
aKey size >= 2 ifTrue:[ |
8949 | 1197 |
idx := aKey findFirst:[:ch | (';*:=.?!!,-><\/«»' includes:ch) not]. |
1198 |
idx ~~ 0 ifTrue:[ |
|
1199 |
cutOff := aKey copyTo:idx-1. |
|
1200 |
usedKey := aKey copyFrom:idx. |
|
1201 |
val := self localAt:usedKey. "/ recursion |
|
1202 |
val notNil ifTrue:[^ cutOff , val]. |
|
1203 |
^ nil |
|
1204 |
]. |
|
8226 | 1205 |
]. |
1206 |
]. |
|
8949 | 1207 |
"/ try without '&'-char (but not if doubled) |
8226 | 1208 |
(idx := aKey indexOf:$&) ~~ 0 ifTrue:[ |
1209 |
(aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[ |
|
1210 |
usedKey := (aKey copyTo:idx-1) , (aKey copyFrom:idx+1). |
|
1211 |
val := self localAt:usedKey. "/ recursion |
|
1212 |
val notNil ifTrue:[^ val]. |
|
1213 |
]. |
|
1214 |
]. |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1215 |
]. |
4617 | 1216 |
^ nil. |
4580 | 1217 |
|
8949 | 1218 |
" |
1219 |
|pack| |
|
1220 |
||
1221 |
pack := ResourcePack new. |
|
1222 |
pack at:'foo' put:'bar'. |
|
1223 |
pack at:'foo'. |
|
1224 |
pack at:'foo-----'. |
|
1225 |
pack at:'-----foo'. |
|
1226 |
pack at:'-----foo-----'. |
|
1227 |
pack at:'-----...-----'. |
|
1228 |
" |
|
1229 |
||
4617 | 1230 |
"Created: / 18-09-2006 / 17:33:27 / cg" |
5593 | 1231 |
"Modified: / 05-08-2010 / 16:52:32 / sr" |
8226 | 1232 |
"Modified: / 27-11-2017 / 15:33:48 / cg" |
8639 | 1233 |
"Modified: / 27-02-2019 / 16:12:38 / Claus Gittinger" |
2 | 1234 |
! |
1235 |
||
1236 |
name:aKey default:default |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1237 |
"translate a string. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1238 |
Obsolete - use #string:default:" |
123 | 1239 |
|
4844 | 1240 |
<resource: #obsolete> |
1241 |
||
72 | 1242 |
^ self at:aKey ifAbsent:default |
2 | 1243 |
! |
1244 |
||
8630 | 1245 |
resourcePackContainingKey:aKey |
1246 |
"returns the resolving resourcePack or nil." |
|
1247 |
||
1248 |
|val| |
|
1249 |
||
1250 |
aKey isNil ifTrue:[^ nil ]. |
|
1251 |
||
1252 |
val := self localAt:aKey. |
|
1253 |
val notNil ifTrue:[^ self]. |
|
1254 |
||
1255 |
self superPackHierarchyDo:[:eachPack | |
|
1256 |
val := eachPack localAt:aKey. |
|
1257 |
val notNil ifTrue:[ |
|
1258 |
^ eachPack. |
|
1259 |
]. |
|
1260 |
]. |
|
1261 |
^ nil. |
|
1262 |
||
1263 |
" |
|
1264 |
Workspace classResources resourcePackContainingKey:'Cancel' |
|
1265 |
WorkspaceApplication classResources resourcePackContainingKey:'Cancel' |
|
1266 |
" |
|
1267 |
||
1268 |
"Created: / 20-02-2019 / 12:46:32 / Claus Gittinger" |
|
1269 |
! |
|
1270 |
||
0 | 1271 |
string:s |
3097 | 1272 |
"translate (retrieve) a string - if not present, return s" |
123 | 1273 |
|
72 | 1274 |
^ self at:s ifAbsent:s |
3097 | 1275 |
|
1276 |
" |
|
1277 |
NewLauncher classResources |
|
8462 | 1278 |
string:'LICENCEFILE' |
3097 | 1279 |
" |
0 | 1280 |
! |
1281 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1282 |
string:s default:defaultString |
3097 | 1283 |
"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
|
1284 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1285 |
^ self at:s ifAbsent:defaultString |
3097 | 1286 |
|
1287 |
" |
|
1288 |
NewLauncher classResources |
|
8462 | 1289 |
string:'fooBar' default:'Hello world' |
3097 | 1290 |
" |
1291 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1292 |
! |
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 |
string:s default:defaultString with:arg |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1295 |
"translate and expand arg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1296 |
|
8445 | 1297 |
^ self string:s default:defaultString withArguments:(Array with:arg) |
3097 | 1298 |
|
1299 |
" |
|
1300 |
NewLauncher classResources |
|
8445 | 1301 |
string:'%1 fooBar' default:'Hello %1' with:'foo' |
3097 | 1302 |
" |
1303 |
||
8445 | 1304 |
"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
|
1305 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1306 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1307 |
string:s default:defaultString with:arg1 with:arg2 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1308 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1309 |
|
8445 | 1310 |
^ self string:s default:defaultString withArguments:(Array with:arg1 with:arg2) |
1311 |
||
1312 |
"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
|
1313 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1314 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1315 |
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
|
1316 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1317 |
|
8445 | 1318 |
^ 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
|
1319 |
|
8445 | 1320 |
"Created: / 09-12-1995 / 19:08:50 / cg" |
1321 |
"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
|
1322 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1323 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1324 |
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
|
1325 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1326 |
|
8445 | 1327 |
^ 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
|
1328 |
|
8445 | 1329 |
"Created: / 09-09-1996 / 18:52:14 / cg" |
1330 |
"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
|
1331 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1332 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1333 |
string:s default:defaultString withArgs:argArray |
8445 | 1334 |
<resource: #obsolete> |
1335 |
"translate and expand args" |
|
1336 |
||
1337 |
^ self string:s default:defaultString withArguments:argArray |
|
1338 |
||
1339 |
"Modified: / 09-08-2018 / 14:55:38 / Claus Gittinger" |
|
1340 |
! |
|
1341 |
||
1342 |
string:s default:defaultString withArguments:argArray |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1343 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1344 |
|
5070 | 1345 |
|template| |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1346 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1347 |
template := self at:s ifAbsent:defaultString. |
5070 | 1348 |
^ template expandPlaceholdersWith:argArray. |
8445 | 1349 |
|
1350 |
"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
|
1351 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1352 |
|
0 | 1353 |
string:s with:arg |
123 | 1354 |
"translate and expand arg" |
1355 |
||
8445 | 1356 |
^ self string:s withArguments:(Array with:arg) |
1357 |
||
1358 |
"Modified: / 09-08-2018 / 14:56:02 / Claus Gittinger" |
|
0 | 1359 |
! |
1360 |
||
1361 |
string:s with:arg1 with:arg2 |
|
123 | 1362 |
"translate and expand args" |
1363 |
||
8445 | 1364 |
^ self string:s withArguments:(Array with:arg1 with:arg2) |
1365 |
||
1366 |
"Modified: / 09-08-2018 / 14:56:04 / Claus Gittinger" |
|
0 | 1367 |
! |
1368 |
||
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1369 |
string:s with:arg1 with:arg2 with:arg3 |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1370 |
"translate and expand args" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1371 |
|
8445 | 1372 |
^ 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
|
1373 |
|
8445 | 1374 |
"Created: / 09-12-1995 / 19:08:50 / cg" |
1375 |
"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
|
1376 |
! |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
1377 |
|
1042 | 1378 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 |
1379 |
"translate and expand args" |
|
1380 |
||
8445 | 1381 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
1042 | 1382 |
|
8445 | 1383 |
"Created: / 09-09-1996 / 18:52:14 / cg" |
1384 |
"Modified: / 09-08-2018 / 14:56:09 / Claus Gittinger" |
|
1042 | 1385 |
! |
1386 |
||
3184 | 1387 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
1388 |
"translate and expand args" |
|
1389 |
||
8445 | 1390 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
3184 | 1391 |
|
8445 | 1392 |
"Modified: / 09-08-2018 / 14:56:12 / Claus Gittinger" |
3184 | 1393 |
! |
1394 |
||
5652 | 1395 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
1396 |
"translate and expand args" |
|
1397 |
||
8445 | 1398 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6) |
5652 | 1399 |
|
1400 |
"Created: / 13-11-2010 / 11:35:00 / cg" |
|
8445 | 1401 |
"Modified: / 09-08-2018 / 14:56:14 / Claus Gittinger" |
5652 | 1402 |
! |
1403 |
||
1404 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7 |
|
1405 |
"translate and expand args" |
|
1406 |
||
8445 | 1407 |
^ self string:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7) |
5652 | 1408 |
|
1409 |
"Created: / 13-11-2010 / 11:35:07 / cg" |
|
8445 | 1410 |
"Modified: / 09-08-2018 / 14:55:07 / Claus Gittinger" |
5652 | 1411 |
! |
1412 |
||
0 | 1413 |
string:s withArgs:argArray |
8445 | 1414 |
<resource: #obsolete> |
1415 |
"translate and expand args - allow text as arguments" |
|
1416 |
||
1417 |
^ self string:s withArguments:argArray |
|
1418 |
||
1419 |
"Modified: / 09-08-2018 / 14:54:54 / Claus Gittinger" |
|
1420 |
! |
|
1421 |
||
1422 |
string:s withArguments:argArray |
|
4932
b19b928b0026
Allow (and insert) Texts as arguments in #string:with:
Stefan Vogel <sv@exept.de>
parents:
4848
diff
changeset
|
1423 |
"translate and expand args - allow text as arguments" |
123 | 1424 |
|
5069 | 1425 |
|template| |
0 | 1426 |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
1427 |
template := self at:s ifAbsent:s. |
5069 | 1428 |
^ template expandPlaceholdersWith:argArray. |
4932
b19b928b0026
Allow (and insert) Texts as arguments in #string:with:
Stefan Vogel <sv@exept.de>
parents:
4848
diff
changeset
|
1429 |
|
8445 | 1430 |
"Created: / 09-08-2018 / 14:54:43 / Claus Gittinger" |
3823 | 1431 |
! |
1432 |
||
4402 | 1433 |
stringWithCRs:s |
8459 | 1434 |
"translate (retrieve) a string - if not present, return s. |
1435 |
replaces \'s with CRs" |
|
4402 | 1436 |
|
8779 | 1437 |
^ self stringWithCRs:s withArguments:#() |
4402 | 1438 |
|
1439 |
" |
|
1440 |
NewLauncher classResources |
|
8459 | 1441 |
stringWithCRs:'LICENCEFILE' |
4402 | 1442 |
" |
8459 | 1443 |
|
1444 |
"Modified: / 07-09-2018 / 12:43:00 / Claus Gittinger" |
|
4402 | 1445 |
! |
1446 |
||
3823 | 1447 |
stringWithCRs:s with:arg |
1448 |
"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
|
1449 |
CR-replacement is donw before args are inserted |
3823 | 1450 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1451 |
||
8445 | 1452 |
^ self stringWithCRs:s withArguments:(Array with:arg) |
3823 | 1453 |
|
8445 | 1454 |
"Modified: / 21-03-2003 / 14:22:09 / cg" |
1455 |
"Modified: / 09-08-2018 / 14:56:21 / Claus Gittinger" |
|
3823 | 1456 |
! |
1457 |
||
1458 |
stringWithCRs:s with:arg1 with:arg2 |
|
1459 |
"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
|
1460 |
CR-replacement is donw before args are inserted |
3823 | 1461 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1462 |
||
8445 | 1463 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2) |
3823 | 1464 |
|
8445 | 1465 |
"Modified: / 21-03-2003 / 14:22:06 / cg" |
1466 |
"Modified: / 09-08-2018 / 14:56:25 / Claus Gittinger" |
|
3823 | 1467 |
! |
1468 |
||
1469 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 |
|
1470 |
"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
|
1471 |
CR-replacement is donw before args are inserted |
3823 | 1472 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1473 |
||
8445 | 1474 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3) |
3823 | 1475 |
|
8445 | 1476 |
"Created: / 09-12-1995 / 19:08:50 / cg" |
1477 |
"Modified: / 09-08-2018 / 14:56:27 / Claus Gittinger" |
|
3823 | 1478 |
! |
1479 |
||
1480 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 |
|
1481 |
"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
|
1482 |
CR-replacement is donw before args are inserted |
3823 | 1483 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1484 |
||
8445 | 1485 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
3823 | 1486 |
|
8445 | 1487 |
"Modified: / 21-03-2003 / 14:21:48 / cg" |
1488 |
"Modified: / 09-08-2018 / 14:56:30 / Claus Gittinger" |
|
3823 | 1489 |
! |
1490 |
||
1491 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
1492 |
"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
|
1493 |
CR-replacement is donw before args are inserted |
3823 | 1494 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1495 |
||
8445 | 1496 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
3823 | 1497 |
|
8445 | 1498 |
"Modified: / 21-03-2003 / 14:21:55 / cg" |
1499 |
"Modified: / 09-08-2018 / 14:56:32 / Claus Gittinger" |
|
3823 | 1500 |
! |
1501 |
||
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1502 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
5652 | 1503 |
"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
|
1504 |
CR-replacement is donw before args are inserted |
5652 | 1505 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1506 |
||
8445 | 1507 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6) |
5652 | 1508 |
|
1509 |
"Created: / 13-11-2010 / 11:35:30 / cg" |
|
8445 | 1510 |
"Modified: / 09-08-2018 / 14:56:35 / Claus Gittinger" |
5652 | 1511 |
! |
1512 |
||
1513 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7 |
|
1514 |
"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
|
1515 |
CR-replacement is donw before args are inserted |
5652 | 1516 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
1517 |
||
8445 | 1518 |
^ self stringWithCRs:s withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 with:arg7) |
5652 | 1519 |
|
1520 |
"Created: / 13-11-2010 / 11:35:20 / cg" |
|
8445 | 1521 |
"Modified: / 09-08-2018 / 14:56:37 / Claus Gittinger" |
5652 | 1522 |
! |
1523 |
||
3823 | 1524 |
stringWithCRs:s withArgs:argArray |
8445 | 1525 |
<resource: #obsolete> |
1526 |
"translate, replace \'s with CRs and finally expand args. |
|
1527 |
CR-replacement is done before args are inserted |
|
1528 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
1529 |
||
1530 |
^ self stringWithCRs:s withArguments:argArray |
|
1531 |
||
1532 |
"Modified: / 09-08-2018 / 14:54:29 / Claus Gittinger" |
|
1533 |
! |
|
1534 |
||
1535 |
stringWithCRs:s withArguments:argArray |
|
3823 | 1536 |
"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
|
1537 |
CR-replacement is done before args are inserted |
8779 | 1538 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated. |
1539 |
If there is no xlation for the whole string, |
|
1540 |
try xlations for individual line." |
|
3823 | 1541 |
|
8779 | 1542 |
|xlation collectedXLations| |
3823 | 1543 |
|
8459 | 1544 |
(s startsWith:':c:') ifTrue:[ |
1545 |
^ (self string:(s withoutPrefix:':c:')) withoutCEscapes expandPlaceholdersWith:argArray |
|
1546 |
]. |
|
1547 |
(s startsWith:':st:') ifTrue:[ |
|
1548 |
^ (self string:(s withoutPrefix:':st:')) expandPlaceholdersWith:argArray |
|
1549 |
]. |
|
8779 | 1550 |
xlation := self at:s ifAbsent:nil. |
1551 |
xlation notNil ifTrue:[ |
|
1552 |
^ xlation withCRs expandPlaceholdersWith:argArray. |
|
1553 |
]. |
|
1554 |
"/ try individual lines... |
|
8914 | 1555 |
collectedXLations := s withCRs asStringCollection collect:[:eachLine | self string:eachLine withArguments:argArray]. |
1556 |
(s endsWith:$\) ifTrue:[^ collectedXLations asString]. |
|
8779 | 1557 |
^ collectedXLations asStringWithoutFinalCR |
1558 |
||
1559 |
" |
|
1560 |
stx_libview classResources string:'Copy\Paste' |
|
1561 |
stx_libview classResources stringWithCRs:'Copy\Paste' |
|
1562 |
stx_libtool classResources stringWithCRs:'copy\paste' |
|
1563 |
" |
|
8445 | 1564 |
|
1565 |
"Created: / 09-08-2018 / 14:54:16 / Claus Gittinger" |
|
8459 | 1566 |
"Modified: / 07-09-2018 / 12:44:06 / Claus Gittinger" |
6174 | 1567 |
! |
1568 |
||
8630 | 1569 |
superPackHierarchyDo:aBlock |
1570 |
"evaluate aBlock for all of the searched super packs; |
|
1571 |
that is my project's pack and my superpack(s)" |
|
1572 |
||
1573 |
|pack alreadySearched toSearch more| |
|
1574 |
||
1575 |
superPacks notEmptyOrNil ifTrue:[ |
|
1576 |
alreadySearched := Set new. |
|
1577 |
toSearch := OrderedCollection withAll:superPacks. |
|
1578 |
[toSearch notEmpty] whileTrue:[ |
|
1579 |
pack := toSearch removeFirst. |
|
1580 |
(alreadySearched includes:pack packsFileName) ifFalse:[ |
|
1581 |
aBlock value:pack. |
|
1582 |
||
1583 |
alreadySearched add:pack packsFileName. |
|
1584 |
(more := pack superPacks) notEmptyOrNil ifTrue:[ |
|
1585 |
self assert:(more conform:[:each | each isNil or:[pack isKindOf:ResourcePack]]). |
|
1586 |
toSearch addAll:more. |
|
1587 |
]. |
|
1588 |
]. |
|
1589 |
]. |
|
1590 |
]. |
|
1591 |
||
1592 |
"Created: / 20-02-2019 / 12:49:56 / Claus Gittinger" |
|
1593 |
! |
|
1594 |
||
6174 | 1595 |
whichPackIncludesKey:aKey |
1596 |
"for debugging: return the pack (alogn the super-pack chain), which |
|
1597 |
has a translation for a string" |
|
1598 |
||
8510 | 1599 |
|val pack projectPack alreadySearched toSearch| |
6174 | 1600 |
|
1601 |
aKey isNil ifTrue:[ ^ nil ]. |
|
1602 |
||
1603 |
val := self localAt:aKey. |
|
1604 |
val notNil ifTrue:[^ self]. |
|
1605 |
||
8516 | 1606 |
superPacks isEmptyOrNil ifTrue:[^ nil]. |
6174 | 1607 |
|
8510 | 1608 |
alreadySearched := Set new. |
1609 |
toSearch := OrderedCollection withAll:superPacks. |
|
1610 |
[toSearch notEmpty] whileTrue:[ |
|
1611 |
pack := toSearch removeFirst. |
|
1612 |
(alreadySearched includes:pack) ifFalse:[ |
|
1613 |
val := pack localAt:aKey. |
|
1614 |
val notNil ifTrue:[^ pack]. |
|
1615 |
alreadySearched add:pack. |
|
1616 |
toSearch addAll:(pack superPacks). |
|
8462 | 1617 |
]. |
6174 | 1618 |
]. |
8510 | 1619 |
^ nil. |
1620 |
||
1621 |
"/ (projectPack := self projectPack) notNil ifTrue:[ |
|
1622 |
"/ val := projectPack localAt:aKey. |
|
1623 |
"/ val notNil ifTrue:[^ projectPack]. |
|
1624 |
"/ ]. |
|
1625 |
"/ alreadySearched := Set new. |
|
1626 |
"/ projectPack notNil ifTrue:[ alreadySearched add:projectPack ]. |
|
1627 |
"/ |
|
1628 |
"/ pack := self superPack. |
|
1629 |
"/ [ pack notNil ] whileTrue:[ |
|
1630 |
"/ val := pack localAt:aKey. |
|
1631 |
"/ val notNil ifTrue:[^ pack]. |
|
1632 |
"/ |
|
1633 |
"/ (projectPack := pack projectPack) notNil ifTrue:[ |
|
1634 |
"/ (alreadySearched includes:projectPack) ifFalse:[ |
|
1635 |
"/ val := projectPack localAt:aKey. |
|
1636 |
"/ val notNil ifTrue:[^ projectPack]. |
|
1637 |
"/ alreadySearched add:projectPack. |
|
1638 |
"/ ]. |
|
1639 |
"/ ]. |
|
1640 |
"/ pack := pack superPack |
|
1641 |
"/ ]. |
|
1642 |
"/ |
|
1643 |
"/ alreadySearched copy do:[:projectPack | |
|
1644 |
"/ |p| |
|
1645 |
"/ |
|
1646 |
"/ p := projectPack superPack. |
|
1647 |
"/ [p notNil and:[(alreadySearched includes:p) not]] whileTrue:[ |
|
1648 |
"/ val := p localAt:aKey. |
|
1649 |
"/ val notNil ifTrue:[^ p]. |
|
1650 |
"/ alreadySearched add:p. |
|
1651 |
"/ p := p superPack. |
|
1652 |
"/ ]. |
|
1653 |
"/ ]. |
|
1654 |
"/ |
|
1655 |
"/ ^ nil |
|
0 | 1656 |
! ! |
1657 |
||
3317 | 1658 |
!ResourcePack methodsFor:'accessing-internals'! |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1659 |
|
8510 | 1660 |
addSuperPack:anotherResourcePack |
1661 |
(anotherResourcePack == self) ifTrue:[ |
|
1662 |
^ self |
|
1663 |
]. |
|
1664 |
superPacks isNil ifTrue:[ superPacks := OrderedCollection new ]. |
|
1665 |
(superPacks includes:anotherResourcePack) ifFalse:[ |
|
1666 |
self assert:(anotherResourcePack isKindOf:ResourcePack). |
|
1667 |
superPacks add:anotherResourcePack |
|
1668 |
]. |
|
1669 |
! |
|
1670 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1671 |
name:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1672 |
"translate a string" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1673 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1674 |
^ self at:aKey ifAbsent:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1675 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1676 |
|
8517 | 1677 |
packsFileName |
1678 |
^ packsFileName |
|
1679 |
! |
|
1680 |
||
1681 |
packsPackage |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1682 |
^ packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1683 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1684 |
|
8517 | 1685 |
packsPackage:aPackage |
1686 |
packsClassName := aPackage |
|
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1687 |
! |
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1688 |
|
4617 | 1689 |
projectPack |
1690 |
^ projectPack |
|
1691 |
||
1692 |
"Created: / 18-09-2006 / 17:38:07 / cg" |
|
1693 |
! |
|
1694 |
||
8510 | 1695 |
superPacks |
1696 |
^ superPacks ? #() |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1697 |
! ! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1698 |
|
0 | 1699 |
!ResourcePack methodsFor:'file reading'! |
1700 |
||
684 | 1701 |
fileReadFailed |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1702 |
"return true, if the pack does not really contain |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1703 |
valid translations, since the fileRead failed. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1704 |
However, all inherited translations are still available |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1705 |
through the receiver" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1706 |
|
687 | 1707 |
^ fileReadFailed ~~ false |
684 | 1708 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1709 |
"Created: / 14.5.1996 / 10:19:26 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1710 |
"Modified: / 29.1.1998 / 22:46:38 / cg" |
684 | 1711 |
! |
1712 |
||
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1713 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1714 |
"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
|
1715 |
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
|
1716 |
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
|
1717 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1718 |
^ nil |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1719 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1720 |
"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
|
1721 |
! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1722 |
|
4332 | 1723 |
processLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError |
145 | 1724 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
1725 |
||
4509 | 1726 |
self class |
8462 | 1727 |
processResourceLine:lineString |
1728 |
encoding:encodingSymbolOrEncoder |
|
1729 |
file:fileName |
|
1730 |
printErrorWith:printError |
|
1731 |
for:self |
|
9002 | 1732 |
keepUselessTranslations:false |
144 | 1733 |
! |
1734 |
||
244 | 1735 |
readFromFile:fileName directory:dirName |
1736 |
"read definitions from a file in a directory" |
|
1737 |
||
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1738 |
|triedFilename inStream ok| |
244 | 1739 |
|
686 | 1740 |
fileReadFailed := false. |
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1741 |
"/ 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
|
1742 |
"/ (happens when da.rs is not present in libbasic/resources.rs) |
8959 | 1743 |
OpenError handle:[:ex | |
8462 | 1744 |
Transcript showCR:'ResourcePack: failed to open file: ',fileName asString,' in ',dirName asString. |
1745 |
inStream := nil. |
|
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1746 |
] do:[ |
8462 | 1747 |
dirName = 'resources' ifTrue:[ |
1748 |
inStream := Smalltalk resourceFileStreamFor:fileName |
|
1749 |
] ifFalse:[ |
|
1750 |
inStream := Smalltalk systemFileStreamFor: |
|
1751 |
(dirName isNil |
|
1752 |
ifTrue:[fileName] |
|
1753 |
ifFalse:[dirName asFilename construct:fileName]). |
|
1754 |
]. |
|
244 | 1755 |
]. |
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1756 |
|
8515 | 1757 |
"/ '7) inStream ' print. inStream printCR. |
8512 | 1758 |
|
244 | 1759 |
inStream isNil ifTrue:[ |
8462 | 1760 |
" |
1761 |
an empty pack |
|
1762 |
" |
|
1763 |
^ self nonexistingFileRead |
|
244 | 1764 |
]. |
2996 | 1765 |
|
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1766 |
triedFilename := inStream pathName. |
8675 | 1767 |
Error handle:[:ex | |
1768 |
Logger warning:'ResourcePack [warning]: aborted read of "%1" due to error: %2' |
|
1769 |
with:triedFilename |
|
1770 |
with:ex description. |
|
1771 |
ok := false. |
|
1772 |
] do:[ |
|
1773 |
[ |
|
1774 |
ok := self readFromResourceStream:inStream in:(triedFilename asFilename directoryName). |
|
1775 |
] ensure:[ |
|
1776 |
inStream close. |
|
1777 |
]. |
|
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1778 |
]. |
8675 | 1779 |
|
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1780 |
ok ifTrue:[ |
8462 | 1781 |
packsFileName := triedFilename |
5951
61a41352ce81
remember the actual filename from which a pack was read
Claus Gittinger <cg@exept.de>
parents:
5826
diff
changeset
|
1782 |
] ifFalse:[ |
8462 | 1783 |
fileReadFailed := true. |
684 | 1784 |
|
8667 | 1785 |
Logger warning:'ResourcePack [warning]: "%1" contains error(s) - data may be incomplete.' |
1786 |
with:triedFilename. |
|
244 | 1787 |
]. |
1788 |
||
5781
fc35ed4fd223
changed: #readFromFile:directory:
Claus Gittinger <cg@exept.de>
parents:
5653
diff
changeset
|
1789 |
"Modified: / 20-08-2011 / 17:10:02 / cg" |
8675 | 1790 |
"Modified: / 06-05-2019 / 13:57:25 / Claus Gittinger" |
244 | 1791 |
! |
1792 |
||
72 | 1793 |
readFromResourceStream:inStream in:dirName |
4848 | 1794 |
"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
|
1795 |
specify where #include files are searched for. |
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1796 |
Return true, if the style sheet could be read without errors, false otherwise." |
145 | 1797 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1798 |
|lineString l lineNumber rest value ifLevel skipping first ok encoding decoder pack errorHandler |
4947 | 1799 |
printError fileName pushedSkipValues| |
4058 | 1800 |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
1801 |
fileName := (inStream isFileStream |
8636 | 1802 |
ifTrue:[inStream baseName] |
6992 | 1803 |
ifFalse:['---']). |
4058 | 1804 |
|
8667 | 1805 |
DebugResources == true ifTrue:[ |
1806 |
printError := [:message | |
|
1807 |
Logger warning:'ResourcePack [warning]: %1 in file: %2 line: %3' |
|
1808 |
with:message |
|
1809 |
with:fileName |
|
1810 |
with:lineNumber. |
|
1811 |
]. |
|
1812 |
] ifFalse:[ |
|
1813 |
printError := [:message | ]. |
|
1814 |
]. |
|
1815 |
||
462
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1816 |
encoding := nil. |
0 | 1817 |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1818 |
ok := true. |
0 | 1819 |
ifLevel := 0. |
1820 |
skipping := false. |
|
4058 | 1821 |
lineNumber := 0. |
4947 | 1822 |
pushedSkipValues := OrderedCollection new. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1823 |
|
8667 | 1824 |
errorHandler := |
1825 |
[:ex | |
|
1826 |
|con count| |
|
4947 | 1827 |
|
8667 | 1828 |
Logger warning:'ResourcePack [warning]: "%1"' with:ex description. |
1829 |
Logger warning:'ResourcePack [info]: in: %1 [%2]: "%3"' |
|
1830 |
with:inStream pathName |
|
1831 |
with:lineNumber |
|
1832 |
with:lineString. |
|
1833 |
con := ex suspendedContext. |
|
1834 |
Logger warning:'ResourcePack [info]: in: %1' with:con fullPrintString. |
|
1835 |
con := con sender. |
|
1836 |
count := 1. |
|
1837 |
[con notNil and:[count <= 20]] whileTrue:[ |
|
1838 |
Logger warning:'ResourcePack [info]: : %1' with:con fullPrintString. |
|
1839 |
count := count + 1. |
|
1840 |
con := con sender. |
|
1841 |
]. |
|
1842 |
value := nil. |
|
1843 |
ok := false. |
|
1844 |
]. |
|
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1845 |
|
0 | 1846 |
[inStream atEnd] whileFalse:[ |
6992 | 1847 |
lineString := inStream nextLine. lineNumber := lineNumber + 1. |
1848 |
[lineString notNil and:[lineString endsWith:$\]] whileTrue:[ |
|
1849 |
lineString := lineString copyButLast:1. |
|
1850 |
l := inStream nextLine. lineNumber := lineNumber + 1. |
|
1851 |
l notNil ifTrue:[ |
|
1852 |
lineString := lineString , l. |
|
1853 |
]. |
|
1854 |
]. |
|
177 | 1855 |
|
8650 | 1856 |
(lineString size ~~ 0) ifTrue:[ |
6992 | 1857 |
first := lineString at:1. |
1858 |
"/ |
|
1859 |
"/ for your convenience: treat both ';' AND '"/' as comment-line |
|
1860 |
"/ |
|
1861 |
((first == $;) or:[lineString startsWith:'"/']) ifFalse:[ |
|
1862 |
((first == $#) and:[(lineString startsWith:'#(') not]) ifTrue:[ |
|
1863 |
"/ a directive |
|
1864 |
lineString := (lineString copyFrom:2) withoutSpaces. |
|
72 | 1865 |
|
6992 | 1866 |
(lineString startsWith:'if') ifTrue:[ |
1867 |
pushedSkipValues add:skipping. |
|
1868 |
skipping ifFalse:[ |
|
1869 |
rest := lineString copyFrom:3. |
|
1870 |
Error, UserInformation |
|
1871 |
handle:errorHandler |
|
1872 |
do:[ |
|
1873 |
value := Compiler evaluate:rest compile:false. |
|
1874 |
]. |
|
1875 |
(value == #Error) ifTrue:[ |
|
1876 |
printError value:('error in resource:' , lineString). |
|
1877 |
]. |
|
1878 |
(value == false) ifTrue:[ |
|
1879 |
skipping := true |
|
1880 |
] |
|
1881 |
]. |
|
1882 |
ifLevel := ifLevel + 1 |
|
1883 |
] ifFalse:[ |
|
1884 |
(lineString startsWith:'endif') ifTrue:[ |
|
1885 |
ifLevel == 0 ifTrue:[ |
|
1886 |
printError value:('if/endif nesting error'). |
|
1887 |
] ifFalse:[ |
|
1888 |
ifLevel := ifLevel - 1. |
|
1889 |
skipping := pushedSkipValues removeLast. |
|
1890 |
] |
|
1891 |
] ifFalse:[ |
|
1892 |
(lineString startsWith:'else') ifTrue:[ |
|
1893 |
(pushedSkipValues includes:true) ifFalse:[ |
|
1894 |
skipping := skipping not |
|
1895 |
] |
|
1896 |
] ifFalse:[ |
|
1897 |
skipping ifFalse:[ |
|
1898 |
(lineString startsWith:'superpack') ifTrue:[ |
|
1899 |
rest := lineString copyFrom:('superpack' size + 1). |
|
1900 |
value := Compiler evaluate:rest compile:false. |
|
1901 |
(value isKindOf:ResourcePack) ifTrue:[ |
|
8517 | 1902 |
self addSuperPack:value. |
6992 | 1903 |
] |
1904 |
] ifFalse:[ |
|
1905 |
(lineString startsWith:'include') ifTrue:[ |
|
1906 |
(lineString startsWith:'includeResourcesFor') ifTrue:[ |
|
1907 |
"/ include those resources ... |
|
1908 |
rest := lineString copyFrom:('includeResourcesFor' size + 1). |
|
1909 |
value := Compiler evaluate:rest compile:false. |
|
1910 |
value isBehavior ifTrue:[ |
|
1911 |
pack := self class for:value. |
|
1912 |
pack notNil ifTrue:[ |
|
1913 |
self addAll:pack. |
|
1914 |
] |
|
1915 |
] |
|
1916 |
] ifFalse:[ |
|
1917 |
rest := lineString copyFrom:('include' size + 1). |
|
1918 |
value := Compiler evaluate:rest compile:false. |
|
1919 |
value isString ifFalse:[ |
|
1920 |
printError value:('bad include filename: ' , value printString, ' "',lineString,'"'). |
|
1921 |
] ifTrue:[ |
|
1922 |
self readFromFile:value directory:dirName |
|
1923 |
] |
|
1924 |
] |
|
1925 |
] ifFalse:[ |
|
1926 |
(lineString startsWith:'encoding') ifTrue:[ |
|
4848 | 1927 |
"/decoder notNil ifTrue:[self halt:'oops - encoding change in file']. |
6992 | 1928 |
encoding := self class extractEncodingFromLine:lineString. |
1929 |
decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil. |
|
1930 |
] |
|
1931 |
] |
|
1932 |
] |
|
1933 |
] |
|
1934 |
] |
|
1935 |
] |
|
1936 |
]. |
|
1937 |
] ifFalse:[ |
|
1938 |
skipping ifFalse:[ |
|
1939 |
Error, UserInformation |
|
1940 |
handle:errorHandler |
|
1941 |
do:[ |
|
1942 |
(lineString at:1) == $!! ifTrue:[ |
|
1943 |
"/ evaluate the rest |
|
1944 |
Compiler evaluate:(lineString copyFrom:2) |
|
1945 |
receiver:self |
|
1946 |
notifying:nil |
|
1947 |
compile:false. |
|
1948 |
] ifFalse:[ |
|
1949 |
"/ process as resource |
|
8667 | 1950 |
self class |
1951 |
processResourceLine:lineString |
|
6992 | 1952 |
encoding:decoder |
1953 |
file:(inStream isFileStream |
|
1954 |
ifTrue:[inStream pathName] |
|
1955 |
ifFalse:['---']) |
|
1956 |
printErrorWith:printError |
|
8667 | 1957 |
for:self |
9002 | 1958 |
keepUselessTranslations:false |
6992 | 1959 |
]] |
1960 |
] |
|
1961 |
] |
|
1962 |
] |
|
1963 |
] |
|
0 | 1964 |
]. |
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1965 |
^ ok |
177 | 1966 |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
1967 |
"Modified: / 31-08-1995 / 02:33:45 / claus" |
4619 | 1968 |
"Modified: / 18-09-2006 / 20:35:37 / cg" |
8496 | 1969 |
"Modified: / 10-10-2018 / 14:14:00 / sr" |
8637 | 1970 |
"Modified: / 22-02-2019 / 17:13:13 / Stefan Vogel" |
8667 | 1971 |
"Modified: / 27-03-2019 / 12:01:12 / Claus Gittinger" |
0 | 1972 |
! ! |
1973 |
||
8509 | 1974 |
|
4093 | 1975 |
!ResourcePack methodsFor:'printing & storing'! |
1976 |
||
5603
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1977 |
displayOn:aGCOrStream |
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1978 |
|
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1979 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
7931 | 1980 |
"/ old ST80 means: draw-yourself on a GC. |
1981 |
(aGCOrStream isStream) ifFalse:[ |
|
1982 |
^ super displayOn:aGCOrStream |
|
5603
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1983 |
]. |
0945abfddb9a
Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
5593
diff
changeset
|
1984 |
|
8710 | 1985 |
aGCOrStream nextPutAll:self className. |
8667 | 1986 |
packsClassName notNil ifTrue:[ |
1987 |
aGCOrStream nextPutAll:' for: '. |
|
1988 |
packsClassName printOn:aGCOrStream. |
|
1989 |
] ifFalse:[ |
|
1990 |
aGCOrStream nextPutAll:' from: '. |
|
1991 |
packsFileName printOn:aGCOrStream. |
|
1992 |
]. |
|
7931 | 1993 |
|
1994 |
"Modified: / 22-02-2017 / 17:00:31 / cg" |
|
8710 | 1995 |
"Modified: / 28-06-2019 / 09:07:53 / Claus Gittinger" |
4093 | 1996 |
! ! |
1997 |
||
8461 | 1998 |
!ResourcePack methodsFor:'statistics'! |
1999 |
||
2000 |
forgetUsedKeys |
|
2001 |
"stop keeping a statistic on which keys are actually used" |
|
2002 |
||
2003 |
usedKeys := nil. |
|
2004 |
||
2005 |
"Modified (comment): / 12-09-2018 / 18:23:27 / Claus Gittinger" |
|
2006 |
! |
|
2007 |
||
2008 |
rememberUsedKeys |
|
2009 |
"start keeping a statistic on which keys are actually used" |
|
2010 |
||
2011 |
usedKeys := Set new. |
|
2012 |
||
2013 |
"Modified (comment): / 12-09-2018 / 18:23:22 / Claus Gittinger" |
|
2014 |
! |
|
2015 |
||
2016 |
usedKeys |
|
2017 |
"get keys which were actually used. |
|
2018 |
(must call #rememberUsedKeys before)" |
|
2019 |
||
2020 |
^ usedKeys |
|
2021 |
||
2022 |
"Created: / 12-09-2018 / 18:24:26 / Claus Gittinger" |
|
2023 |
! ! |
|
2024 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
2025 |
!ResourcePack class methodsFor:'documentation'! |
251 | 2026 |
|
2027 |
version |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
2028 |
^ '$Header$' |
5357 | 2029 |
! |
2030 |
||
2031 |
version_CVS |
|
6887
b10262d21ed1
linked index chain in WeakArray
Claus Gittinger <cg@exept.de>
parents:
6799
diff
changeset
|
2032 |
^ '$Header$' |
251 | 2033 |
! ! |
3769 | 2034 |
|
6051
f01078ce8c2c
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
5951
diff
changeset
|
2035 |
|
0 | 2036 |
ResourcePack initialize! |