--- a/ResourcePack.st Mon Oct 15 10:53:02 2018 +0200
+++ b/ResourcePack.st Mon Oct 15 11:41:56 2018 +0200
@@ -228,6 +228,21 @@
!ResourcePack class methodsFor:'instance creation'!
+defaultResourcePack
+ |rsrcs cls superPack|
+
+ rsrcs := ResourcePack new.
+ (cls := Smalltalk classNamed:'stx_libtool') notNil ifTrue:[
+ superPack := cls classResources
+ ] ifFalse:[
+ (cls := Smalltalk classNamed:'stx_libview') notNil ifTrue:[
+ superPack := cls classResources
+ ].
+ ].
+ superPack notNil ifTrue:[ rsrcs addSuperPack:superPack ].
+ ^ rsrcs
+!
+
for:aClass
"get the full resource definitions for aClass (i.e. with super packs).
Also leave the resulting pack in the cache for faster access next time."
@@ -341,46 +356,50 @@
|fullName pack rsrcDir file|
- package isNil ifTrue:[^ nil].
+ package isNil ifTrue:[
+ '[ResourcePack] warning: nil package asking for resource file'.
+ ^ self defaultResourcePack
+ ].
+
fullName := (package copyReplaceAll:$: with:$/),'/resources/',resourceFileName.
cached ifTrue:[
pack := self searchCacheFor:fullName.
pack notNil ifTrue:[^ pack].
- (FailedToLoadPacks includes:fullName) ifTrue:[^ nil].
+ (FailedToLoadPacks includes:fullName) ifTrue:[
+ ^ self defaultResourcePack.
+ ].
].
"/ Smalltalk projectDirectoryForPackage:'stx:libview'
rsrcDir := Smalltalk projectDirectoryForPackage:package.
"/ '1) projectDirectoryForPackage -> ' print.
"/ rsrcDir printCR.
- rsrcDir isNil ifTrue:[
- file := Smalltalk getResourceFileName:resourceFileName forPackage:package.
- "/ '2) getResourceFileName -> ' print.
- "/ rsrcDir printCR.
- file isNil ifTrue:[
- FailedToLoadPacks add:fullName.
- ^ nil
- ].
- rsrcDir := file asFilename directory.
- ] ifFalse:[
- rsrcDir := rsrcDir asFilename construct:'resources'.
+ rsrcDir notNil ifTrue:[
+ rsrcDir := rsrcDir asFilename / 'resources'.
"/ '3) rsrcDir -> ' print.
"/ rsrcDir printCR.
- rsrcDir exists ifFalse:[
- FailedToLoadPacks add:fullName.
- ^ nil
+ rsrcDir exists ifTrue:[
+ pack := self fromFile:resourceFileName directory:rsrcDir cached:cached.
+ pack packsPackage:package.
+ ^ pack
].
+ ].
+
+ file := Smalltalk getResourceFileName:resourceFileName forPackage:package.
+ (file notNil and:[file exists]) ifTrue:[
+ rsrcDir := file asFilename directory.
+ pack := self fromFile:resourceFileName directory:rsrcDir cached:cached.
+ pack packsPackage:package.
+ ^ pack
].
-
- "/ '4) fromFile ' print. resourceFileName print.
- "/ ' in ' print. rsrcDir printCR.
-
- pack := self fromFile:resourceFileName directory:rsrcDir cached:cached.
- pack packsClassOrFileName:fullName.
- ^ pack
+
+ FailedToLoadPacks add:fullName.
+ ^ self defaultResourcePack
"
+ ResourcePack flushCachedResourcePacks.
+
ResourcePack
forPackage:'stx:libbasic'
resourceFileName:'resources.rs'
@@ -465,7 +484,7 @@
"Modified: / 18-09-2006 / 19:12:12 / cg"
!
-searchCacheFor:aClassOrFileName
+searchCacheFor:aPackageName
|sz "{ Class: SmallInteger }" lang|
Packs isNil ifTrue:[
@@ -482,7 +501,7 @@
aPack := Packs at:idx.
(aPack notNil and:[aPack class ~~ SmallInteger]) ifTrue:[
(aPack at:'__language__' ifAbsent:nil) = lang ifTrue:[
- aClassOrFileName = aPack packsClassOrFileName ifTrue:[
+ aPackageName = aPack packsPackage ifTrue:[
"
bring to front for LRU
"
@@ -498,7 +517,7 @@
^ nil
"
- ResourcePack searchCacheFor:'TextView'
+ ResourcePack searchCacheFor:'stx:libview'
"
"Modified: / 18-09-2006 / 19:13:13 / cg"
@@ -827,6 +846,8 @@
aKey isNil ifTrue:[ ^ defaultValue value ].
+ usedKeys notNil ifTrue:[usedKeys add:aKey].
+
val := self localAt:aKey.
val notNil ifTrue:[^ val].
@@ -1428,28 +1449,16 @@
^ self at:aKey ifAbsent:aKey
!
-packsClassName
+packsFileName
+ ^ packsFileName
+!
+
+packsPackage
^ packsClassName
!
-packsClassName:aString
- packsClassName := aString
-!
-
-packsClassOrFileName
- "old: should no longer be used to access the filename; see packsFileName"
-
- ^ packsClassName
-!
-
-packsClassOrFileName:aString
- "old: should no longer be used to access the filename; see packsFileName"
-
- packsClassName := aString
-!
-
-packsFileName
- ^ packsFileName
+packsPackage:aPackage
+ packsClassName := aPackage
!
projectPack
@@ -1458,33 +1467,6 @@
"Created: / 18-09-2006 / 17:38:07 / cg"
!
-projectPack:anotherResourcePack
- projectPack := anotherResourcePack
-
- "Created: / 29.1.1998 / 22:43:09 / cg"
-!
-
-superPack
- "sr: don't know why and where but did happen
- will end up in recursion loop.
- I added an assert to the setter"
- self == superPack ifTrue:[
- ^ nil
- ].
-
- ^ superPack
-
- "Created: / 18-09-2006 / 17:38:12 / cg"
- "Modified (comment): / 10-10-2018 / 14:14:44 / sr"
-!
-
-superPack:anotherResourcePack
- self addSuperPack:anotherResourcePack.
-
- "Created: / 29-01-1998 / 22:43:09 / cg"
- "Modified (comment): / 10-10-2018 / 14:14:39 / sr"
-!
-
superPacks
^ superPacks ? #()
! !
@@ -1679,7 +1661,7 @@
rest := lineString copyFrom:('superpack' size + 1).
value := Compiler evaluate:rest compile:false.
(value isKindOf:ResourcePack) ifTrue:[
- self superPack:value.
+ self addSuperPack:value.
]
] ifFalse:[
(lineString startsWith:'include') ifTrue:[