225 |
225 |
226 "Modified: / 28-09-2011 / 15:53:21 / cg" |
226 "Modified: / 28-09-2011 / 15:53:21 / cg" |
227 ! ! |
227 ! ! |
228 |
228 |
229 !ResourcePack class methodsFor:'instance creation'! |
229 !ResourcePack class methodsFor:'instance creation'! |
|
230 |
|
231 defaultResourcePack |
|
232 |rsrcs cls superPack| |
|
233 |
|
234 rsrcs := ResourcePack new. |
|
235 (cls := Smalltalk classNamed:'stx_libtool') notNil ifTrue:[ |
|
236 superPack := cls classResources |
|
237 ] ifFalse:[ |
|
238 (cls := Smalltalk classNamed:'stx_libview') notNil ifTrue:[ |
|
239 superPack := cls classResources |
|
240 ]. |
|
241 ]. |
|
242 superPack notNil ifTrue:[ rsrcs addSuperPack:superPack ]. |
|
243 ^ rsrcs |
|
244 ! |
230 |
245 |
231 for:aClass |
246 for:aClass |
232 "get the full resource definitions for aClass (i.e. with super packs). |
247 "get the full resource definitions for aClass (i.e. with super packs). |
233 Also leave the resulting pack in the cache for faster access next time." |
248 Also leave the resulting pack in the cache for faster access next time." |
234 |
249 |
339 Also optionally leave the resulting pack in the cache for faster access next time. |
354 Also optionally leave the resulting pack in the cache for faster access next time. |
340 Remember failed packs, to avoid retrying reading the file again and again" |
355 Remember failed packs, to avoid retrying reading the file again and again" |
341 |
356 |
342 |fullName pack rsrcDir file| |
357 |fullName pack rsrcDir file| |
343 |
358 |
344 package isNil ifTrue:[^ nil]. |
359 package isNil ifTrue:[ |
|
360 '[ResourcePack] warning: nil package asking for resource file'. |
|
361 ^ self defaultResourcePack |
|
362 ]. |
|
363 |
345 fullName := (package copyReplaceAll:$: with:$/),'/resources/',resourceFileName. |
364 fullName := (package copyReplaceAll:$: with:$/),'/resources/',resourceFileName. |
346 |
365 |
347 cached ifTrue:[ |
366 cached ifTrue:[ |
348 pack := self searchCacheFor:fullName. |
367 pack := self searchCacheFor:fullName. |
349 pack notNil ifTrue:[^ pack]. |
368 pack notNil ifTrue:[^ pack]. |
350 (FailedToLoadPacks includes:fullName) ifTrue:[^ nil]. |
369 (FailedToLoadPacks includes:fullName) ifTrue:[ |
|
370 ^ self defaultResourcePack. |
|
371 ]. |
351 ]. |
372 ]. |
352 |
373 |
353 "/ Smalltalk projectDirectoryForPackage:'stx:libview' |
374 "/ Smalltalk projectDirectoryForPackage:'stx:libview' |
354 rsrcDir := Smalltalk projectDirectoryForPackage:package. |
375 rsrcDir := Smalltalk projectDirectoryForPackage:package. |
355 "/ '1) projectDirectoryForPackage -> ' print. |
376 "/ '1) projectDirectoryForPackage -> ' print. |
356 "/ rsrcDir printCR. |
377 "/ rsrcDir printCR. |
357 rsrcDir isNil ifTrue:[ |
378 rsrcDir notNil ifTrue:[ |
358 file := Smalltalk getResourceFileName:resourceFileName forPackage:package. |
379 rsrcDir := rsrcDir asFilename / 'resources'. |
359 "/ '2) getResourceFileName -> ' print. |
|
360 "/ rsrcDir printCR. |
|
361 file isNil ifTrue:[ |
|
362 FailedToLoadPacks add:fullName. |
|
363 ^ nil |
|
364 ]. |
|
365 rsrcDir := file asFilename directory. |
|
366 ] ifFalse:[ |
|
367 rsrcDir := rsrcDir asFilename construct:'resources'. |
|
368 "/ '3) rsrcDir -> ' print. |
380 "/ '3) rsrcDir -> ' print. |
369 "/ rsrcDir printCR. |
381 "/ rsrcDir printCR. |
370 rsrcDir exists ifFalse:[ |
382 rsrcDir exists ifTrue:[ |
371 FailedToLoadPacks add:fullName. |
383 pack := self fromFile:resourceFileName directory:rsrcDir cached:cached. |
372 ^ nil |
384 pack packsPackage:package. |
373 ]. |
385 ^ pack |
374 ]. |
386 ]. |
375 |
387 ]. |
376 "/ '4) fromFile ' print. resourceFileName print. |
388 |
377 "/ ' in ' print. rsrcDir printCR. |
389 file := Smalltalk getResourceFileName:resourceFileName forPackage:package. |
378 |
390 (file notNil and:[file exists]) ifTrue:[ |
379 pack := self fromFile:resourceFileName directory:rsrcDir cached:cached. |
391 rsrcDir := file asFilename directory. |
380 pack packsClassOrFileName:fullName. |
392 pack := self fromFile:resourceFileName directory:rsrcDir cached:cached. |
381 ^ pack |
393 pack packsPackage:package. |
382 |
394 ^ pack |
383 " |
395 ]. |
|
396 |
|
397 FailedToLoadPacks add:fullName. |
|
398 ^ self defaultResourcePack |
|
399 |
|
400 " |
|
401 ResourcePack flushCachedResourcePacks. |
|
402 |
384 ResourcePack |
403 ResourcePack |
385 forPackage:'stx:libbasic' |
404 forPackage:'stx:libbasic' |
386 resourceFileName:'resources.rs' |
405 resourceFileName:'resources.rs' |
387 cached:false |
406 cached:false |
388 " |
407 " |
480 |aPack| |
499 |aPack| |
481 |
500 |
482 aPack := Packs at:idx. |
501 aPack := Packs at:idx. |
483 (aPack notNil and:[aPack class ~~ SmallInteger]) ifTrue:[ |
502 (aPack notNil and:[aPack class ~~ SmallInteger]) ifTrue:[ |
484 (aPack at:'__language__' ifAbsent:nil) = lang ifTrue:[ |
503 (aPack at:'__language__' ifAbsent:nil) = lang ifTrue:[ |
485 aClassOrFileName = aPack packsClassOrFileName ifTrue:[ |
504 aPackageName = aPack packsPackage ifTrue:[ |
486 " |
505 " |
487 bring to front for LRU |
506 bring to front for LRU |
488 " |
507 " |
489 idx ~~ 1 ifTrue:[ |
508 idx ~~ 1 ifTrue:[ |
490 Packs replaceFrom:2 to:idx with:Packs startingAt:1. |
509 Packs replaceFrom:2 to:idx with:Packs startingAt:1. |
824 "translate a string; search here, in my projects pack and in my superpack(s)" |
843 "translate a string; search here, in my projects pack and in my superpack(s)" |
825 |
844 |
826 |val pack projectPack alreadySearched toSearch more| |
845 |val pack projectPack alreadySearched toSearch more| |
827 |
846 |
828 aKey isNil ifTrue:[ ^ defaultValue value ]. |
847 aKey isNil ifTrue:[ ^ defaultValue value ]. |
|
848 |
|
849 usedKeys notNil ifTrue:[usedKeys add:aKey]. |
829 |
850 |
830 val := self localAt:aKey. |
851 val := self localAt:aKey. |
831 val notNil ifTrue:[^ val]. |
852 val notNil ifTrue:[^ val]. |
832 |
853 |
833 cache isNil ifTrue:[ cache := CacheDictionary new:1000 ]. |
854 cache isNil ifTrue:[ cache := CacheDictionary new:1000 ]. |
1426 "translate a string" |
1447 "translate a string" |
1427 |
1448 |
1428 ^ self at:aKey ifAbsent:aKey |
1449 ^ self at:aKey ifAbsent:aKey |
1429 ! |
1450 ! |
1430 |
1451 |
1431 packsClassName |
|
1432 ^ packsClassName |
|
1433 ! |
|
1434 |
|
1435 packsClassName:aString |
|
1436 packsClassName := aString |
|
1437 ! |
|
1438 |
|
1439 packsClassOrFileName |
|
1440 "old: should no longer be used to access the filename; see packsFileName" |
|
1441 |
|
1442 ^ packsClassName |
|
1443 ! |
|
1444 |
|
1445 packsClassOrFileName:aString |
|
1446 "old: should no longer be used to access the filename; see packsFileName" |
|
1447 |
|
1448 packsClassName := aString |
|
1449 ! |
|
1450 |
|
1451 packsFileName |
1452 packsFileName |
1452 ^ packsFileName |
1453 ^ packsFileName |
1453 ! |
1454 ! |
1454 |
1455 |
|
1456 packsPackage |
|
1457 ^ packsClassName |
|
1458 ! |
|
1459 |
|
1460 packsPackage:aPackage |
|
1461 packsClassName := aPackage |
|
1462 ! |
|
1463 |
1455 projectPack |
1464 projectPack |
1456 ^ projectPack |
1465 ^ projectPack |
1457 |
1466 |
1458 "Created: / 18-09-2006 / 17:38:07 / cg" |
1467 "Created: / 18-09-2006 / 17:38:07 / cg" |
1459 ! |
|
1460 |
|
1461 projectPack:anotherResourcePack |
|
1462 projectPack := anotherResourcePack |
|
1463 |
|
1464 "Created: / 29.1.1998 / 22:43:09 / cg" |
|
1465 ! |
|
1466 |
|
1467 superPack |
|
1468 "sr: don't know why and where but did happen |
|
1469 will end up in recursion loop. |
|
1470 I added an assert to the setter" |
|
1471 self == superPack ifTrue:[ |
|
1472 ^ nil |
|
1473 ]. |
|
1474 |
|
1475 ^ superPack |
|
1476 |
|
1477 "Created: / 18-09-2006 / 17:38:12 / cg" |
|
1478 "Modified (comment): / 10-10-2018 / 14:14:44 / sr" |
|
1479 ! |
|
1480 |
|
1481 superPack:anotherResourcePack |
|
1482 self addSuperPack:anotherResourcePack. |
|
1483 |
|
1484 "Created: / 29-01-1998 / 22:43:09 / cg" |
|
1485 "Modified (comment): / 10-10-2018 / 14:14:39 / sr" |
|
1486 ! |
1468 ! |
1487 |
1469 |
1488 superPacks |
1470 superPacks |
1489 ^ superPacks ? #() |
1471 ^ superPacks ? #() |
1490 ! ! |
1472 ! ! |
1677 skipping ifFalse:[ |
1659 skipping ifFalse:[ |
1678 (lineString startsWith:'superpack') ifTrue:[ |
1660 (lineString startsWith:'superpack') ifTrue:[ |
1679 rest := lineString copyFrom:('superpack' size + 1). |
1661 rest := lineString copyFrom:('superpack' size + 1). |
1680 value := Compiler evaluate:rest compile:false. |
1662 value := Compiler evaluate:rest compile:false. |
1681 (value isKindOf:ResourcePack) ifTrue:[ |
1663 (value isKindOf:ResourcePack) ifTrue:[ |
1682 self superPack:value. |
1664 self addSuperPack:value. |
1683 ] |
1665 ] |
1684 ] ifFalse:[ |
1666 ] ifFalse:[ |
1685 (lineString startsWith:'include') ifTrue:[ |
1667 (lineString startsWith:'include') ifTrue:[ |
1686 (lineString startsWith:'includeResourcesFor') ifTrue:[ |
1668 (lineString startsWith:'includeResourcesFor') ifTrue:[ |
1687 "/ include those resources ... |
1669 "/ include those resources ... |