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