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