DirectoryView.st
author Patrik Svestka <patrik.svestka@gmail.com>
Wed, 14 Nov 2018 12:07:51 +0100
branchjv
changeset 3630 5e718e0a754e
parent 3366 70c6139984a6
child 3491 c1333ee85336
permissions -rw-r--r--
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present

- All source *.st files are now Unicode UTF8 without BOM
Files are in two groups (fileOut works this way in Smalltalk/X):
- containing a unicode character have "{ Encoding: utf8 }" at the header
- ASCII only are without the header
     1 "
     2  COPYRIGHT (c) 1997 by eXept Software AG
     3               All Rights Reserved
     4 
     5  This software is furnished under a license and may be used
     6  only in accordance with the terms of that license and with the
     7  inclusion of the above copyright notice. This software may not
     8  be provided or otherwise made available to, or used by, any
     9  other person. No title to or ownership of the software is
    10  hereby transferred.
    11 "
    12 "{ Package: 'stx:libtool2' }"
    13 
    14 "{ NameSpace: Smalltalk }"
    15 
    16 ApplicationModel subclass:#DirectoryView
    17 	instanceVariableNames:'directory selectedFileFilter readTask monitoring
    18 		monitoringTimeBlock fileDoubleClickAction fileSelectAction
    19 		fileFilterSelectAction fileAttributes'
    20 	classVariableNames:''
    21 	poolDictionaries:''
    22 	category:'Interface-Dialogs'
    23 !
    24 
    25 Object subclass:#FileRow
    26 	instanceVariableNames:'fileName size modified iconKey imageFromFile group owner
    27 		permissions baseName'
    28 	classVariableNames:'MaxImageFileSize'
    29 	poolDictionaries:''
    30 	privateIn:DirectoryView
    31 !
    32 
    33 !DirectoryView class methodsFor:'documentation'!
    34 
    35 copyright
    36 "
    37  COPYRIGHT (c) 1997 by eXept Software AG
    38               All Rights Reserved
    39 
    40  This software is furnished under a license and may be used
    41  only in accordance with the terms of that license and with the
    42  inclusion of the above copyright notice. This software may not
    43  be provided or otherwise made available to, or used by, any
    44  other person. No title to or ownership of the software is
    45  hereby transferred.
    46 "
    47 
    48 !
    49 
    50 documentation
    51 "
    52     this is somewhat outdated. However, it is still used by the image editor and
    53     some other resource editors.
    54     It has the advantage of showing the file-contents...
    55     ...but the disadvantage of having an ugly layout and user interface.
    56 
    57     [author:]
    58         Thomas Zwick
    59 "
    60 ! !
    61 
    62 !DirectoryView class methodsFor:'instance creation'!
    63 
    64 openOnDirectory: aDirectoryString
    65     "open a DirectoryView for a aDirectoryString"
    66 
    67     ^ (self new directory: aDirectoryString) open
    68 
    69     "
    70      self openOnDirectory: '/etc'
    71     "
    72 
    73     "Modified: / 28.1.1998 / 15:44:53 / stefan"
    74 ! !
    75 
    76 !DirectoryView class methodsFor:'interface specs'!
    77 
    78 windowSpec
    79     "This resource specification was automatically generated
    80      by the UIPainter of ST/X."
    81 
    82     "Do not manually edit this!! If it is corrupted,
    83      the UIPainter may not be able to read the specification."
    84 
    85     "
    86      UIPainter new openOnClass:DirectoryView andSelector:#windowSpec
    87      DirectoryView new openInterface:#windowSpec
    88      DirectoryView open
    89     "
    90 
    91     <resource: #canvas>
    92 
    93     ^ 
    94      #(#FullSpec
    95         #name: #windowSpec
    96         #window: 
    97        #(#WindowSpec
    98           #label: 'Directory View'
    99           #name: 'Directory View'
   100           #min: #(#Point 10 10)
   101           #max: #(#Point 1152 900)
   102           #bounds: #(#Rectangle 13 23 413 323)
   103         )
   104         #component: 
   105        #(#SpecCollection
   106           #collection: #(
   107            #(#DataSetSpec
   108               #name: 'filesDataSetView'
   109               #layout: #(#LayoutFrame 0 0.0 24 0.0 -2 1.0 0 1.0)
   110               #model: #selectionOfFile
   111               #menu: #fileListMenu
   112               #hasHorizontalScrollBar: true
   113               #hasVerticalScrollBar: true
   114               #miniScrollerHorizontal: true
   115               #dataList: #listOfFiles
   116               #useIndex: false
   117               #has3Dsepartors: false
   118               #doubleClickSelector: #fileDoubleClicked
   119               #columnHolder: #fileAttributeColumns
   120               #valueChangeSelector: #fileSelected
   121               #verticalSpacing: 1
   122             )
   123            #(#ComboBoxSpec
   124               #name: 'formatComboBox'
   125               #layout: #(#LayoutFrame 63 0.0 0 0 0 1.0 22 0)
   126               #model: #selectionOfFileFilter
   127               #immediateAccept: false
   128               #acceptOnTab: false
   129               #acceptOnPointerLeave: false
   130               #comboList: #listOfFileFilters
   131             )
   132            #(#LabelSpec
   133               #label: 'Filter: '
   134               #name: 'filterLabel'
   135               #layout: #(#LayoutFrame 0 0 0 0 62 0 22 0)
   136               #adjust: #right
   137             )
   138            )
   139          
   140         )
   141       )
   142 
   143     "Modified: / 11.2.2000 / 00:11:43 / cg"
   144 ! !
   145 
   146 !DirectoryView class methodsFor:'list specs'!
   147 
   148 tableColumnsForFileAttributes
   149     "This resource specification was automatically generated
   150      by the DataSetBuilder of ST/X."
   151 
   152     "Do not manually edit this!! If it is corrupted,
   153      the DataSetBuilder may not be able to read the specification."
   154 
   155     "
   156      DataSetBuilder new openOnClass:DirectoryView andSelector:#tableColumnsForFileAttributes
   157     "
   158 
   159     <resource: #tableColumns>
   160 
   161 
   162     ^ #(
   163         #(#DataSetColumnSpec
   164            #label: ''
   165            #width: 30
   166            #height: 22
   167            #printSelector: #iconOn:
   168            #canSelect: false
   169        )
   170         #(#DataSetColumnSpec
   171            #label: 'File name'
   172            #labelAlignment: #left
   173            #minWidth: 150
   174            #model: #baseName
   175            #canSelect: false
   176        )
   177         #(#DataSetColumnSpec
   178            #label: 'Size'
   179            #labelAlignment: #left
   180            #width: 70
   181            #model: #size
   182            #canSelect: false
   183        )
   184         #(#DataSetColumnSpec
   185            #label: 'Modified'
   186            #labelAlignment: #left
   187            #model: #modified
   188            #canSelect: false
   189        )
   190         #(#DataSetColumnSpec
   191            #label: 'Permissions'
   192            #labelAlignment: #left
   193            #width: 85
   194            #model: #permissions
   195            #canSelect: false
   196        )
   197         #(#DataSetColumnSpec
   198            #label: 'Owner'
   199            #labelAlignment: #left
   200            #width: 50
   201            #model: #owner
   202            #canSelect: false
   203        )
   204         #(#DataSetColumnSpec
   205            #label: 'Group'
   206            #labelAlignment: #left
   207            #width: 50
   208            #model: #group
   209            #canSelect: false
   210        )
   211      )
   212 ! !
   213 
   214 !DirectoryView class methodsFor:'menu specs'!
   215 
   216 fileListMenu
   217     "This resource specification was automatically generated
   218      by the MenuEditor of ST/X."
   219 
   220     "Do not manually edit this!! If it is corrupted,
   221      the MenuEditor may not be able to read the specification."
   222 
   223     "
   224      MenuEditor new openOnClass:DirectoryView andSelector:#fileListMenu
   225      (Menu new fromLiteralArrayEncoding:(DirectoryView fileListMenu)) startUp
   226     "
   227 
   228     <resource: #menu>
   229 
   230     ^ 
   231      #(#Menu
   232         #(
   233          #(#MenuItem
   234             #label: 'Update'
   235             #translateLabel: true
   236             #value: #updateFileList
   237           )
   238          )
   239         nil
   240         nil
   241       )
   242 
   243     "Created: / 11.2.2000 / 00:11:39 / cg"
   244 ! !
   245 
   246 !DirectoryView methodsFor:'accessing'!
   247 
   248 directory: aDirectory
   249 
   250     directory := aDirectory asFilename asAbsoluteFilename name
   251 !
   252 
   253 fileAttributes: anArray
   254 
   255     fileAttributes := anArray
   256 !
   257 
   258 fileDoubleClickAction: anActionBlock
   259 
   260     fileDoubleClickAction := anActionBlock
   261 !
   262 
   263 fileFilterSelectAction: anActionBlock
   264 
   265     fileFilterSelectAction := anActionBlock
   266 !
   267 
   268 fileSelectAction: anActionBlock
   269 
   270     fileSelectAction := anActionBlock
   271 !
   272 
   273 listOfFileFilters: aCollection
   274 
   275     self listOfFileFilters contents: aCollection.
   276     self selectionOfFileFilter value: (self listOfFileFilters at: 1 ifAbsent: [nil]).
   277 !
   278 
   279 monitoring: aBoolean
   280 
   281     aBoolean
   282     ifTrue:
   283     [
   284         monitoringTimeBlock := [self readDirectory].
   285         self readDirectory.
   286     ]
   287     ifFalse:
   288     [
   289         monitoring ifTrue:
   290         [
   291             Processor removeTimedBlock:monitoringTimeBlock.
   292             monitoringTimeBlock := nil
   293         ]
   294     ].
   295 
   296     monitoring := aBoolean.
   297 
   298 ! !
   299 
   300 !DirectoryView methodsFor:'aspects'!
   301 
   302 fileAttributeColumns
   303 
   304     |holder|
   305     (holder := builder bindingAt:#fileAttributeColumns) isNil ifTrue:[
   306         |fileAttributeColumns|
   307         builder aspectAt:#fileAttributeColumns put:(holder := List new).
   308         fileAttributeColumns := self class tableColumnsForFileAttributes collect: [:i| i decodeAsLiteralArray].
   309         holder add: fileAttributeColumns first.
   310         fileAttributeColumns do:
   311         [:col|
   312             (fileAttributes includes: col label) ifTrue: [holder add: col]
   313         ].
   314         holder do: [:col| col label: ' ', col label]
   315     ].
   316     ^ holder
   317 !
   318 
   319 listOfFileFilters
   320 
   321     |holder|          
   322     (holder := builder bindingAt:#listOfFileFilters) isNil ifTrue:[
   323         builder aspectAt:#listOfFileFilters put:(holder :=  List with: '*').
   324     ].
   325     ^ holder
   326 !
   327 
   328 listOfFiles
   329 
   330     |holder|
   331     (holder := builder bindingAt:#listOfFiles) isNil ifTrue:[
   332         builder aspectAt:#listOfFiles put:(holder :=  List new).
   333     ].
   334     ^ holder
   335 !
   336 
   337 selectionOfFile
   338 
   339     |holder|
   340     (holder := builder bindingAt:#selectionOfFile) isNil ifTrue:[
   341         builder aspectAt:#selectionOfFile put:(holder :=  ValueHolder new).
   342     ].
   343     ^ holder
   344 
   345 !
   346 
   347 selectionOfFileFilter
   348 
   349     |holder|
   350     (holder := builder bindingAt:#selectionOfFileFilter) isNil ifTrue:[
   351         builder aspectAt:#selectionOfFileFilter put:
   352         (holder := AspectAdaptor new subject:self; forAspect:#selectedFileFilter).
   353         selectedFileFilter := '*'.
   354     ].
   355     ^ holder
   356 ! !
   357 
   358 !DirectoryView methodsFor:'callbacks'!
   359 
   360 fileDoubleClicked
   361       
   362     (fileDoubleClickAction notNil and: [self selectionOfFile value notNil]) 
   363     ifTrue: 
   364     [
   365         fileDoubleClickAction numArgs = 0
   366         ifTrue:
   367         [
   368             fileDoubleClickAction value
   369         ].
   370         fileDoubleClickAction numArgs = 1
   371         ifTrue:
   372         [                
   373             fileDoubleClickAction value: (directory asFilename construct: self selectionOfFile value baseName) name
   374         ]
   375     ]
   376 !
   377 
   378 fileSelected
   379       
   380     (fileSelectAction notNil and: [self selectionOfFile value notNil]) 
   381     ifTrue: 
   382     [
   383         fileSelectAction numArgs = 0
   384         ifTrue:
   385         [
   386             fileSelectAction value
   387         ].
   388         fileSelectAction numArgs = 1
   389         ifTrue:
   390         [
   391             fileSelectAction value: (directory asFilename construct: self selectionOfFile value baseName) name
   392         ]
   393     ]
   394 ! !
   395 
   396 !DirectoryView methodsFor:'initialization'!
   397 
   398 initialize
   399 
   400     super initialize.
   401     self createBuilder.
   402 
   403     directory :=  (directory ? '.') asFilename asAbsoluteFilename directoryName.
   404     monitoring := false.
   405     fileAttributes := #('File name' 'Size' 'Modified').
   406     self selectionOfFileFilter value: (self listOfFileFilters at: 1 ifAbsent: [nil]).
   407 
   408     "Modified: / 20.6.1998 / 14:46:10 / cg"
   409 ! !
   410 
   411 !DirectoryView methodsFor:'initialize-release'!
   412 
   413 release
   414 
   415     monitoring ifTrue:
   416     [
   417         Processor removeTimedBlock:monitoringTimeBlock.
   418         monitoringTimeBlock := nil
   419     ].
   420 
   421     super release
   422 
   423 ! !
   424 
   425 !DirectoryView methodsFor:'menu actions'!
   426 
   427 updateFileList
   428     DirectoryContents flushCache.
   429     self readDirectory
   430 
   431     "Created: / 11.2.2000 / 00:12:46 / cg"
   432     "Modified: / 11.2.2000 / 00:14:32 / cg"
   433 ! !
   434 
   435 !DirectoryView methodsFor:'private'!
   436 
   437 readDirectory
   438     |allDirectories allFiles foundFiles filterList dir newContents|    
   439 
   440     allFiles := OrderedCollection new.
   441     allDirectories := OrderedCollection new.
   442     foundFiles := OrderedCollection new.
   443     "/ filterList := self listOfFileFilters value.
   444     filterList := self selectedFileFilter asCollectionOfSubstringsSeparatedBy:$;.
   445     filterList := filterList collect:[:pattern | pattern withoutSeparators].
   446 
   447     self withCursor:Cursor read do:[ 
   448         (dir := DirectoryContents directoryNamed: directory) notNil ifTrue:[
   449 "/            dir filesAndBasenamesDo:[:file :name|      
   450 "/                filterList do:[:filter|
   451 "/                    ((filter match:name) and:[(foundFiles includes: name) not])
   452 "/                    ifTrue:[
   453 "/                        foundFiles add: name
   454 "/                    ].
   455 "/                ].
   456 "/            ].
   457             dir filesAndBasenamesDo:[:file :name|      
   458                 allFiles add: name
   459             ].
   460             dir directoriesAndBasenamesDo:[:file :name|      
   461                 allDirectories add: name
   462             ].
   463 
   464             Filename isCaseSensitive ifFalse:[
   465                 filterList do:[:filter|
   466                     |lcFilter|
   467 
   468                     lcFilter := filter asLowercase.
   469                     foundFiles
   470                         addAll:(allFiles 
   471                                     select:[:name | lcFilter match:name asLowercase]
   472                                 ).
   473                 ]
   474             ] ifTrue:[
   475                 filterList do:[:filter|
   476                     foundFiles
   477                         addAll:(allFiles 
   478                                     select:[:name | filter match:name]
   479                                 ).
   480                 ]
   481             ].
   482 
   483             foundFiles sort.
   484             allDirectories sort.
   485 
   486             dir := directory asFilename.
   487 
   488             newContents := OrderedCollection new.
   489             newContents addAll:(allDirectories collect:[:name| FileRow new fileName:(dir construct:name)]).
   490             newContents addAll:(foundFiles collect:[:name| FileRow new fileName:(dir construct:name)]).
   491 
   492             self listOfFiles contents:newContents
   493         ]
   494     ]
   495 
   496     "Modified: / 23.9.1998 / 17:00:42 / cg"
   497 !
   498 
   499 readMonitoringDirectory
   500     "this is a very ugly piece of code - 
   501      left in as a bad example of how to make ST look slow...
   502      DO NOT USE IT, but read to learn"
   503      
   504     |readBlock|
   505 
   506     readTask notNil ifTrue: [readTask terminate].
   507     readBlock :=
   508         [
   509             |dir currentFilenames oldListOfFiles listOfFiles|
   510 
   511             dir := directory asFilename.
   512             currentFilenames := OrderedCollection new.
   513             (dir isReadable and:[dir isExecutable]) ifTrue: [
   514                 self listOfFileFilters value do:
   515                 [:filter|
   516                     (dir filesMatchingWithoutDotDirs: filter) do: [:aFileName|
   517                         |file|
   518                         (file := dir construct: aFileName) isDirectory ifFalse: [
   519                             currentFilenames add: file
   520                         ]
   521                     ].
   522                 ].
   523             ].
   524             listOfFiles := self listOfFiles.
   525             
   526             oldListOfFiles := listOfFiles copy.
   527             (currentFilenames asSortedCollection: [:f1 :f2| f1 baseName < f2 baseName]) asSet 
   528                 do: [:fileName| 
   529                     (oldListOfFiles contains:[:fileRow | fileRow fileName = fileName ])
   530                     ifFalse: [
   531                         |nearestFileRow newRow r|
   532                         
   533                         newRow := FileRow new fileName: fileName asFilename.
   534                         "/ cg: how stupid is that?
   535                         nearestFileRow := listOfFiles indexOf: (listOfFiles detect: [:fileRow| fileRow baseName > fileName baseName] ifNone: nil).
   536                         "/ nearestFileRow := listOfFiles findFirst:[:fileRow | fileRow baseName > fileName baseName].
   537                         nearestFileRow = 0
   538                             ifTrue: [listOfFiles add: newRow]
   539                             ifFalse: [listOfFiles add: newRow beforeIndex: nearestFileRow].
   540                         monitoring ifTrue: [self selectionOfFile value: r].
   541                     ]
   542                 ].
   543                 
   544             listOfFiles 
   545                 reverseDo: [:fileRow|
   546                     (currentFilenames includes: fileRow fileName)
   547                     ifFalse: [listOfFiles remove: fileRow]
   548                 ]
   549         ].
   550 
   551     monitoring ifTrue: [
   552         readTask := readBlock forkAt: Processor userBackgroundPriority.
   553         Processor addTimedBlock: monitoringTimeBlock afterSeconds: 1
   554     ] ifFalse: [
   555         Cursor wait showWhile: [readBlock value]
   556     ]
   557 
   558     "Modified: / 19-11-2016 / 20:34:14 / cg"
   559 ! !
   560 
   561 !DirectoryView methodsFor:'selection'!
   562 
   563 selectedFileFilter
   564 
   565     ^selectedFileFilter
   566 
   567 !
   568 
   569 selectedFileFilter:aString
   570     "change the file filter"
   571 
   572     |listOfFileFilters nArgs|
   573 
   574     aString = selectedFileFilter ifTrue:[^ self].
   575 
   576     listOfFileFilters := self listOfFileFilters.
   577 
   578     "/ what is this for ?
   579     aString size == 0 ifTrue: [
   580         listOfFileFilters remove: selectedFileFilter ifAbsent: nil
   581     ].
   582     selectedFileFilter := aString.
   583 
   584     ((listOfFileFilters includes: selectedFileFilter) not
   585     and:[selectedFileFilter notEmpty])
   586     ifTrue: [
   587         listOfFileFilters addFirst: selectedFileFilter
   588     ].
   589     ((listOfFileFilters includes: selectedFileFilter)
   590     and:[fileFilterSelectAction notNil]) 
   591     ifTrue: [
   592         (nArgs := fileFilterSelectAction numArgs) == 0
   593         ifTrue: [
   594             fileFilterSelectAction value
   595         ] ifFalse:[
   596             nArgs == 1 ifTrue:[
   597                 fileFilterSelectAction value: selectedFileFilter
   598             ] ifFalse:[
   599                 self error:'bad numArgs of fileFilter action block'
   600             ]
   601         ]
   602     ].       
   603     self readDirectory.
   604 
   605     "Modified: / 23.9.1998 / 16:53:05 / cg"
   606 ! !
   607 
   608 !DirectoryView methodsFor:'startup & release'!
   609 
   610 closeRequest
   611 
   612     self release.
   613 
   614     super closeRequest
   615 
   616 ! !
   617 
   618 !DirectoryView::FileRow class methodsFor:'resources'!
   619 
   620 HFileIcon
   621 
   622     ^self hFileIcon
   623 !
   624 
   625 MakefileIcon
   626     "This resource specification was automatically generated
   627      by the ImageEditor of ST/X."
   628 
   629     "Do not manually edit this!! If it is corrupted,
   630      the ImageEditor may not be able to read the specification."
   631 
   632     "
   633      self MakefileIcon inspect
   634      ImageEditor openOnClass:self andSelector:#MakefileIcon
   635      Icon flushCachedIcons
   636     "
   637 
   638     <resource: #image>
   639 
   640     ^Icon
   641         constantNamed:'DirectoryView::FileRow MakefileIcon'
   642         ifAbsentPut:[(Depth1Image width:20 height:19) bits:(ByteArray fromPackedString:'???9 @_0 @W2 @S0 @Q0 @_0 @O8 @@0 @@0 @@0)IV0/U$0)]&0)UT;)UV4 @@0 @@0???0???0')
   643             colorMapFromArray:#[255 255 255 0 0 0]
   644             mask:((ImageMask width:20 height:19) bits:(ByteArray fromPackedString:'??0@??8@??<@??>@???@??? ???0???0???0???0???0???0???0???0???0???0???0???0_??0'); yourself); yourself]
   645 !
   646 
   647 binaryFileIcon
   648     "This resource specification was automatically generated
   649      by the ImageEditor of ST/X."
   650 
   651     "Do not manually edit this!! If it is corrupted,
   652      the ImageEditor may not be able to read the specification."
   653 
   654     "
   655      self binaryFileIcon inspect
   656      ImageEditor openOnClass:self andSelector:#binaryFileIcon
   657      Icon flushCachedIcons
   658     "
   659 
   660     <resource: #image>
   661 
   662     ^Icon
   663         constantNamed:'DirectoryView::FileRow binaryFileIcon'
   664         ifAbsentPut:[(Depth1Image width:20 height:19) bits:(ByteArray fromPackedString:'???3 @_7 @W4#&S0&6Q0&6_3&6O5&6@0#&@9 @@0&\@2&6@0&6@0&6@1&6@8&\@0 @@0???0???1')
   665             colorMapFromArray:#[255 255 255 0 0 0]
   666             mask:((ImageMask width:20 height:19) bits:(ByteArray fromPackedString:'??0@??8@??<@??>@???@??? ???0???0???0???0???0???0???0???0???0???0???0???0_??0'); yourself); yourself]
   667 !
   668 
   669 cFileIcon
   670     "This resource specification was automatically generated
   671      by the ImageEditor of ST/X."
   672 
   673     "Do not manually edit this!! If it is corrupted,
   674      the ImageEditor may not be able to read the specification."
   675 
   676     "
   677      self cFileIcon inspect
   678      ImageEditor openOnClass:self andSelector:#cFileIcon
   679      Icon flushCachedIcons
   680     "
   681 
   682     <resource: #image>
   683 
   684     ^Icon
   685         constantNamed:'DirectoryView::FileRow cFileIcon'
   686         ifAbsentPut:[(Depth1Image width:20 height:19) bits:(ByteArray fromPackedString:'???9 @_0 @W2 @S0 @Q0 @_0 @O8 @@0 @@0 \@0 "@0  @0  @0&"@;&\@4 @@0 @@0???0???0')
   687             colorMapFromArray:#[255 255 255 0 0 0]
   688             mask:((ImageMask width:20 height:19) bits:(ByteArray fromPackedString:'??0@??8@??<@??>@???@??? ???0???0???0???0???0???0???0???0???0???0???0???0_??0'); yourself); yourself]
   689 !
   690 
   691 exeFileIcon
   692     "This resource specification was automatically generated
   693      by the ImageEditor of ST/X."
   694 
   695     "Do not manually edit this!! If it is corrupted,
   696      the ImageEditor may not be able to read the specification."
   697 
   698     "
   699      self exeFileIcon inspect
   700      ImageEditor openOnClass:self andSelector:#exeFileIcon
   701      Icon flushCachedIcons
   702     "
   703 
   704     <resource: #image>
   705 
   706     ^Icon
   707         constantNamed:'DirectoryView::FileRow exeFileIcon'
   708         ifAbsentPut:[(Depth2Image width:20 height:19) bits:(ByteArray fromPackedString:'UUUUUUU@@@@UUT@@@AEUP@@@DEU@@@@PET@@@AUUQUUUP@UF**)@ATUUUT@EQ???P@UG??=@AT_??4@EQ???P@UG??=@AT_??4@EQUUUP@U@@@@@AUUUUUUU
   709 UUUUUUTb')
   710             colorMapFromArray:#[255 255 255 0 0 0 0 127 127 170 170 170]
   711             mask:((ImageMask width:20 height:19) bits:(ByteArray fromPackedString:'??0@??8@??<@??>@???@??? ???0???0???0???0???0???0???0???0???0???0???0???0_??0'); yourself); yourself]
   712 !
   713 
   714 fileIcon
   715     "Generated by the Image Editor"
   716     "
   717     ImageEditor openOnClass:self andSelector:#fileIcon
   718     "
   719 
   720     <resource: #image>
   721 
   722     ^Icon
   723         constantNamed:#'DirectoryView::FileRow fileIcon'
   724         ifAbsentPut:[(Depth1Image new) width: 20; height: 19; photometric:(#palette); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'???9 @_0 @W2 @S0 @Q0 @_0 @O8 @@0 @@0 @@0 @@0 @@0 @@0 @@; @@4 @@0 @@0???0???0') ; colorMap:((OrderedCollection new add:(Color white); add:(Color black); yourself)); mask:((ImageMask new) width: 20; height: 19; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'??0@??8@??<@??>@???@??? ???0???0???0???0???0???0???0???0???0???0???0???0_??0') ; yourself); yourself]
   725 !
   726 
   727 hFileIcon
   728     "Generated by the Image Editor"
   729     "
   730     ImageEditor openOnClass:self andSelector:#hFileIcon
   731     "
   732 
   733     <resource: #image>
   734 
   735     ^Icon
   736         constantNamed:#'DirectoryView::FileRow hFileIcon'
   737         ifAbsentPut:[(Depth1Image new) width: 20; height: 19; photometric:(#palette); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'???9 @_0 @W2 @S0 @Q0 @_0 @O8  @0  @0 ,@0 2@0 "@0 "@0&"@;&"@4 @@0 @@0???0???0'); colorMap:((OrderedCollection new add:(Color white); add:(Color black); yourself)); mask:((ImageMask new) width: 20; height: 19; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'??0@??8@??<@??>@???@??? ???0???0???0???0???0???0???0???0???0???0???0???0_??0'); yourself); yourself]
   738 !
   739 
   740 htmlFileIcon
   741     "This resource specification was automatically generated
   742      by the ImageEditor of ST/X."
   743 
   744     "Do not manually edit this!! If it is corrupted,
   745      the ImageEditor may not be able to read the specification."
   746 
   747     "
   748      self htmlFileIcon inspect
   749      ImageEditor openOnClass:self andSelector:#htmlFileIcon
   750      Icon flushCachedIcons
   751     "
   752 
   753     <resource: #image>
   754 
   755     ^Icon
   756         constantNamed:'DirectoryView::FileRow htmlFileIcon'
   757         ifAbsentPut:[(Depth4Image width:20 height:19) bits:(ByteArray fromPackedString:'
   758 DQDQDQDQDQDQDQ????????DQDQD_???????1@QDQG???L3L3<P@QDQ??L3=DL3D@@QD_?3L?P3L1DQDQG?L3MCP3L1DQDQ?3QCQCMCP??1D_<4P4QDL4O?<Q
   759 G?L4QDL3MD??DQ?3L3QCL3S??1D_<3L4QDL4O?<QG?<3QDQCMO??DQ??L4QDP4S??1D_??=D??S???<QG???????????DQ???????????1DQDQDQDQDQDQDQ
   760 DQDQDQDQDQDQDP@a')
   761             colorMapFromArray:#[255 255 255 0 0 0 255 0 0 0 255 0 0 0 255 0 255 255 255 255 0 255 0 255 127 0 0 0 127 0 0 0 127 0 127 127 127 127 0 127 0 127 127 127 127 170 170 170]
   762             mask:((ImageMask width:20 height:19) bits:(ByteArray fromPackedString:'??0@??8@??<@??>@???@??? ???0???0???0???0???0???0???0???0???0???0???0???0_??0'); yourself); yourself]
   763 !
   764 
   765 imageFileIcon
   766     "This resource specification was automatically generated
   767      by the ImageEditor of ST/X."
   768 
   769     "Do not manually edit this!! If it is corrupted,
   770      the ImageEditor may not be able to read the specification."
   771 
   772     "
   773      self imageFileIcon inspect
   774      ImageEditor openOnClass:self andSelector:#imageFileIcon
   775      Icon flushCachedIcons
   776     "
   777 
   778     <resource: #image>
   779 
   780     ^Icon
   781         constantNamed:'DirectoryView::FileRow imageFileIcon'
   782         ifAbsentPut:[(Depth4Image width:20 height:19) bits:(ByteArray fromPackedString:'
   783 @@@@@@@@@@@@@@DQDQDQDQ@@@@@ADQDQDQDPD@@@@QDQDQDQDAD@@@DQDQDQDQ@QD@@ADQDQDQDP@@@@@TQG]4)G50@@@@EDQ7^$+W4QDP@AQD]7R$_WDQD@
   784 @SL6Y#$61!!DQ@@D3M&ZS''F0QDP@AL3Y&NS[FDQD@@RH%UR %-QDQ@@D"IUVB"5,QDP@AH"UUJBV5DQD@@QDQDQDQDQDQ@@DQDQDQDQDQDP@@@@@@@@@@@@@@
   785 @@@@@@@@@@@@@@@a')
   786             colorMapFromArray:#[0 0 0 255 255 255 255 0 0 0 255 0 0 0 255 0 255 255 255 255 0 255 0 255 127 0 0 0 127 0 0 0 127 0 127 127 127 127 0 127 0 127]
   787             mask:((ImageMask width:20 height:19) bits:(ByteArray fromPackedString:'??0@??8@??<@??>@???@??? ???0???0???0???0???0???0???0???0???0???0???0???0_??0'); yourself); yourself]
   788 !
   789 
   790 imgFileIcon
   791     "Generated by the Image Editor"
   792     "
   793     ImageEditor openOnClass:self andSelector:#imgFileIcon
   794     "
   795 
   796     <resource: #image>
   797 
   798     ^Icon
   799         constantNamed:#'DirectoryView::FileRow imgFileIcon'
   800         ifAbsentPut:[(Depth1Image new) width: 20; height: 19; photometric:(#palette); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'???9 @_0 @W2 @S0 @Q0 @_0 @O8  @0 @@0!!-F0 **0 **0 **0&**;&*&4 @B0 @N0???0???0'); colorMap:((OrderedCollection new add:(Color white); add:(Color black); yourself)); mask:((ImageMask new) width: 20; height: 19; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'??0@??8@??<@??>@???@??? ???0???0???0???0???0???0???0???0???0???0???0???0_??0'); yourself); yourself]
   801 !
   802 
   803 linkedFileIcon
   804     "Generated by the Image Editor"
   805     "
   806     ImageEditor openOnClass:self andSelector:#linkedFileIcon
   807     "
   808 
   809     <resource: #image>
   810 
   811     ^Icon
   812         constantNamed:#'DirectoryView::FileRow linkedFileIcon'
   813         ifAbsentPut:[(Depth2Image new) width: 20; height: 19; photometric:(#palette); bitsPerSample:(#(2 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'UUUUUUU@@@@UUT@@@AEUP@@@DEU@@@@PET@@@AUUP@@@AUU@@@@@AT@@@@ EP@@@B U@@@**!!T@@J**EP@B B UB*(@HATJ*@@@EP@@@@@U@@@@@AUUUUUUUUUUUUUTb') ; colorMap:((OrderedCollection new add:(Color white); add:(Color black); add:(Color red:0.0 green:0.0 blue:100.0); add:(Color red:100.0 green:0.0 blue:0.0); yourself)); mask:((ImageMask new) width: 20; height: 19; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'??0@??8@??<@??>@???@??? ???0???0???0???0???0???0???0???0???0???0???0???0_??0') ; yourself); yourself]
   814 !
   815 
   816 lockedFileIcon
   817     "Generated by the Image Editor"
   818     "
   819     ImageEditor openOnClass:self andSelector:#lockedFileIcon
   820     "
   821 
   822     <resource: #image>
   823 
   824     ^Icon
   825         constantNamed:#'DirectoryView::FileRow lockedFileIcon'
   826         ifAbsentPut:[(Depth2Image new) width: 20; height: 19; photometric:(#palette); bitsPerSample:(#(2 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'UUUUUUU(@@@UUT(@@AEUP(@@DEU@(@@PET@(@IUUP@(B!!UU@@((@AT@@*@@EP@B(@@U@@((@AT@J@(@EPB @(@U@(@@(ATJ@@@(ER @@@(U(@@@@)UUUUUUUUUUUUUTb') ; colorMap:((OrderedCollection new add:(Color white); add:(Color black); add:(Color red:100.0 green:0.0 blue:0.0); add:(Color red:0.0 green:100.0 blue:0.0); yourself)); mask:((ImageMask new) width: 20; height: 19; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'??0@??8@??<@??>@???@??? ???0???0???0???0???0???0???0???0???0???0???0???0_??0') ; yourself); yourself]
   827 !
   828 
   829 protoFileIcon
   830 
   831     ^self MakefileIcon
   832 !
   833 
   834 rcFileIcon
   835     "Generated by the Image Editor"
   836     "
   837     ImageEditor openOnClass:self andSelector:#rcFileIcon
   838     "
   839 
   840     <resource: #image>
   841 
   842     ^Icon
   843         constantNamed:#'DirectoryView::FileRow rcFileIcon'
   844         ifAbsentPut:[(Depth1Image new) width: 20; height: 19; photometric:(#palette); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'???9 @_0 @W2 @S0 @Q0 @_0 @O8 @@0 @@0 ) 0 2P0 "@0 "@0&"P;&!! 4 @@0 @@0???0???0') ; colorMap:((OrderedCollection new add:(Color white); add:(Color black); yourself)); mask:((ImageMask new) width: 20; height: 19; photometric:(#blackIs0); bitsPerSample:(#(1 )); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'??0@??8@??<@??>@???@??? ???0???0???0???0???0???0???0???0???0???0???0???0_??0') ; yourself); yourself]
   845 !
   846 
   847 sFileIcon
   848     "This resource specification was automatically generated
   849      by the ImageEditor of ST/X."
   850 
   851     "Do not manually edit this!! If it is corrupted,
   852      the ImageEditor may not be able to read the specification."
   853 
   854     "
   855      self sFileIcon inspect
   856      ImageEditor openOnClass:self andSelector:#sFileIcon
   857      Icon flushCachedIcons
   858     "
   859 
   860     <resource: #image>
   861 
   862     ^Icon
   863         constantNamed:'DirectoryView::FileRow sFileIcon'
   864         ifAbsentPut:[(Depth1Image width:20 height:19) bits:(ByteArray fromPackedString:'???9 @_0 @W2 @S0 @Q0 @_0 @O8 @@0 @@0 X@0  @0 0@0 X@0&H@;&0@4 @@0 @@0???0???0')
   865             colorMapFromArray:#[255 255 255 0 0 0]
   866             mask:((ImageMask width:20 height:19) bits:(ByteArray fromPackedString:'??0@??8@??<@??>@???@??? ???0???0???0???0???0???0???0???0???0???0???0???0_??0'); yourself); yourself]
   867 !
   868 
   869 stFileIcon
   870     "This resource specification was automatically generated
   871      by the ImageEditor of ST/X."
   872 
   873     "Do not manually edit this!! If it is corrupted,
   874      the ImageEditor may not be able to read the specification."
   875 
   876     "
   877      self stFileIcon inspect
   878      ImageEditor openOnClass:self andSelector:#stFileIcon
   879      Icon flushCachedIcons
   880     "
   881 
   882     <resource: #image>
   883 
   884     ^Icon
   885         constantNamed:'DirectoryView::FileRow stFileIcon'
   886         ifAbsentPut:[(Depth1Image width:20 height:19) bits:(ByteArray fromPackedString:'???9 @_0 @W2 @S0 @Q0 @_0 @O8 A@0 A@0 [00 !!@0 1@0 Y@0&I@;&004 @@0 @@0???0???0')
   887             colorMapFromArray:#[255 255 255 0 0 0]
   888             mask:((ImageMask width:20 height:19) bits:(ByteArray fromPackedString:'??0@??8@??<@??>@???@??? ???0???0???0???0???0???0???0???0???0???0???0???0_??0'); yourself); yourself]
   889 !
   890 
   891 stcFileIcon
   892     "This resource specification was automatically generated
   893      by the ImageEditor of ST/X."
   894 
   895     "Do not manually edit this!! If it is corrupted,
   896      the ImageEditor may not be able to read the specification."
   897 
   898     "
   899      self stcFileIcon inspect
   900      ImageEditor openOnClass:self andSelector:#stcFileIcon
   901      Icon flushCachedIcons
   902     "
   903 
   904     <resource: #image>
   905 
   906     ^Icon
   907         constantNamed:'DirectoryView::FileRow stcFileIcon'
   908         ifAbsentPut:[(Depth1Image width:20 height:19) bits:(ByteArray fromPackedString:'???9 @_0 @W2 @S0 @Q0 @_0 @O8 B@0 B@0 _L0 "R0 2P0 ZP0&JR;&3L4 @@0 @@0???0???0')
   909             colorMapFromArray:#[255 255 255 0 0 0]
   910             mask:((ImageMask width:20 height:19) bits:(ByteArray fromPackedString:'??0@??8@??<@??>@???@??? ???0???0???0???0???0???0???0???0???0???0???0???0_??0'); yourself); yourself]
   911 ! !
   912 
   913 !DirectoryView::FileRow methodsFor:'accessing'!
   914 
   915 baseName
   916 
   917     ^baseName ? (baseName := fileName baseName)
   918 
   919 
   920 
   921 
   922 
   923 
   924 
   925 !
   926 
   927 fileName
   928 
   929     ^fileName
   930 !
   931 
   932 fileName: aFileName
   933 
   934     fileName := aFileName
   935 !
   936 
   937 group
   938 
   939     ^group
   940 !
   941 
   942 iconOn:aGC
   943 
   944     |icon|
   945     iconKey isNil 
   946     ifTrue: 
   947     [
   948         self validateAttributes.
   949         (imageFromFile isNil and: [iconKey == #imageFileIcon])
   950             ifTrue:  [icon := self retrieveImageFromFileAndRegisterOn: aGC]
   951     ].
   952     imageFromFile == true
   953         ifFalse: [icon := aGC registerImage: (self class perform: iconKey) key: iconKey]
   954         ifTrue:  [icon := aGC registeredImageAt: iconKey].
   955     ^icon
   956 
   957     "Modified: / 18.2.1998 / 18:01:52 / cg"
   958 !
   959 
   960 modified
   961 
   962     ^modified
   963 !
   964 
   965 owner
   966 
   967     ^owner
   968 !
   969 
   970 permissions
   971 
   972     ^permissions
   973 !
   974 
   975 retrieveImageFromFileAndRegisterOn: aGC
   976     "retrieve a bitmap image - but only if it is smaller than some limit (currently 20k)"
   977 
   978     |image maxImageFileSize|
   979 
   980     maxImageFileSize := MaxImageFileSize ? 20000.
   981 
   982     imageFromFile := false.       
   983     (image := aGC registeredImageAt: fileName name asSymbol) isNil
   984     ifTrue:[            
   985         size < maxImageFileSize ifTrue:[     
   986             Error handle: [:ex|]
   987             do:[   
   988                 (image := Image fromFile: fileName name) notNil ifTrue:[
   989                     image extent y > 22 ifTrue:[         
   990                         image := image magnifiedBy: 22/image extent y
   991                     ].
   992                     image := aGC registerImage: image key: fileName name asSymbol.
   993                 ]
   994             ] 
   995         ].
   996     ].
   997     image notNil ifTrue: [imageFromFile := true. iconKey := fileName name asSymbol].
   998     ^image
   999 !
  1000 
  1001 size
  1002     size isNumber ifFalse:[^ size].
  1003     size < 1000        ifTrue: [^ size printString].
  1004     size < (100*1024)  ifTrue: [^(((size/1024) * 10) asInteger/10) asFloat printString, ' Kb'].
  1005     size < (1000*1024) ifTrue: [^(((size/1024)) asInteger) printString, ' Kb'].
  1006     ^(((size/1048576) * 10) asInteger/10) asFloat printString, ' Mb'
  1007 
  1008     "Modified: / 6.2.1998 / 03:38:45 / cg"
  1009 ! !
  1010 
  1011 !DirectoryView::FileRow methodsFor:'private'!
  1012 
  1013 validateAttributes
  1014     |info mode suffix| 
  1015 
  1016     permissions := '---------' copy.
  1017 
  1018     (info := fileName info) isNil ifTrue:[
  1019         iconKey := #lockedFileIcon.
  1020         size    := owner := group := '?'.
  1021         ^ self
  1022     ].        
  1023     size   := info size.
  1024     modified := info modificationTime printString.
  1025     owner  := OperatingSystem getUserNameFromID: info uid.
  1026     group  := OperatingSystem getGroupNameFromID: info gid.
  1027     mode   := info mode.
  1028 
  1029     1 to:9 by:3 do:[:i|
  1030         #((0 $x) (1 $w) (2 $r)) do:
  1031         [:m|
  1032             (mode bitAt:i + m first) == 1 ifTrue:[permissions at: 10 - m first - i put: m last]
  1033         ]
  1034     ].
  1035 
  1036     fileName isReadable ifFalse:[
  1037         ^ iconKey := #lockedFileIcon
  1038     ].
  1039     info type == #symbolicLink ifTrue:[
  1040         ^ iconKey := #linkedFileIcon
  1041     ].
  1042     suffix := fileName suffix.
  1043 
  1044     ((self class respondsTo:(iconKey := (suffix, 'FileIcon') asSymbol))
  1045         or: [self class respondsTo: (iconKey := (fileName baseName, 'Icon') asSymbol)]
  1046     ) ifFalse:[
  1047         iconKey := #fileIcon.
  1048         ((suffix = 'o') or:[suffix = 'so']) ifTrue: [
  1049             ^ iconKey := #binaryFileIcon
  1050         ].
  1051         (Image isImageFileSuffix:suffix) ifTrue: [
  1052             ^ iconKey := #imageFileIcon
  1053         ].
  1054 
  1055         fileName isExecutableProgram ifTrue:[
  1056             ^ iconKey := #exeFileIcon
  1057         ]
  1058     ]
  1059 ! !
  1060 
  1061 !DirectoryView class methodsFor:'documentation'!
  1062 
  1063 version
  1064     ^ '$Header$'
  1065 !
  1066 
  1067 version_CVS
  1068     ^ '$Header$'
  1069 ! !
  1070