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