--- a/FSelList.st Tue Aug 30 00:54:47 1994 +0200
+++ b/FSelList.st Mon Oct 10 04:03:47 1994 +0100
@@ -23,7 +23,7 @@
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libwidg/Attic/FSelList.st,v 1.7 1994-08-24 01:45:21 claus Exp $
+$Header: /cvs/stx/stx/libwidg/Attic/FSelList.st,v 1.8 1994-10-10 03:01:30 claus Exp $
'!
!FileSelectionList class methodsFor:'documentation'!
@@ -44,7 +44,7 @@
version
"
-$Header: /cvs/stx/stx/libwidg/Attic/FSelList.st,v 1.7 1994-08-24 01:45:21 claus Exp $
+$Header: /cvs/stx/stx/libwidg/Attic/FSelList.st,v 1.8 1994-10-10 03:01:30 claus Exp $
"
!
@@ -53,22 +53,168 @@
this class implements file selection lists - its basically a
selection in list, but adds some right-arrows to directories.
(and will soon remember the previous position when changing directories).
- Only files matching a pattern (plus directories) are shown.
+ You can specify an optional filename-pattern (such as '*.st') and an
+ optional matchBlock (such as: [:name | name startsWith:'A']).
+
+ Only files (plus directories) matching the pattern (if present) and
+ for which the matchBlock returns true (if present), are shown.
Instance variables:
pattern the matchpattern
+
directory the current directory
+
timeStamp the time, when directoryContents was last taken
directoryId the directories id (inode-nr) when it was taken
- directoryContents contents of current directory
- directoryFileTypes file types (symbols) of current directory
- fileTypes file types as shown in list
- (i.e only matching ones)
- realAction the action to perform when a file is selected
+ directoryContents (cached) contents of current directory
+ directoryFileTypes (cached) file types (symbols) of current directory
+ fileTypes file types as shown in list (i.e only matching ones)
+ matchBlock if non-nil: block evaluated per full filename;
+ only files for which matchBlock returns true are shown.
+
+ realAction (internal) the action to perform when a file is selected
Example use:
FileSelectionLists are typically used in FileSelectionBoxes,
or file-browser-like applications.
+ Thus, the following examples are a bit untypical.
+
+ example1 (plain file-list):
+ |list|
+
+ list := FileSelectionList new.
+ list open
+
+ example2 (scrolled & some action):
+ |top v list|
+
+ top := StandardSystemView new.
+ top extent:(300 @ 200).
+ v := ScrollableView for:FileSelectionList in:top.
+ v origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ list := v scrolledView.
+ list action:[:index | Transcript showCr:'you selected: ' , list selectionValue].
+ top open
+
+ example3 (adds a pattern):
+ |top v list|
+
+ top := StandardSystemView new.
+ top extent:(300 @ 200).
+ v := ScrollableView for:FileSelectionList in:top.
+ v origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ list := v scrolledView.
+ list pattern:'*.st'.
+ list action:[:index | Transcript showCr:'you selected: ' , list selectionValue].
+ top open
+
+ example4 (a more complicated pattern):
+ |top v list|
+
+ top := StandardSystemView new.
+ top extent:(300 @ 200).
+ v := ScrollableView for:FileSelectionList in:top.
+ v origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ list := v scrolledView.
+ list pattern:'[A-D]*.st'.
+ list action:[:index | Transcript showCr:'you selected: ' , list selectionValue].
+ top open
+
+ example5 (adds a matchblock to show only writable files):
+ |top v list|
+
+ top := StandardSystemView new.
+ top extent:(300 @ 200).
+ v := ScrollableView for:FileSelectionList in:top.
+ v origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ list := v scrolledView.
+ list matchBlock:[:name |
+ |fileName|
+ fileName := name asFilename.
+ fileName isWritable or:[fileName isDirectory]
+ ].
+ list action:[:index | Transcript showCr:'you selected: ' , list selectionValue].
+ top open
+
+ example6 (adds a matchblock to suppress directories):
+ |top v list|
+
+ top := StandardSystemView new.
+ top extent:(300 @ 200).
+ v := ScrollableView for:FileSelectionList in:top.
+ v origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ list := v scrolledView.
+ list matchBlock:[:name |
+ name asFilename isDirectory not
+ ].
+ list action:[:index | Transcript showCr:'you selected: ' , list selectionValue].
+ top open
+
+ example7 (adds a matchblock to block moving up (i.e. only allow files here & below):
+ |top v list currentDir|
+
+ currentDir := '.' asFilename pathName.
+
+ top := StandardSystemView new.
+ top extent:(300 @ 200).
+ v := ScrollableView for:FileSelectionList in:top.
+ v origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ list := v scrolledView.
+ list matchBlock:[:name |
+ ((name endsWith:'/..') and:[list directory pathName = currentDir]) not
+ ].
+ list action:[:index | Transcript showCr:'you selected: ' , list selectionValue].
+ top open
+
+ example8 (block moving up AND show all .rc-files only):
+ |top v list currentDir|
+
+ currentDir := '.' asFilename pathName.
+
+ top := StandardSystemView new.
+ top extent:(300 @ 200).
+ v := ScrollableView for:FileSelectionList in:top.
+ v origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ list := v scrolledView.
+ list pattern:'*.rc'.
+ list matchBlock:[:name |
+ ((name endsWith:'/..') and:[list directory pathName = currentDir]) not
+ ].
+ list action:[:index | Transcript showCr:'you selected: ' , list selectionValue].
+ top open
+
+ example9 (show only .rc-files in current directory):
+ |top v list currentDir|
+
+ currentDir := '.' asFilename pathName.
+
+ top := StandardSystemView new.
+ top extent:(300 @ 200).
+ v := ScrollableView for:FileSelectionList in:top.
+ v origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ list := v scrolledView.
+ list pattern:'*.rc'.
+ list matchBlock:[:name |
+ name asFilename isDirectory not
+ ].
+ list action:[:index | Transcript showCr:'you selected: ' , list selectionValue].
+ top open
+
+ example10 (show only .rc-files in /etc; dont allow directory changes):
+ |top v list|
+
+ top := StandardSystemView new.
+ top extent:(300 @ 200).
+ v := ScrollableView for:FileSelectionList in:top.
+ v origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ list := v scrolledView.
+ list directory:'/etc'.
+ list pattern:'*.rc'.
+ list matchBlock:[:name | name printNL.
+ name asFilename isDirectory not
+ ].
+ list action:[:index | Transcript showCr:'you selected: ' , list selectionValue].
+ top open
"
! !
@@ -158,8 +304,10 @@
].
oldPath := directory pathName.
directory pathName:name.
- (directory pathName = oldPath) ifFalse:[
- self updateList
+ realized ifTrue:[
+ (directory pathName = oldPath) ifFalse:[
+ self updateList
+ ]
]
!
@@ -262,7 +410,11 @@
fileTypes := OrderedCollection new.
index := 1.
files do:[:name |
- (matchBlock isNil or:[matchBlock value:name]) ifTrue:[
+ |fullName|
+
+ fullName := directory pathName , Filename separator asString , name.
+
+ (matchBlock isNil or:[matchBlock value:fullName]) ifTrue:[
(directoryFileTypes at:index) == #directory ifTrue:[
name = '..' ifTrue:[
newList add:name.