ResourcePack.st
changeset 2970 928387584c9c
parent 2608 a36fad717685
child 2971 8dd578866ddc
equal deleted inserted replaced
2969:c0c385edd320 2970:928387584c9c
   193 
   193 
   194 for:aClass
   194 for:aClass
   195     "get the full resource definitions for aClass (i.e. with super packs).
   195     "get the full resource definitions for aClass (i.e. with super packs).
   196      Also leave the resulting pack in the cache for faster access next time."
   196      Also leave the resulting pack in the cache for faster access next time."
   197 
   197 
   198     |nm pack superPack|
   198     |nm pack superPack pkg prj prjDir baseName|
   199 
   199 
   200     nm := aClass resourcePackName.
   200     nm := aClass resourcePackName.
   201     pack := self searchCacheFor:nm.
   201     pack := self searchCacheFor:nm.
   202     pack notNil ifTrue:[^ pack].
   202     pack notNil ifTrue:[^ pack].
   203 
   203 
   204     pack := self fromFile:(Smalltalk fileNameForClass:nm) , '.rs'.
   204     ((pkg := aClass package) startsWith:'stx:') ifFalse:[
       
   205         "/ there might be a package specific resource directory ...
       
   206         prj := Project projectWithId:pkg.
       
   207         prj notNil ifTrue:[
       
   208             prjDir := prj directory.
       
   209         ].
       
   210     ].
       
   211 
       
   212     baseName := (Smalltalk fileNameForClass:nm) , '.rs'.
       
   213 
       
   214     (prjDir notNil and:[(prjDir := prjDir asFilename) exists]) ifTrue:[
       
   215         pack := self 
       
   216                     fromFile:((prjDir construct:'resources') constructString:baseName)
       
   217                     directory:nil.
       
   218     ] ifFalse:[
       
   219         pack := self fromFile:baseName.
       
   220     ].
   205     aClass == Object ifFalse:[
   221     aClass == Object ifFalse:[
   206 	pack superPack:(self for:(aClass superclass)).
   222         pack superPack:(self for:(aClass superclass)).
   207     ].
   223     ].
   208     pack packsClassName:nm.
   224     pack packsClassName:nm.
   209     self addToCache:pack.
   225     self addToCache:pack.
   210     ^ pack
   226     ^ pack
   211 
   227 
   212     "
   228     "
   213      ResourcePack for:TextView
   229      ResourcePack for:TextView
   214      ResourcePack for:CodeView
   230      ResourcePack for:CodeView
   215      ResourcePack for:Workspace 
   231      ResourcePack for:Workspace 
       
   232      ResourcePack for:ErrorLogger 
   216      Workspace classResources
   233      Workspace classResources
   217     "
   234     "
   218 
   235 
   219     "Modified: / 29.1.1998 / 22:42:53 / cg"
   236     "Modified: / 29.1.1998 / 22:42:53 / cg"
   220 !
   237 !
   583 
   600 
   584     |inStream ok|
   601     |inStream ok|
   585 
   602 
   586     fileReadFailed := false.
   603     fileReadFailed := false.
   587     dirName = 'resources' ifTrue:[
   604     dirName = 'resources' ifTrue:[
   588 	inStream := Smalltalk resourceFileStreamFor:fileName
   605         inStream := Smalltalk resourceFileStreamFor:fileName
   589     ] ifFalse:[
   606     ] ifFalse:[
   590 	inStream := Smalltalk systemFileStreamFor:(dirName , '/' , fileName).
   607         dirName isNil ifTrue:[
       
   608             inStream := Smalltalk systemFileStreamFor:fileName.
       
   609         ] ifFalse:[
       
   610             inStream := Smalltalk systemFileStreamFor:(dirName , '/' , fileName).
       
   611         ]
   591     ].
   612     ].
   592     inStream isNil ifTrue:[
   613     inStream isNil ifTrue:[
   593 	"
   614         "
   594 	 an empty pack
   615          an empty pack
   595 	"
   616         "
   596 	^ self nonexistingFileRead
   617         ^ self nonexistingFileRead
   597     ].
   618     ].
   598     ok := self readFromResourceStream:inStream in:dirName.
   619     ok := self readFromResourceStream:inStream in:dirName.
   599     inStream close.
   620     inStream close.
   600 
   621 
   601     ok ifFalse:[
   622     ok ifFalse:[
   602 	fileReadFailed := true.
   623         fileReadFailed := true.
   603 
   624 
   604 	('ResourcePack [warning]: ''' , fileName , ''' contains error(s) - data may be incomplete.') errorPrintCR.
   625         ('ResourcePack [warning]: ''' , fileName , ''' contains error(s) - data may be incomplete.') errorPrintCR.
   605     ].
   626     ].
   606 
   627 
   607     "Modified: 10.1.1997 / 18:05:17 / cg"
   628     "Modified: 10.1.1997 / 18:05:17 / cg"
   608 !
   629 !
   609 
   630 
   707 ! !
   728 ! !
   708 
   729 
   709 !ResourcePack class methodsFor:'documentation'!
   730 !ResourcePack class methodsFor:'documentation'!
   710 
   731 
   711 version
   732 version
   712     ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.51 1999-04-28 20:39:58 cg Exp $'
   733     ^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.52 1999-10-13 16:21:11 cg Exp $'
   713 ! !
   734 ! !
   714 ResourcePack initialize!
   735 ResourcePack initialize!