Filename.st
changeset 4131 f370ebc75bf9
parent 3978 b2babde0857b
child 4148 70c391aa0e3e
equal deleted inserted replaced
4130:662554f2a37c 4131:f370ebc75bf9
   754      If multiple files match, the exception block aBlock is evaluated with a 
   754      If multiple files match, the exception block aBlock is evaluated with a 
   755      filename representing the directory (where the match was done) as argument.
   755      filename representing the directory (where the match was done) as argument.
   756      (this may be different from the inDirectory argument, if aString is absolute
   756      (this may be different from the inDirectory argument, if aString is absolute
   757       or starts with ../)"
   757       or starts with ../)"
   758 
   758 
   759     |s f matchSet nMatch name words dir isAbsolute|
   759     |s f matchSet nMatch name words dir isAbsolute sep|
   760 
   760 
   761     (self ~~ ConcreteClass) ifTrue:[
   761     (self ~~ ConcreteClass) ifTrue:[
   762         ^ ConcreteClass 
   762         ^ ConcreteClass 
   763             filenameCompletionFor:aString 
   763             filenameCompletionFor:aString 
   764             directory:inDirectory       
   764             directory:inDirectory       
   781 
   781 
   782     f := words last asFilename.
   782     f := words last asFilename.
   783     isAbsolute := f isAbsolute.
   783     isAbsolute := f isAbsolute.
   784 
   784 
   785     matchSet := f filenameCompletionIn:inDirectory.
   785     matchSet := f filenameCompletionIn:inDirectory.
   786 
       
   787     dir := f directory.
   786     dir := f directory.
   788 
   787 
   789     directoriesOnly ifTrue:[
   788     matchSet := matchSet select:[:aFilename |
   790         matchSet := matchSet select:[:aFilename |
   789         |f isDir|
   791             |f|
   790 
   792 
   791         isAbsolute ifTrue:[
   793             isAbsolute ifTrue:[
   792             f := aFilename asFilename
   794                 f := aFilename asFilename
   793         ] ifFalse:[
   795             ] ifFalse:[
   794             f := (dir construct:aFilename). 
   796                 f := (dir construct:aFilename). 
       
   797             ].
       
   798             f isDirectory
       
   799         ].
   795         ].
   800     ] ifFalse:[
   796         isDir := f isDirectory.
   801         filesOnly ifTrue:[
   797         directoriesOnly ifTrue:[    
   802             matchSet := matchSet select:[:aFilename |
   798             isDir
   803                 |f|
   799         ] ifFalse:[
   804 
   800             isDir not
   805                 isAbsolute ifTrue:[
       
   806                     f := aFilename asFilename
       
   807                 ] ifFalse:[
       
   808                     f := (dir construct:aFilename). 
       
   809                 ].
       
   810                 f isDirectory not
       
   811             ].
       
   812         ]
   801         ]
   813     ].
   802     ].
   814 
   803 
   815     (nMatch := matchSet size) ~~ 1 ifTrue:[
   804     (nMatch := matchSet size) ~~ 1 ifTrue:[
   816         "
   805         "
   817          more than one possible completion -
   806          more than one possible completion -
   818         "
   807         "
   819         aBlock value:f
   808         aBlock value:f
   820     ].
   809     ].
       
   810 
       
   811     sep := self separator.
       
   812 
   821     "
   813     "
   822      even with more than one possible completion,
   814      even with more than one possible completion,
   823      f's name is now the common prefix
   815      f's name is now the common prefix
   824     "
   816     "
   825     name := f asString.
   817     name := f asString.
   828          exactly one possible completion -
   820          exactly one possible completion -
   829         "
   821         "
   830 "/        f := dir construct:matchSet first.
   822 "/        f := dir construct:matchSet first.
   831         false "directoriesOnly" ifFalse:[
   823         false "directoriesOnly" ifFalse:[
   832             f isDirectory ifTrue:[
   824             f isDirectory ifTrue:[
   833                 (name endsWith:(Filename separator)) ifFalse:[
   825                 (name endsWith:sep) ifFalse:[
   834                     name := name , (Filename separator)
   826                     name := name , sep asString
   835                 ].
   827                 ].
   836             ].
   828             ].
   837         ]
   829         ]
   838     ].
   830     ].
   839 
   831 
   848     s := s , name.
   840     s := s , name.
   849 
   841 
   850     "/ special: if there was no change, and the string represented
   842     "/ special: if there was no change, and the string represented
   851     "/ is a directories name, add a directory separator
   843     "/ is a directories name, add a directory separator
   852     ((nMatch == 1) or:[s = aString]) ifTrue:[
   844     ((nMatch == 1) or:[s = aString]) ifTrue:[
   853         (s endsWith:Filename separator) ifFalse:[
   845         (s endsWith:sep) ifFalse:[
   854             s asFilename isDirectory ifTrue:[
   846             s asFilename isDirectory ifTrue:[
   855                 ^ s , Filename separator asString
   847                 ^ s , sep asString
   856             ]
   848             ]
   857         ].
   849         ].
   858     ].
   850     ].
   859 
   851 
   860     ^ s
   852     ^ s
   861 
   853 
   862     "Modified: / 24.9.1998 / 22:10:34 / cg"
   854     "Modified: / 30.4.1999 / 09:40:13 / cg"
   863 !
   855 !
   864 
   856 
   865 filesMatching:aPattern
   857 filesMatching:aPattern
   866     "return a collection of strings, representing the names
   858     "return a collection of strings, representing the names
   867      of files matching aPattern.
   859      of files matching aPattern.
  2775             allMatching := true.
  2767             allMatching := true.
  2776         ].
  2768         ].
  2777 
  2769 
  2778         [allMatching] whileTrue:[
  2770         [allMatching] whileTrue:[
  2779             matching do:[:aName |
  2771             matching do:[:aName |
  2780                 (aName startsWith:try) ifFalse:[
  2772                 ((caseless and:[aName asLowercase startsWith:try asLowercase])
       
  2773                 or:[caseless not and:[aName startsWith:try]]) ifFalse:[
  2781                     allMatching := false
  2774                     allMatching := false
  2782                 ]
  2775                 ]
  2783             ].
  2776             ].
  2784             allMatching ifTrue:[
  2777             allMatching ifTrue:[
  2785                 matchLen <  matching first size ifTrue:[
  2778                 matchLen <  matching first size ifTrue:[
  2838      '/u' asFilename filenameCompletion             
  2831      '/u' asFilename filenameCompletion             
  2839      '../../libpr' asFilename filenameCompletion    
  2832      '../../libpr' asFilename filenameCompletion    
  2840     "
  2833     "
  2841 
  2834 
  2842     "Modified: / 22.9.1997 / 18:03:33 / stefan"
  2835     "Modified: / 22.9.1997 / 18:03:33 / stefan"
  2843     "Modified: / 20.8.1998 / 01:54:14 / cg"
  2836     "Modified: / 30.4.1999 / 09:39:52 / cg"
  2844 !
  2837 !
  2845 
  2838 
  2846 head 
  2839 head 
  2847     "return the directory name as a string. 
  2840     "return the directory name as a string. 
  2848      An alias for directoryName, for ST-80 compatiblity.
  2841      An alias for directoryName, for ST-80 compatiblity.
  3186 ! !
  3179 ! !
  3187 
  3180 
  3188 !Filename class methodsFor:'documentation'!
  3181 !Filename class methodsFor:'documentation'!
  3189 
  3182 
  3190 version
  3183 version
  3191     ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.151 1999-02-11 18:15:10 cg Exp $'
  3184     ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.152 1999-04-30 07:59:39 cg Exp $'
  3192 ! !
  3185 ! !
  3193 Filename initialize!
  3186 Filename initialize!