AbstractDirectoryBrowser.st
changeset 18750 6be368350a8f
parent 18281 906957435fec
child 18752 45360c74eb11
equal deleted inserted replaced
18749:78d06a49dc41 18750:6be368350a8f
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "
     3 "
     2  COPYRIGHT (c) 2003 by eXept Software AG
     4  COPYRIGHT (c) 2003 by eXept Software AG
     3               All Rights Reserved
     5               All Rights Reserved
     4 
     6 
     5  This software is furnished under a license and may be used
     7  This software is furnished under a license and may be used
    68 ! !
    70 ! !
    69 
    71 
    70 !AbstractDirectoryBrowser methodsFor:'actions'!
    72 !AbstractDirectoryBrowser methodsFor:'actions'!
    71 
    73 
    72 findFilesMatching:aGLOBPattern
    74 findFilesMatching:aGLOBPattern
       
    75     "search files which match aGLOBPattern.
       
    76      If a folder is selected, the search starts there;
       
    77      otherwise in the top folder"
       
    78      
       
    79     |selItem searchDir|
       
    80 
       
    81     (selItem := self theSingleSelectedItemOrNil) notNil ifTrue:[
       
    82         selItem isDirectory ifTrue:[
       
    83             searchDir := selItem pathName
       
    84         ] ifFalse:[
       
    85             searchDir := selItem pathName asFilename directory
       
    86         ].    
       
    87     ] ifFalse:[   
       
    88         searchDir := self directory 
       
    89     ].  
       
    90     ^ self findFilesMatching:aGLOBPattern in:searchDir
       
    91 
       
    92     "Created: / 17-07-2018 / 12:53:32 / Claus Gittinger"
       
    93     "Modified: / 02-05-2019 / 20:41:57 / Claus Gittinger"
       
    94 !
       
    95 
       
    96 findFilesMatching:aGLOBPattern in:searchDir
       
    97     "search files which match aGLOBPattern."
       
    98      
    73     |matching|
    99     |matching|
    74 
   100 
    75     matching := OrderedCollection new.
   101     matching := OrderedCollection new.
    76     self directory recursiveDirectoryContentsAsFilenamesDo:[:each |
   102     searchDir asFilename recursiveDirectoryContentsAsFilenamesDo:[:each |
    77         (aGLOBPattern match:each baseName) ifTrue:[
   103         (aGLOBPattern match:each baseName) ifTrue:[
    78             matching add:each
   104             matching add:each
    79         ].    
   105         ].    
    80     ].
   106     ].
    81     ^ matching
   107     ^ matching
    82 
   108 
    83     "Created: / 17-07-2018 / 12:53:32 / Claus Gittinger"
   109     "Created: / 02-05-2019 / 18:58:30 / Claus Gittinger"
       
   110 !
       
   111 
       
   112 findNextFileMatching:aGLOBPattern startingAt:anItemOrNil
       
   113     "search files which match aGLOBPattern."
       
   114      
       
   115     |searchFolder searchIndex stack|
       
   116 
       
   117     stack := OrderedCollection new.
       
   118     anItemOrNil isRootItem ifFalse:[
       
   119         |i|
       
   120         
       
   121         i := anItemOrNil.
       
   122         [i isRootItem] whileFalse:[
       
   123             stack addFirst:(i parent -> (i parent children indexOf:i)).
       
   124             i := i parent.
       
   125         ].    
       
   126     ].
       
   127     
       
   128     anItemOrNil isDirectory ifTrue:[
       
   129         searchFolder := anItemOrNil.
       
   130         searchIndex := 0.
       
   131     ] ifFalse:[
       
   132         searchFolder := anItemOrNil parent.
       
   133         searchIndex := anItemOrNil parent children indexOf:anItemOrNil.
       
   134     ].
       
   135     stack add:(searchFolder -> searchIndex).
       
   136     
       
   137     [stack notEmpty] whileTrue:[
       
   138         |work children|
       
   139 
       
   140         work := stack removeLast.
       
   141         searchFolder := work key.
       
   142         searchIndex := work value.
       
   143         
       
   144         children := searchFolder children.
       
   145         searchIndex+1 to:(children size) doWithExit:[:childIndex :exit|
       
   146             |child|
       
   147             
       
   148             child := children at:childIndex.
       
   149 Transcript showCR:'search %1' with:child pathName.
       
   150             child isDirectory ifFalse:[
       
   151                 (aGLOBPattern match:child baseName) ifTrue:[
       
   152                     ^ child pathName asFilename
       
   153                 ].
       
   154             ] ifTrue:[
       
   155                 stack add:(searchFolder -> childIndex).
       
   156                 stack add:(child -> 0).
       
   157                 exit value:nil.
       
   158             ]
       
   159         ].
       
   160     ].  
       
   161     ^ nil
       
   162 
       
   163     "Created: / 02-05-2019 / 20:39:58 / Claus Gittinger"
    84 ! !
   164 ! !
    85 
   165 
    86 !AbstractDirectoryBrowser methodsFor:'drag & drop'!
   166 !AbstractDirectoryBrowser methodsFor:'drag & drop'!
    87 
   167 
    88 canDrop:aDropContext
   168 canDrop:aDropContext
   213 
   293 
   214 findAndSelectFilesMatching:aGLOBPattern
   294 findAndSelectFilesMatching:aGLOBPattern
   215     self selectFiles:(self findFilesMatching:aGLOBPattern).
   295     self selectFiles:(self findFilesMatching:aGLOBPattern).
   216 
   296 
   217     "Created: / 17-07-2018 / 12:48:23 / Claus Gittinger"
   297     "Created: / 17-07-2018 / 12:48:23 / Claus Gittinger"
       
   298 !
       
   299 
       
   300 findAndSelectNextFileMatching:aGLOBPattern
       
   301     |fileOrNil|
       
   302 
       
   303     fileOrNil := self findNextFileMatching:aGLOBPattern 
       
   304                       startingAt:(self theSingleSelectedItemOrNil ? self fileList root).
       
   305     self selectFiles:(fileOrNil isNil 
       
   306                         ifTrue:[#()]
       
   307                         ifFalse:[{ fileOrNil }])
       
   308 
       
   309     "Created: / 02-05-2019 / 20:43:41 / Claus Gittinger"
   218 ! !
   310 ! !
   219 
   311 
   220 !AbstractDirectoryBrowser methodsFor:'selection'!
   312 !AbstractDirectoryBrowser methodsFor:'selection'!
   221 
   313 
   222 selectedFiles
   314 selectedFiles