FileSelectionList.st
changeset 21 9ef599238fea
parent 11 c47dbae39a71
child 24 966098a893f8
equal deleted inserted replaced
20:0d9c61aacaa4 21:9ef599238fea
    11 "
    11 "
    12 
    12 
    13 SelectionInListView subclass:#FileSelectionList
    13 SelectionInListView subclass:#FileSelectionList
    14        instanceVariableNames:'pattern directory timeStamp directoryId
    14        instanceVariableNames:'pattern directory timeStamp directoryId
    15                               directoryContents directoryFileTypes
    15                               directoryContents directoryFileTypes
    16                               realAction'
    16                               realAction fileTypes'
    17        classVariableNames:''
    17        classVariableNames:''
    18        poolDictionaries:''
    18        poolDictionaries:''
    19        category:'Views-Text'
    19        category:'Views-Text'
    20 !
    20 !
    21 
    21 
    22 FileSelectionList comment:'
    22 FileSelectionList comment:'
    23 
    23 
    24 COPYRIGHT (c) 1993 by Claus Gittinger
    24 COPYRIGHT (c) 1993 by Claus Gittinger
    25               All Rights Reserved
    25               All Rights Reserved
    26 
    26 
    27 $Header: /cvs/stx/stx/libwidg/FileSelectionList.st,v 1.1 1993-12-16 11:02:42 claus Exp $
    27 $Header: /cvs/stx/stx/libwidg/FileSelectionList.st,v 1.2 1994-01-08 17:27:17 claus Exp $
    28 written Dec 93 by claus
    28 written Dec 93 by claus
    29 '!
    29 '!
    30 
    30 
    31 !FileSelectionList class methodsFor:'documentation'!
    31 !FileSelectionList class methodsFor:'documentation'!
    32 
    32 
    34 "
    34 "
    35 this class implements file selection lists - its basically a
    35 this class implements file selection lists - its basically a
    36 selection in list, but remembers the previous position when
    36 selection in list, but remembers the previous position when
    37 changing directories.
    37 changing directories.
    38 Only files matching a pattern (plus directories) are shown.
    38 Only files matching a pattern (plus directories) are shown.
       
    39 
       
    40 Instance variables:
       
    41         directoryContents       contents of current directory
       
    42         directoryFileTypes      file types (symbols) of current directory
       
    43         fileTypes               file types as shown in list 
       
    44                                 (i.e only matching ones)
    39 "
    45 "
    40 ! !
    46 ! !
    41 
    47 
    42 !FileSelectionList methodsFor:'initialization'!
    48 !FileSelectionList methodsFor:'initialization'!
    43 
    49 
   124             self updateList
   130             self updateList
   125         ].
   131         ].
   126     ].
   132     ].
   127 ! !
   133 ! !
   128 
   134 
       
   135 !FileSelectionList methodsFor:'drawing'!
       
   136 
       
   137 redrawFromVisibleLine:startVisLineNr to:endVisLineNr
       
   138     "redefined to look for directory in every line"
       
   139 
       
   140     startVisLineNr to:endVisLineNr do:[:l |
       
   141         self redrawVisibleLine:l
       
   142     ]
       
   143 !
       
   144 
       
   145 redrawVisibleLine:visLineNr
       
   146     "if the line is one for a directory, draw a right arrow"
       
   147 
       
   148     |l|
       
   149 
       
   150     super redrawVisibleLine:visLineNr.
       
   151     l := self visibleLineToListLine:visLineNr.
       
   152     l notNil ifTrue:[
       
   153         (fileTypes at:l) == #directory ifTrue:[
       
   154             self drawRightArrowInVisibleLine:visLineNr
       
   155         ]
       
   156     ]
       
   157 ! !
       
   158 
   129 !FileSelectionList methodsFor:'private'!
   159 !FileSelectionList methodsFor:'private'!
       
   160 
       
   161 visibleLineNeedsSpecialCare:visLineNr
       
   162     |l|
       
   163 
       
   164     l := self visibleLineToListLine:visLineNr.
       
   165     l notNil ifTrue:[
       
   166         (fileTypes at:l) == #directory ifTrue:[^ true].
       
   167         ^ super visibleLineNeedsSpecialCare:visLineNr
       
   168     ].
       
   169     ^ false
       
   170 !
       
   171 
       
   172 widthForScrollBetween:firstLine and:lastLine
       
   173     "return the width in pixels for a scroll between firstLine and lastLine
       
   174      - return full width here since there might be directory marks"
       
   175 
       
   176     ^ (width - margin - margin)
       
   177 !
   130 
   178 
   131 updateList
   179 updateList
   132     "set the lists contents to the filenames in the directory"
   180     "set the lists contents to the filenames in the directory"
   133 
   181 
   134     |oldCursor files newList index|
   182     |oldCursor files newList index|
   144         directoryContents do:[:name | directoryFileTypes add:(directory typeOf:name)].
   192         directoryContents do:[:name | directoryFileTypes add:(directory typeOf:name)].
   145     ].
   193     ].
   146 
   194 
   147     files := directoryContents.
   195     files := directoryContents.
   148     newList := OrderedCollection new.
   196     newList := OrderedCollection new.
       
   197     fileTypes := OrderedCollection new.
   149     index := 1.
   198     index := 1.
   150     files do:[:name |
   199     files do:[:name |
   151         (directoryFileTypes at:index) == #directory ifTrue:[
   200         (directoryFileTypes at:index) == #directory ifTrue:[
   152             name = '..' ifTrue:[
   201             name = '..' ifTrue:[
   153                 newList add:name
   202                 newList add:name.
       
   203                 fileTypes add:(directoryFileTypes at:index)
   154             ] ifFalse:[
   204             ] ifFalse:[
   155                 name = '.' ifTrue:[
   205                 name = '.' ifTrue:[
       
   206                     "ignore"
   156                 ] ifFalse:[
   207                 ] ifFalse:[
   157                     newList add:(name , ' ...')
   208                     newList add:(name ", ' ...'").
       
   209                     fileTypes add:(directoryFileTypes at:index)
   158                 ]
   210                 ]
   159             ]
   211             ]
   160         ] ifFalse:[
   212         ] ifFalse:[
   161             (pattern isEmpty or:[pattern = '*' or:[pattern match:name]]) ifTrue:[
   213             (pattern isEmpty or:[pattern = '*' or:[pattern match:name]]) ifTrue:[
   162                 newList add:name
   214                 newList add:name.
       
   215                 fileTypes add:(directoryFileTypes at:index)
   163             ]
   216             ]
   164         ].
   217         ].
   165         index := index + 1
   218         index := index + 1
   166     ].
   219     ].
   167     super list:newList.
   220     super list:newList.