FileSelectionTree.st
changeset 492 0b6a6bc3f1cb
parent 488 bb017dc6df4f
child 495 e34c13af578d
equal deleted inserted replaced
491:c7d57a5e7a21 492:0b6a6bc3f1cb
   152         |fn|
   152         |fn|
   153         fn := scr selectedPathname asFilename.
   153         fn := scr selectedPathname asFilename.
   154         fn isDirectory ifFalse:[
   154         fn isDirectory ifFalse:[
   155             scr showLines:(scr showLines not)
   155             scr showLines:(scr showLines not)
   156         ]
   156         ]
       
   157     ].
       
   158     top open
       
   159                                                                         [exEnd]
       
   160 
       
   161 
       
   162 
       
   163     example associated with a FileSelectionList
       
   164                                                                         [exBegin]
       
   165     |top tree list field label|
       
   166 
       
   167     top   := StandardSystemView new label:'select'; extent:600@600.
       
   168     tree  := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(0.5 @ 1.0) in:top.
       
   169     list  := HVScrollableView for:FileSelectionList origin:(0.5 @  25) corner:(1.0 @ 1.0) in:top.
       
   170     label := Label origin:(0.5 @ 2) in:top.
       
   171     label label:'pattern:'.
       
   172     field := EditField origin:0.5@2 in:top.
       
   173     field leftInset:(label preferredExtent x) + 5.
       
   174     field width:1.0.
       
   175     field editValue:'*'.
       
   176     field crAction:[list pattern:field editValue].
       
   177 
       
   178     tree  := tree scrolledView.
       
   179     list  := list scrolledView.
       
   180     list ignoreDirectories:true.
       
   181     list pattern:(field editValue).
       
   182 
       
   183     tree itemClass:(FileSelectionItem directoriesOnly).
       
   184     tree directory:(Filename homeDirectory).
       
   185     tree showDirectoryIndicator:true.
       
   186     list directory:(tree directory).
       
   187 
       
   188     list action:[:index| Transcript showCR:'you selected: ' , list selectedPathname].
       
   189     tree action:[:anIndex|
       
   190         list directory:(tree selectedPathname).
   157     ].
   191     ].
   158     top open
   192     top open
   159                                                                         [exEnd]
   193                                                                         [exEnd]
   160 
   194 
   161 
   195 
   244 directory:aPathname
   278 directory:aPathname
   245     "change the root directory of the selection tree to the full pathName,
   279     "change the root directory of the selection tree to the full pathName,
   246      aPathname. The pathname must be a directory otherwise the root directory
   280      aPathname. The pathname must be a directory otherwise the root directory
   247      is set to nil.
   281      is set to nil.
   248     "
   282     "
   249     |root|
   283     |root dir path keep|
   250 
   284 
       
   285     (aPathname notNil and:[(path := aPathname asFilename) isDirectory]) ifFalse:[
       
   286         model root:nil.
       
   287       ^ self selection:nil
       
   288     ].
       
   289 
       
   290     (dir := self directory) notNil ifTrue:[
       
   291         dir  := dir asFilename.
       
   292         keep := path pathName = dir directory pathName.
       
   293     ] ifFalse:[
       
   294         keep := false
       
   295     ].
   251     self selection:nil.
   296     self selection:nil.
   252 
   297 
   253     (aPathname notNil and:[aPathname asFilename isDirectory]) ifFalse:[
   298     root := self itemClass pathName:path.
   254         model root:nil.
   299     model root:root keepRoot:keep.
   255         ^ self
       
   256     ].
       
   257 
       
   258     root := self itemClass pathName:aPathname.
       
   259     model root:root.
       
   260     model expand:root.
   300     model expand:root.
       
   301 
       
   302     keep ifTrue:[
       
   303         self selectPathname:(dir pathName)
       
   304     ].
       
   305 
   261 !
   306 !
   262 
   307 
   263 itemClass
   308 itemClass
   264     "returns current itemClass used
   309     "returns current itemClass used
   265     "
   310     "
   278         (directory := self directory) notNil ifTrue:[
   323         (directory := self directory) notNil ifTrue:[
   279             self directory:directory
   324             self directory:directory
   280         ].
   325         ].
   281     ].
   326     ].
   282 
   327 
       
   328 !
       
   329 
       
   330 pathnameAtIndex:anIndex
       
   331     "returns pathname at an index or nil
       
   332     "
       
   333     |node|
       
   334 
       
   335     (node := self nodeAtIndex:anIndex) notNil ifTrue:[
       
   336         ^ node pathName
       
   337     ].
       
   338   ^ nil
   283 ! !
   339 ! !
   284 
   340 
   285 !FileSelectionTree methodsFor:'drawing basics'!
   341 !FileSelectionTree methodsFor:'drawing basics'!
   286 
   342 
   287 figureFor:aNode
   343 figureFor:aNode
   326     itemClass := FileSelectionItem.
   382     itemClass := FileSelectionItem.
   327     self model:(SelectionInTree new).
   383     self model:(SelectionInTree new).
   328 
   384 
   329 ! !
   385 ! !
   330 
   386 
   331 !FileSelectionTree methodsFor:'queries'!
       
   332 
       
   333 canSelect:aFilename
       
   334     "returns true if a file is selectable dependant on
       
   335      filter ...
       
   336     "
       
   337     |root|
       
   338 
       
   339     (itemClass isSelectableFile:aFilename) ifTrue:[
       
   340         (root := self directory) notNil ifTrue:[
       
   341             ^ aFilename asString startsWith:root
       
   342         ]
       
   343     ].
       
   344   ^ false
       
   345 ! !
       
   346 
       
   347 !FileSelectionTree methodsFor:'selection'!
   387 !FileSelectionTree methodsFor:'selection'!
   348 
   388 
   349 selectPathname:aPath
   389 selectPathname:aPath
   350     "set selection to a path
   390     "set selection to a path
   351     "
   391     "
   352     |node comp rdwNd path|
   392     |node comp rdwNd path|
   353 
   393 
   354     (self canSelect:aPath) ifFalse:[
   394     (aPath notNil and:[aPath asFilename exists]) ifFalse:[
   355         ^ self selection:nil
   395         ^ self selection:nil
   356     ].
   396     ].
   357     ((path := aPath asString) = self selectedPathname) ifTrue:[
   397     ((path := aPath asString) = self selectedPathname) ifTrue:[
   358         "/ already selected
   398         "/ already selected
   359         ^ self
   399         ^ self
   400 ! !
   440 ! !
   401 
   441 
   402 !FileSelectionTree class methodsFor:'documentation'!
   442 !FileSelectionTree class methodsFor:'documentation'!
   403 
   443 
   404 version
   444 version
   405     ^ '$Header: /cvs/stx/stx/libwidg2/FileSelectionTree.st,v 1.2 1997-08-07 13:28:47 cg Exp $'
   445     ^ '$Header: /cvs/stx/stx/libwidg2/FileSelectionTree.st,v 1.3 1997-08-11 11:02:30 ca Exp $'
   406 ! !
   446 ! !