ResourcePack.st
changeset 4619 f4fb56981bad
parent 4618 d07d2f6445b6
child 4623 81241ac5d815
equal deleted inserted replaced
4618:d07d2f6445b6 4619:f4fb56981bad
   199 
   199 
   200 for:aClass
   200 for:aClass
   201     "get the full resource definitions for aClass (i.e. with super packs).
   201     "get the full resource definitions for aClass (i.e. with super packs).
   202      Also leave the resulting pack in the cache for faster access next time."
   202      Also leave the resulting pack in the cache for faster access next time."
   203 
   203 
   204     ^ self for:aClass cached:true
   204     ^ self for:aClass cached:false
   205 
   205 
   206     "
   206     "
   207      ResourcePack for:TextView     
   207      ResourcePack for:TextView     
   208      ResourcePack for:CodeView
   208      ResourcePack for:CodeView
   209      ResourcePack for:Workspace  
   209      ResourcePack for:Workspace  
   210      ResourcePack for:View      
   210      ResourcePack for:View      
   211      ResourcePack for:ErrorLogger 
   211      ResourcePack for:ErrorLogger 
   212      ResourcePack for:NewLauncher 
   212      ResourcePack for:NewLauncher 
   213      Workspace classResources
   213      Workspace classResources
   214     "
   214     "
       
   215 
       
   216     "Modified: / 18-09-2006 / 19:02:57 / cg"
   215 !
   217 !
   216 
   218 
   217 for:aClass cached:cached
   219 for:aClass cached:cached
   218     "get the full resource definitions for aClass (i.e. with super packs).
   220     "get the full resource definitions for aClass (i.e. with super packs).
   219      Also leave the resulting pack in the cache for faster access next time."
   221      Also leave the resulting pack in the cache for faster access next time."
   240     and:[(rsrcDir construct:baseName) exists]]) ifTrue:[
   242     and:[(rsrcDir construct:baseName) exists]]) ifTrue:[
   241         pack := self fromFile:baseName directory:rsrcDir pathName.
   243         pack := self fromFile:baseName directory:rsrcDir pathName.
   242     ] ifFalse:[
   244     ] ifFalse:[
   243         pack := self fromFile:baseName.
   245         pack := self fromFile:baseName.
   244     ].
   246     ].
   245     aClass == Object ifFalse:[
   247     aClass superclass notNil ifTrue:[
   246         pack superPack:(self for:(aClass superclass)).
   248         pack superPack:(self for:(aClass superclass)).
   247     ].
   249     ].
   248     pack packsClassOrFileName:nm.
   250     pack packsClassOrFileName:nm.
   249     cached ifTrue:[
   251     cached ifTrue:[
   250         self addToCache:pack.
   252         self addToCache:pack.
   261      ResourcePack for:ErrorLogger 
   263      ResourcePack for:ErrorLogger 
   262      ResourcePack for:NewLauncher 
   264      ResourcePack for:NewLauncher 
   263      Workspace classResources
   265      Workspace classResources
   264     "
   266     "
   265 
   267 
   266     "Modified: / 18-09-2006 / 17:43:37 / cg"
   268     "Modified: / 18-09-2006 / 19:07:23 / cg"
   267 !
   269 !
   268 
   270 
   269 forPackage:package 
   271 forPackage:package 
   270     "get the full resource definitions given a package id (such as stx:libbasic').
   272     "get the full resource definitions given a package id (such as stx:libbasic').
   271      Also leave the resulting pack in the cache for faster access next time."
   273      Also leave the resulting pack in the cache for faster access next time."
   364          throw away oldest
   366          throw away oldest
   365         "
   367         "
   366         idx := Packs size.
   368         idx := Packs size.
   367         Packs replaceFrom:1 to:idx-1 with:Packs startingAt:2.
   369         Packs replaceFrom:1 to:idx-1 with:Packs startingAt:2.
   368     ].
   370     ].
   369     Packs at:idx put:aPack
   371     aPack at:'__language__' put:(Smalltalk language,'_',Smalltalk languageTerritory).
       
   372     Packs at:idx put:aPack.
       
   373 
       
   374     "Modified: / 18-09-2006 / 19:12:12 / cg"
   370 !
   375 !
   371 
   376 
   372 searchCacheFor:aClassOrFileName
   377 searchCacheFor:aClassOrFileName
   373     |sz "{ Class: SmallInteger }" |
   378     |sz "{ Class: SmallInteger }" lang|
   374 
   379 
   375     Packs isNil ifTrue:[
   380     Packs isNil ifTrue:[
   376         self initialize.
   381         self initialize.
   377         ^ nil
   382         ^ nil
   378     ].
   383     ].
   379 
   384 
       
   385     lang := (Smalltalk language,'_',Smalltalk languageTerritory).
       
   386 
   380     sz := Packs size.
   387     sz := Packs size.
   381     1 to:sz do:[:idx |
   388     1 to:sz do:[:idx |
   382         |aPack|
   389         |aPack|
   383 
   390 
   384         aPack := Packs at:idx.
   391         aPack := Packs at:idx.
   385         (aPack notNil and:[aPack ~~ 0]) ifTrue:[
   392         (aPack notNil and:[aPack ~~ 0]) ifTrue:[
   386             aClassOrFileName = aPack packsClassOrFileName ifTrue:[
   393             (aPack at:'__language__' ifAbsent:nil) = lang ifTrue:[
   387                 "
   394                 aClassOrFileName = aPack packsClassOrFileName ifTrue:[
   388                  bring to front for LRU
   395                     "
   389                 "
   396                      bring to front for LRU
   390                 idx ~~ 1 ifTrue:[
   397                     "
   391                     Packs replaceFrom:2 to:idx with:Packs startingAt:1.
   398                     idx ~~ 1 ifTrue:[
   392                     Packs at:1 put:aPack.
   399                         Packs replaceFrom:2 to:idx with:Packs startingAt:1.
   393                 ].
   400                         Packs at:1 put:aPack.
   394                 ^ aPack
   401                     ].
       
   402                     ^ aPack
       
   403                 ]
   395             ]
   404             ]
   396         ]
   405         ]
   397     ].
   406     ].
   398     ^ nil
   407     ^ nil
   399 
   408 
   400     "
   409     "
   401      ResourcePack searchCacheFor:'TextView' 
   410      ResourcePack searchCacheFor:'TextView' 
   402     "
   411     "
       
   412 
       
   413     "Modified: / 18-09-2006 / 19:13:13 / cg"
   403 ! !
   414 ! !
   404 
   415 
   405 !ResourcePack class methodsFor:'utilities'!
   416 !ResourcePack class methodsFor:'utilities'!
   406 
   417 
   407 extractEncodingFromLine:lineString
   418 extractEncodingFromLine:lineString
   576                 aResourcePack at:name put:value.
   587                 aResourcePack at:name put:value.
   577             ]
   588             ]
   578         ]
   589         ]
   579     ]
   590     ]
   580 
   591 
   581     "Modified: / 05-07-2006 / 17:25:07 / cg"
   592     "Modified: / 18-09-2006 / 20:33:49 / cg"
   582 ! !
   593 ! !
   583 
   594 
   584 !ResourcePack methodsFor:'accessing'!
   595 !ResourcePack methodsFor:'accessing'!
   585 
   596 
   586 array:anArray
   597 array:anArray
  1168                                                     self readFromFile:value directory:dirName
  1179                                                     self readFromFile:value directory:dirName
  1169                                                 ]
  1180                                                 ]
  1170                                             ]
  1181                                             ]
  1171                                         ] ifFalse:[
  1182                                         ] ifFalse:[
  1172                                             (lineString startsWith:'encoding') ifTrue:[
  1183                                             (lineString startsWith:'encoding') ifTrue:[
       
  1184 decoder notNil ifTrue:[self halt:'oops - encoding change in file'].
  1173                                                 encoding := self class extractEncodingFromLine:lineString.
  1185                                                 encoding := self class extractEncodingFromLine:lineString.
  1174                                                 decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil.
  1186                                                 decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil.
  1175                                             ]
  1187                                             ]
  1176                                         ]
  1188                                         ]
  1177                                     ]
  1189                                     ]
  1206         ]
  1218         ]
  1207     ].
  1219     ].
  1208     ^ ok
  1220     ^ ok
  1209 
  1221 
  1210     "Modified: / 31-08-1995 / 02:33:45 / claus"
  1222     "Modified: / 31-08-1995 / 02:33:45 / claus"
  1211     "Modified: / 18-09-2006 / 18:48:02 / cg"
  1223     "Modified: / 18-09-2006 / 20:35:37 / cg"
  1212 ! !
  1224 ! !
  1213 
  1225 
  1214 !ResourcePack methodsFor:'printing & storing'!
  1226 !ResourcePack methodsFor:'printing & storing'!
  1215 
  1227 
  1216 displayString
  1228 displayString
  1223 ! !
  1235 ! !
  1224 
  1236 
  1225 !ResourcePack class methodsFor:'documentation'!
  1237 !ResourcePack class methodsFor:'documentation'!
  1226 
  1238 
  1227 version
  1239 version
  1228     ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.114 2006-09-18 16:50:38 cg Exp $'
  1240     ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.115 2006-09-18 18:34:39 cg Exp $'
  1229 ! !
  1241 ! !
  1230 
  1242 
  1231 ResourcePack initialize!
  1243 ResourcePack initialize!