DirectoryView.st
author Claus Gittinger <cg@exept.de>
Sat, 21 Jul 2012 18:58:03 +0200
changeset 2898 c7f6c498df6a
parent 2878 241be37ce37b
child 2938 8e9207531826
permissions -rw-r--r--
category of:15 methods
     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:'initialize-release'!
   410 
   411 release
   412 
   413     monitoring ifTrue:
   414     [
   415         Processor removeTimedBlock:monitoringTimeBlock.
   416         monitoringTimeBlock := nil
   417     ].
   418 
   419     super release
   420 
   421 ! !
   422 
   423 !DirectoryView methodsFor:'menu actions'!
   424 
   425 updateFileList
   426     DirectoryContents flushCache.
   427     self readDirectory
   428 
   429     "Created: / 11.2.2000 / 00:12:46 / cg"
   430     "Modified: / 11.2.2000 / 00:14:32 / cg"
   431 ! !
   432 
   433 !DirectoryView methodsFor:'private'!
   434 
   435 readDirectory
   436     |allDirectories allFiles foundFiles filterList dir newContents|    
   437 
   438     allFiles := OrderedCollection new.
   439     allDirectories := OrderedCollection new.
   440     foundFiles := OrderedCollection new.
   441     "/ filterList := self listOfFileFilters value.
   442     filterList := self selectedFileFilter asCollectionOfSubstringsSeparatedBy:$;.
   443     filterList := filterList collect:[:pattern | pattern withoutSeparators].
   444 
   445     self withCursor:Cursor read do:[ 
   446         (dir := DirectoryContents directoryNamed: directory) notNil ifTrue:[
   447 "/            dir filesAndBasenamesDo:[:file :name|      
   448 "/                filterList do:[:filter|
   449 "/                    ((filter match:name) and:[(foundFiles includes: name) not])
   450 "/                    ifTrue:[
   451 "/                        foundFiles add: name
   452 "/                    ].
   453 "/                ].
   454 "/            ].
   455             dir filesAndBasenamesDo:[:file :name|      
   456                 allFiles add: name
   457             ].
   458             dir directoriesAndBasenamesDo:[:file :name|      
   459                 allDirectories add: name
   460             ].
   461 
   462             Filename isCaseSensitive ifFalse:[
   463                 filterList do:[:filter|
   464                     |lcFilter|
   465 
   466                     lcFilter := filter asLowercase.
   467                     foundFiles
   468                         addAll:(allFiles 
   469                                     select:[:name | lcFilter match:name asLowercase]
   470                                 ).
   471                 ]
   472             ] ifTrue:[
   473                 filterList do:[:filter|
   474                     foundFiles
   475                         addAll:(allFiles 
   476                                     select:[:name | filter match:name]
   477                                 ).
   478                 ]
   479             ].
   480 
   481             foundFiles sort.
   482             allDirectories sort.
   483 
   484             dir := directory asFilename.
   485 
   486             newContents := OrderedCollection new.
   487             newContents addAll:(allDirectories collect:[:name| FileRow new fileName:(dir construct:name)]).
   488             newContents addAll:(foundFiles collect:[:name| FileRow new fileName:(dir construct:name)]).
   489 
   490             self listOfFiles contents:newContents
   491         ]
   492     ]
   493 
   494     "Modified: / 23.9.1998 / 17:00:42 / cg"
   495 !
   496 
   497 readMonitoringDirectory
   498 
   499     |readBlock|
   500     readTask notNil ifTrue: [readTask terminate].
   501     readBlock :=
   502     [
   503         |dir currentFilenames oldListOfFiles|
   504         dir := directory asFilename.
   505         currentFilenames := OrderedCollection new.
   506         (dir isReadable and:[dir isExecutable]) ifTrue:
   507         [
   508             self listOfFileFilters value do:
   509             [:filter|
   510                 (dir filesMatchingWithoutDotDirs: filter) do:
   511                 [:aFileName|
   512                     |file|
   513                     (file := dir construct: aFileName) isDirectory
   514                     ifFalse:
   515                     [
   516                         currentFilenames add: file
   517                     ]
   518                 ].
   519             ].
   520         ].
   521         oldListOfFiles := self listOfFiles copy.
   522         (currentFilenames asSortedCollection: [:f1 :f2| f1 baseName < f2 baseName]) asSet do: 
   523         [:fileName| 
   524             (oldListOfFiles detect: [:fileRow| fileRow fileName = fileName] ifNone: nil) isNil
   525             ifTrue:                                                                             
   526             [
   527                 |nearestFileRow r|
   528                 nearestFileRow := self listOfFiles indexOf: (self listOfFiles detect: [:fileRow| fileRow baseName > fileName baseName] ifNone: nil).
   529                 nearestFileRow = 0
   530                 ifTrue: [self listOfFiles add: (r := FileRow new fileName: fileName asFilename)]
   531                 ifFalse: [self listOfFiles add: (r := FileRow new fileName: fileName asFilename) beforeIndex: nearestFileRow].
   532                 monitoring ifTrue: [self selectionOfFile value: r].
   533             ]
   534         ].
   535         self listOfFiles reverseDo:
   536         [:fileRow|
   537             (currentFilenames includes: fileRow fileName)
   538             ifFalse: [self listOfFiles remove: fileRow]
   539         ]
   540     ].
   541 
   542     monitoring
   543     ifTrue:
   544     [
   545         readTask := readBlock forkAt: Processor userBackgroundPriority.
   546         Processor addTimedBlock: monitoringTimeBlock afterSeconds: 1
   547     ]
   548     ifFalse:
   549     [
   550         Cursor wait showWhile: [readBlock value]
   551     ]
   552 ! !
   553 
   554 !DirectoryView methodsFor:'selection'!
   555 
   556 selectedFileFilter
   557 
   558     ^selectedFileFilter
   559 
   560 !
   561 
   562 selectedFileFilter:aString
   563     "change the file filter"
   564 
   565     |listOfFileFilters nArgs|
   566 
   567     aString = selectedFileFilter ifTrue:[^ self].
   568 
   569     listOfFileFilters := self listOfFileFilters.
   570 
   571     "/ what is this for ?
   572     aString size == 0 ifTrue: [
   573         listOfFileFilters remove: selectedFileFilter ifAbsent: nil
   574     ].
   575     selectedFileFilter := aString.
   576 
   577     ((listOfFileFilters includes: selectedFileFilter) not
   578     and:[selectedFileFilter notEmpty])
   579     ifTrue: [
   580         listOfFileFilters addFirst: selectedFileFilter
   581     ].
   582     ((listOfFileFilters includes: selectedFileFilter)
   583     and:[fileFilterSelectAction notNil]) 
   584     ifTrue: [
   585         (nArgs := fileFilterSelectAction numArgs) == 0
   586         ifTrue: [
   587             fileFilterSelectAction value
   588         ] ifFalse:[
   589             nArgs == 1 ifTrue:[
   590                 fileFilterSelectAction value: selectedFileFilter
   591             ] ifFalse:[
   592                 self error:'bad numArgs of fileFilter action block'
   593             ]
   594         ]
   595     ].       
   596     self readDirectory.
   597 
   598     "Modified: / 23.9.1998 / 16:53:05 / cg"
   599 ! !
   600 
   601 !DirectoryView methodsFor:'startup / release'!
   602 
   603 closeRequest
   604 
   605     self release.
   606 
   607     super closeRequest
   608 
   609 ! !
   610 
   611 !DirectoryView::FileRow class methodsFor:'resources'!
   612 
   613 HFileIcon
   614 
   615     ^self hFileIcon
   616 !
   617 
   618 MakefileIcon
   619     "Generated by the Image Editor"
   620     "
   621     ImageEditor openOnClass:self andSelector:#MakefileIcon
   622     "
   623 
   624     <resource: #image>
   625 
   626     ^Icon
   627         constantNamed:#'DirectoryView::FileRow MakefileIcon'
   628         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]
   629 !
   630 
   631 binaryFileIcon
   632     "Generated by the Image Editor"
   633     "
   634     ImageEditor openOnClass:self andSelector:#binaryFileIcon
   635     "
   636 
   637     <resource: #image>
   638 
   639     ^Icon
   640         constantNamed:#'DirectoryView::FileRow binaryFileIcon'
   641         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]
   642 !
   643 
   644 cFileIcon
   645     "Generated by the Image Editor"
   646     "
   647     ImageEditor openOnClass:self andSelector:#cFileIcon
   648     "
   649 
   650     <resource: #image>
   651 
   652     ^Icon
   653         constantNamed:#'DirectoryView::FileRow cFileIcon'
   654         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]
   655 !
   656 
   657 exeFileIcon
   658     "Generated by the Image Editor"
   659     "
   660     ImageEditor openOnClass:self andSelector:#exeFileIcon
   661     "
   662 
   663     <resource: #image>
   664 
   665     ^Icon
   666         constantNamed:#'DirectoryView::FileRow exeFileIcon'
   667         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]
   668 !
   669 
   670 fileIcon
   671     "Generated by the Image Editor"
   672     "
   673     ImageEditor openOnClass:self andSelector:#fileIcon
   674     "
   675 
   676     <resource: #image>
   677 
   678     ^Icon
   679         constantNamed:#'DirectoryView::FileRow fileIcon'
   680         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]
   681 !
   682 
   683 hFileIcon
   684     "Generated by the Image Editor"
   685     "
   686     ImageEditor openOnClass:self andSelector:#hFileIcon
   687     "
   688 
   689     <resource: #image>
   690 
   691     ^Icon
   692         constantNamed:#'DirectoryView::FileRow hFileIcon'
   693         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]
   694 !
   695 
   696 htmlFileIcon
   697     "Generated by the Image Editor"
   698     "
   699     ImageEditor openOnClass:self andSelector:#htmlFileIcon
   700     "
   701 
   702     <resource: #image>
   703 
   704     ^Icon
   705         constantNamed:#'DirectoryView::FileRow htmlFileIcon'
   706         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]
   707 !
   708 
   709 imageFileIcon
   710     "Generated by the Image Editor"
   711     "
   712     ImageEditor openOnClass:self andSelector:#imageFileIcon
   713     "
   714 
   715     <resource: #image>
   716 
   717     ^Icon
   718         constantNamed:#'DirectoryView::FileRow imageFileIcon'
   719         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]
   720 !
   721 
   722 imgFileIcon
   723     "Generated by the Image Editor"
   724     "
   725     ImageEditor openOnClass:self andSelector:#imgFileIcon
   726     "
   727 
   728     <resource: #image>
   729 
   730     ^Icon
   731         constantNamed:#'DirectoryView::FileRow imgFileIcon'
   732         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]
   733 !
   734 
   735 linkedFileIcon
   736     "Generated by the Image Editor"
   737     "
   738     ImageEditor openOnClass:self andSelector:#linkedFileIcon
   739     "
   740 
   741     <resource: #image>
   742 
   743     ^Icon
   744         constantNamed:#'DirectoryView::FileRow linkedFileIcon'
   745         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]
   746 !
   747 
   748 lockedFileIcon
   749     "Generated by the Image Editor"
   750     "
   751     ImageEditor openOnClass:self andSelector:#lockedFileIcon
   752     "
   753 
   754     <resource: #image>
   755 
   756     ^Icon
   757         constantNamed:#'DirectoryView::FileRow lockedFileIcon'
   758         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]
   759 !
   760 
   761 protoFileIcon
   762 
   763     ^self MakefileIcon
   764 !
   765 
   766 rcFileIcon
   767     "Generated by the Image Editor"
   768     "
   769     ImageEditor openOnClass:self andSelector:#rcFileIcon
   770     "
   771 
   772     <resource: #image>
   773 
   774     ^Icon
   775         constantNamed:#'DirectoryView::FileRow rcFileIcon'
   776         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]
   777 !
   778 
   779 sFileIcon
   780     "Generated by the Image Editor"
   781     "
   782     ImageEditor openOnClass:self andSelector:#sFileIcon
   783     "
   784 
   785     <resource: #image>
   786 
   787     ^Icon
   788         constantNamed:#'DirectoryView::FileRow sFileIcon'
   789         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]
   790 !
   791 
   792 stFileIcon
   793     "Generated by the Image Editor"
   794     "
   795     ImageEditor openOnClass:self andSelector:#stFileIcon
   796     "
   797 
   798     <resource: #image>
   799 
   800     ^Icon
   801         constantNamed:#'DirectoryView::FileRow stFileIcon'
   802         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]
   803 !
   804 
   805 stcFileIcon
   806     "Generated by the Image Editor"
   807     "
   808     ImageEditor openOnClass:self andSelector:#stcFileIcon
   809     "
   810 
   811     <resource: #image>
   812 
   813     ^Icon
   814         constantNamed:#'DirectoryView::FileRow stcFileIcon'
   815         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]
   816 ! !
   817 
   818 !DirectoryView::FileRow methodsFor:'accessing'!
   819 
   820 baseName
   821 
   822     ^baseName ? (baseName := fileName baseName)
   823 
   824 
   825 
   826 
   827 
   828 
   829 
   830 !
   831 
   832 fileName
   833 
   834     ^fileName
   835 !
   836 
   837 fileName: aFileName
   838 
   839     fileName := aFileName
   840 !
   841 
   842 group
   843 
   844     ^group
   845 !
   846 
   847 iconOn:aGC
   848 
   849     |icon|
   850     iconKey isNil 
   851     ifTrue: 
   852     [
   853         self validateAttributes.
   854         (imageFromFile isNil and: [iconKey == #imageFileIcon])
   855             ifTrue:  [icon := self retrieveImageFromFileAndRegisterOn: aGC]
   856     ].
   857     imageFromFile == true
   858         ifFalse: [icon := aGC registerImage: (self class perform: iconKey) key: iconKey]
   859         ifTrue:  [icon := aGC registeredImageAt: iconKey].
   860     ^icon
   861 
   862     "Modified: / 18.2.1998 / 18:01:52 / cg"
   863 !
   864 
   865 modified
   866 
   867     ^modified
   868 !
   869 
   870 owner
   871 
   872     ^owner
   873 !
   874 
   875 permissions
   876 
   877     ^permissions
   878 !
   879 
   880 retrieveImageFromFileAndRegisterOn: aGC
   881     "retrieve a bitmap image - but only if it is smaller than some limit (currently 20k)"
   882 
   883     |image maxImageFileSize|
   884 
   885     maxImageFileSize := MaxImageFileSize ? 20000.
   886 
   887     imageFromFile := false.       
   888     (image := aGC registeredImageAt: fileName name asSymbol) isNil
   889     ifTrue:[            
   890         size < maxImageFileSize ifTrue:[     
   891             Object errorSignal handle: [:ex|]
   892             do:[   
   893                 (image := Image fromFile: fileName name) notNil ifTrue:[
   894                     image extent y > 22 ifTrue:[         
   895                         image := image magnifiedBy: 22/image extent y
   896                     ].
   897                     image := aGC registerImage: image key: fileName name asSymbol.
   898                 ]
   899             ] 
   900         ].
   901     ].
   902     image notNil ifTrue: [imageFromFile := true. iconKey := fileName name asSymbol].
   903     ^image
   904 
   905 
   906 
   907 !
   908 
   909 size
   910     size isNumber ifFalse:[^ size].
   911     size < 1000        ifTrue: [^ size printString].
   912     size < (100*1024)  ifTrue: [^(((size/1024) * 10) asInteger/10) asFloat printString, ' Kb'].
   913     size < (1000*1024) ifTrue: [^(((size/1024)) asInteger) printString, ' Kb'].
   914     ^(((size/1048576) * 10) asInteger/10) asFloat printString, ' Mb'
   915 
   916     "Modified: / 6.2.1998 / 03:38:45 / cg"
   917 ! !
   918 
   919 !DirectoryView::FileRow methodsFor:'private'!
   920 
   921 validateAttributes
   922 
   923     |info mode| 
   924 
   925     permissions := String new:9 withAll:$-.
   926 
   927     (info := fileName info) isNil
   928     ifTrue:
   929     [
   930         iconKey := #lockedFileIcon.
   931         size    := owner := group := '?'.
   932       ^ self
   933     ].        
   934     size   := info size.
   935     modified := info modificationTime printString.
   936     owner  := OperatingSystem getUserNameFromID: info uid.
   937     group  := OperatingSystem getGroupNameFromID: info gid.
   938     mode   := info mode.
   939 
   940     1 to:9 by:3 do:[:i|
   941         #((0 $x) (1 $w) (2 $r)) do:
   942         [:m|
   943             (mode bitAt:i + m first) == 1 ifTrue:[permissions at: 10 - m first - i put: m last]
   944         ]
   945     ].
   946 
   947     fileName isReadable
   948     ifTrue:
   949     [
   950         info type == #symbolicLink
   951         ifTrue:
   952         [
   953             ^iconKey := #linkedFileIcon
   954         ]
   955         ifFalse:
   956         [       
   957             ((DirectoryView::FileRow class implements: (iconKey := (fileName suffix, 'FileIcon') asSymbol))
   958             or:
   959             [DirectoryView::FileRow class implements: (iconKey := (fileName baseName, 'Icon') asSymbol)])
   960             ifFalse:
   961             [
   962                 iconKey := #fileIcon.
   963                 (Image isImageFileSuffix:fileName suffix)
   964                 ifTrue:
   965                 [
   966                     ^iconKey := #imageFileIcon
   967                 ].
   968                 (fileName suffix = 'o') | (fileName suffix = 'so')
   969                 ifTrue:
   970                 [
   971                     ^iconKey := #binaryFileIcon
   972                 ].
   973 
   974                 fileName isExecutableProgram
   975                 ifTrue:
   976                 [
   977                     ^iconKey := #exeFileIcon
   978                 ]
   979             ]
   980         ]
   981     ] 
   982     ifFalse:
   983     [
   984         ^iconKey := #lockedFileIcon
   985     ].
   986 ! !
   987 
   988 !DirectoryView class methodsFor:'documentation'!
   989 
   990 version
   991     ^ '$Header$'
   992 ! !