--- a/FSelBox.st Sat Feb 10 10:32:49 1996 +0100
+++ b/FSelBox.st Sat Feb 10 10:36:47 1996 +0100
@@ -11,10 +11,10 @@
"
ListSelectionBox subclass:#FileSelectionBox
- instanceVariableNames:'patternField'
- classVariableNames:''
- poolDictionaries:''
- category:'Views-DialogBoxes'
+ instanceVariableNames:'patternField selectingDirectory'
+ classVariableNames:''
+ poolDictionaries:''
+ category:'Views-DialogBoxes'
!
!FileSelectionBox class methodsFor:'documentation'!
@@ -68,24 +68,24 @@
simple standard queries
very simple:
- |name|
+ |name|
- name := FileSelectionBox requestFilename.
- Transcript showCr:name
+ name := FileSelectionBox requestFilename.
+ Transcript showCr:name
simple:
- |name|
+ |name|
- name := FileSelectionBox requestFilename:'which file ?'.
- Transcript showCr:name
+ name := FileSelectionBox requestFilename:'which file ?'.
+ Transcript showCr:name
with initial selection:
- |name|
+ |name|
- name := FileSelectionBox requestFilename:'which file ?' default:'Make.proto'.
- Transcript showCr:name
+ name := FileSelectionBox requestFilename:'which file ?' default:'Make.proto'.
+ Transcript showCr:name
@@ -93,137 +93,148 @@
setting title:
- |box|
- box := FileSelectionBox new.
- box title:'Which file ?'.
- box open.
- box accepted ifTrue:[
- Transcript showCr:'you selected: ' , box
- ]
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which file ?'.
+ box open.
+ box accepted ifTrue:[
+ Transcript showCr:'you selected: ' , box
+ ]
setting a matchpattern:
- |box|
- box := FileSelectionBox new.
- box title:'Which file ?'.
- box pattern:'*.rc'.
- box open
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which file ?'.
+ box pattern:'*.rc'.
+ box open
+
+ setting multiple patterns:
+
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which file ?'.
+ box pattern:'*.rc;*.st'.
+ box open
setting a matchblock:
- |box|
- box := FileSelectionBox new.
- box title:'Which file ?'.
- box pattern:'*'.
- box matchBlock:[:name | name first isLowercase].
- box open
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which file ?'.
+ box directory:'/etc'.
+ box pattern:'*'.
+ box matchBlock:[:name | name asFilename baseName first between:$a and:$z].
+ box open
both pattern and matchBlock:
- |box|
- box := FileSelectionBox new.
- box title:'Which directory ?'.
- box pattern:'l*'.
- box matchBlock:[:name | OperatingSystem isDirectory:name].
- box open
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which directory ?'.
+ box selectingDirectory:true.
+ box pattern:'l*'.
+ box matchBlock:[:name | OperatingSystem isDirectory:name].
+ box action:[:fn | Transcript showCr:fn].
+ box open
dont show the parent directory:
- |box|
- box := FileSelectionBox new.
- box title:'Which directory ?'.
- box listView ignoreParentDirectory:true.
- box open
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which directory ?'.
+ box listView ignoreParentDirectory:true.
+ box open
dont show any directory:
- |box|
- box := FileSelectionBox new.
- box title:'Which file ?'.
- box listView ignoreDirectories:true.
- box open
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which file ?'.
+ box listView ignoreDirectories:true.
+ box open
dont show any directory or hidden file:
(notice the basename extraction - we are not interrested in the full pathName)
- |box|
- box := FileSelectionBox new.
- box title:'Which file ?'.
- box listView ignoreDirectories:true.
- box matchBlock:[:name | (name asFilename baseName startsWith:'.') not].
- box open
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which file ?'.
+ box listView ignoreDirectories:true.
+ box matchBlock:[:name | (name asFilename baseName startsWith:'.') not].
+ box open
dont allow direct filename entry:
(i.e. avoid the user choosing files from other directories)
- |box|
- box := FileSelectionBox new.
- box title:'Which one ?'.
- box enterField beInvisible.
- box open.
- box accepted ifTrue:[
- Transcript showCr:'path is ' , box pathName
- ].
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which one ?'.
+ box enterField beInvisible.
+ box open.
+ box accepted ifTrue:[
+ Transcript showCr:'path is ' , box pathName
+ ].
combined with above directory ignoring,
this limits selection of files from a single directory:
- |box|
- box := FileSelectionBox new.
- box title:'Which file ?'.
- box enterField beInvisible.
- box listView ignoreDirectories:true.
- box open.
- box accepted ifTrue:[
- Transcript showCr:'path is ' , box pathName
- ].
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which file ?'.
+ box enterField beInvisible.
+ box listView ignoreDirectories:true.
+ box open.
+ box accepted ifTrue:[
+ Transcript showCr:'path is ' , box pathName
+ ].
finally, an action:
- |box|
- box := FileSelectionBox new.
- box title:'Which directory ?'.
- box pattern:'l*'.
- box matchBlock:[:name | OperatingSystem isDirectory:name].
- box action:[:name | Transcript showCr:name].
- box open
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which directory ?'.
+ box pattern:'l*'.
+ box matchBlock:[:name | OperatingSystem isDirectory:name].
+ box action:[:name | Transcript showCr:name].
+ box open
concrete examples:
only show files beginning with lowercase characters
and ending in '.c':
- |box|
- box := FileSelectionBox new.
- box title:'Which directory ?'.
- box matchBlock:[:name |
- box pathName asFilename isDirectory
- or:[name first isLowercase
- and:[name endsWith:'.c']]
- ].
- box open.
- box accepted ifTrue:[
- Transcript showCr:'full path: ' , box pathName.
- Transcript showCr:'files name: ' , box fileName.
- Transcript showCr:'directory : ' , box directory.
- ]
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which directory ?'.
+ box matchBlock:[:name |
+ box pathName asFilename isDirectory
+ or:[name first isLowercase
+ and:[name endsWith:'.c']]
+ ].
+ box open.
+ box accepted ifTrue:[
+ Transcript showCr:'full path: ' , box pathName.
+ Transcript showCr:'files name: ' , box fileName.
+ Transcript showCr:'directory : ' , box directory.
+ ]
somewhat wierd example:
only show files, if the directory we are in begins with 'lib':
- |box|
- box := FileSelectionBox new.
- box title:'Which directory ?'.
- box pattern:'l*'.
- box matchBlock:[:name |
- box directory asString beginsWith:'lib'
- ].
- box open
- box accepted ifTrue:[
- Transcript showCr:'full path: ' , box pathName.
- Transcript showCr:'files name: ' , box fileName.
- Transcript showCr:'directory : ' , box directory.
- ]
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which directory ?'.
+ box pattern:'l*'.
+ box matchBlock:[:name |
+ box directory asString beginsWith:'lib'
+ ].
+ box open
+ box accepted ifTrue:[
+ Transcript showCr:'full path: ' , box pathName.
+ Transcript showCr:'files name: ' , box fileName.
+ Transcript showCr:'directory : ' , box directory.
+ ]
"
! !
@@ -304,24 +315,6 @@
!FileSelectionBox methodsFor:'accessing'!
-pathName
- "same as contents - return the full pathname of the selected file,
- or the pathname of the directory if nothing has been entered"
-
- ^ self contents
-!
-
-fileName
- "if some filename has been entered, return it (without the directory path)
- otherwise, return nil"
-
- |string|
-
- string := super contents.
- string isNil ifTrue:[^ nil].
- ^ self pathName
-!
-
contents
"return the current entered value (i.e. the enterFields string).
redefined to return the full pathname."
@@ -351,6 +344,17 @@
selectionList directory:directoryName
!
+fileName
+ "if some filename has been entered, return it (without the directory path)
+ otherwise, return nil"
+
+ |string|
+
+ string := super contents.
+ string isNil ifTrue:[^ nil].
+ ^ self pathName
+!
+
matchBlock:aBlock
"set the matchBlock (in the selectionList). Only files
for which the block returns true are shown.
@@ -367,6 +371,13 @@
self showAtPointer
!
+pathName
+ "same as contents - return the full pathname of the selected file,
+ or the pathname of the directory if nothing has been entered"
+
+ ^ self contents
+!
+
pattern:aPattern
"set the pattern - this also enables the PatternField
(if the pattern is non-nil) or hides it (if nil)."
@@ -402,6 +413,10 @@
windowGroup notNil ifTrue:[
windowGroup focusSequence:focusSequence
].
+!
+
+selectingDirectory:aBoolean
+ selectingDirectory := aBoolean
! !
!FileSelectionBox methodsFor:'change & update'!
@@ -458,6 +473,7 @@
|corner|
super initialize.
+ selectingDirectory := false.
label := resources string:'File dialog'.
@@ -467,16 +483,16 @@
patternField := EditField in:self.
self is3D ifTrue:[
- corner := (1.0 @ (labelField origin y+patternField heightIncludingBorder)).
+ corner := (1.0 @ (labelField origin y+patternField heightIncludingBorder)).
] ifFalse:[
- corner := [(width - ViewSpacing - (patternField borderWidth * 2)) @ (labelField origin y+patternField height"IncludingBorder")].
+ corner := [(width - ViewSpacing - (patternField borderWidth * 2)) @ (labelField origin y+patternField height"IncludingBorder")].
].
patternField origin:(0.7 @ labelField origin y) corner:corner.
patternField rightInset:ViewSpacing.
patternField initialText:'*'.
patternField leaveAction:[:reason |
- selectionList pattern:patternField contents.
- self updateList
+ selectionList pattern:patternField contents.
+ self updateList
].
patternField hiddenOnRealize:true. "delay showing, until a pattern is defined"
@@ -556,21 +572,29 @@
|dir string fname|
string := enterField contents.
- string notNil ifTrue:[
- string := string withoutSeparators.
- string asFilename isAbsolute ifTrue:[
- fname := string asFilename
- ] ifFalse:[
- dir := selectionList directory pathName asFilename.
- fname := dir construct:string
- ].
- fname isDirectory ifTrue:[
- selectionList directory:fname asString.
- self updateList.
- ^ self
- ]
+ (string notNil and:[string notEmpty]) ifTrue:[
+ string := string withoutSeparators.
+ string asFilename isAbsolute ifTrue:[
+ fname := string asFilename
+ ] ifFalse:[
+ dir := selectionList directory pathName asFilename.
+ fname := dir construct:string
+ ].
+ fname isDirectory ifTrue:[
+ selectingDirectory ifFalse:[
+ selectionList directory:fname asString.
+ self updateList.
+ ^ self
+ ]
+ ]
+ ] ifFalse:[
+ selectingDirectory ifTrue:[
+ enterField contents:(selectionList directory pathName).
+ ].
].
+
super okPressed
+
!
selectionChanged
@@ -583,5 +607,5 @@
!FileSelectionBox class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg/Attic/FSelBox.st,v 1.27 1996-01-18 21:28:46 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg/Attic/FSelBox.st,v 1.28 1996-02-10 09:36:47 ca Exp $'
! !
--- a/FileSelectionBox.st Sat Feb 10 10:32:49 1996 +0100
+++ b/FileSelectionBox.st Sat Feb 10 10:36:47 1996 +0100
@@ -11,10 +11,10 @@
"
ListSelectionBox subclass:#FileSelectionBox
- instanceVariableNames:'patternField'
- classVariableNames:''
- poolDictionaries:''
- category:'Views-DialogBoxes'
+ instanceVariableNames:'patternField selectingDirectory'
+ classVariableNames:''
+ poolDictionaries:''
+ category:'Views-DialogBoxes'
!
!FileSelectionBox class methodsFor:'documentation'!
@@ -68,24 +68,24 @@
simple standard queries
very simple:
- |name|
+ |name|
- name := FileSelectionBox requestFilename.
- Transcript showCr:name
+ name := FileSelectionBox requestFilename.
+ Transcript showCr:name
simple:
- |name|
+ |name|
- name := FileSelectionBox requestFilename:'which file ?'.
- Transcript showCr:name
+ name := FileSelectionBox requestFilename:'which file ?'.
+ Transcript showCr:name
with initial selection:
- |name|
+ |name|
- name := FileSelectionBox requestFilename:'which file ?' default:'Make.proto'.
- Transcript showCr:name
+ name := FileSelectionBox requestFilename:'which file ?' default:'Make.proto'.
+ Transcript showCr:name
@@ -93,137 +93,148 @@
setting title:
- |box|
- box := FileSelectionBox new.
- box title:'Which file ?'.
- box open.
- box accepted ifTrue:[
- Transcript showCr:'you selected: ' , box
- ]
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which file ?'.
+ box open.
+ box accepted ifTrue:[
+ Transcript showCr:'you selected: ' , box
+ ]
setting a matchpattern:
- |box|
- box := FileSelectionBox new.
- box title:'Which file ?'.
- box pattern:'*.rc'.
- box open
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which file ?'.
+ box pattern:'*.rc'.
+ box open
+
+ setting multiple patterns:
+
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which file ?'.
+ box pattern:'*.rc;*.st'.
+ box open
setting a matchblock:
- |box|
- box := FileSelectionBox new.
- box title:'Which file ?'.
- box pattern:'*'.
- box matchBlock:[:name | name first isLowercase].
- box open
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which file ?'.
+ box directory:'/etc'.
+ box pattern:'*'.
+ box matchBlock:[:name | name asFilename baseName first between:$a and:$z].
+ box open
both pattern and matchBlock:
- |box|
- box := FileSelectionBox new.
- box title:'Which directory ?'.
- box pattern:'l*'.
- box matchBlock:[:name | OperatingSystem isDirectory:name].
- box open
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which directory ?'.
+ box selectingDirectory:true.
+ box pattern:'l*'.
+ box matchBlock:[:name | OperatingSystem isDirectory:name].
+ box action:[:fn | Transcript showCr:fn].
+ box open
dont show the parent directory:
- |box|
- box := FileSelectionBox new.
- box title:'Which directory ?'.
- box listView ignoreParentDirectory:true.
- box open
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which directory ?'.
+ box listView ignoreParentDirectory:true.
+ box open
dont show any directory:
- |box|
- box := FileSelectionBox new.
- box title:'Which file ?'.
- box listView ignoreDirectories:true.
- box open
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which file ?'.
+ box listView ignoreDirectories:true.
+ box open
dont show any directory or hidden file:
(notice the basename extraction - we are not interrested in the full pathName)
- |box|
- box := FileSelectionBox new.
- box title:'Which file ?'.
- box listView ignoreDirectories:true.
- box matchBlock:[:name | (name asFilename baseName startsWith:'.') not].
- box open
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which file ?'.
+ box listView ignoreDirectories:true.
+ box matchBlock:[:name | (name asFilename baseName startsWith:'.') not].
+ box open
dont allow direct filename entry:
(i.e. avoid the user choosing files from other directories)
- |box|
- box := FileSelectionBox new.
- box title:'Which one ?'.
- box enterField beInvisible.
- box open.
- box accepted ifTrue:[
- Transcript showCr:'path is ' , box pathName
- ].
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which one ?'.
+ box enterField beInvisible.
+ box open.
+ box accepted ifTrue:[
+ Transcript showCr:'path is ' , box pathName
+ ].
combined with above directory ignoring,
this limits selection of files from a single directory:
- |box|
- box := FileSelectionBox new.
- box title:'Which file ?'.
- box enterField beInvisible.
- box listView ignoreDirectories:true.
- box open.
- box accepted ifTrue:[
- Transcript showCr:'path is ' , box pathName
- ].
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which file ?'.
+ box enterField beInvisible.
+ box listView ignoreDirectories:true.
+ box open.
+ box accepted ifTrue:[
+ Transcript showCr:'path is ' , box pathName
+ ].
finally, an action:
- |box|
- box := FileSelectionBox new.
- box title:'Which directory ?'.
- box pattern:'l*'.
- box matchBlock:[:name | OperatingSystem isDirectory:name].
- box action:[:name | Transcript showCr:name].
- box open
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which directory ?'.
+ box pattern:'l*'.
+ box matchBlock:[:name | OperatingSystem isDirectory:name].
+ box action:[:name | Transcript showCr:name].
+ box open
concrete examples:
only show files beginning with lowercase characters
and ending in '.c':
- |box|
- box := FileSelectionBox new.
- box title:'Which directory ?'.
- box matchBlock:[:name |
- box pathName asFilename isDirectory
- or:[name first isLowercase
- and:[name endsWith:'.c']]
- ].
- box open.
- box accepted ifTrue:[
- Transcript showCr:'full path: ' , box pathName.
- Transcript showCr:'files name: ' , box fileName.
- Transcript showCr:'directory : ' , box directory.
- ]
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which directory ?'.
+ box matchBlock:[:name |
+ box pathName asFilename isDirectory
+ or:[name first isLowercase
+ and:[name endsWith:'.c']]
+ ].
+ box open.
+ box accepted ifTrue:[
+ Transcript showCr:'full path: ' , box pathName.
+ Transcript showCr:'files name: ' , box fileName.
+ Transcript showCr:'directory : ' , box directory.
+ ]
somewhat wierd example:
only show files, if the directory we are in begins with 'lib':
- |box|
- box := FileSelectionBox new.
- box title:'Which directory ?'.
- box pattern:'l*'.
- box matchBlock:[:name |
- box directory asString beginsWith:'lib'
- ].
- box open
- box accepted ifTrue:[
- Transcript showCr:'full path: ' , box pathName.
- Transcript showCr:'files name: ' , box fileName.
- Transcript showCr:'directory : ' , box directory.
- ]
+ |box|
+ box := FileSelectionBox new.
+ box title:'Which directory ?'.
+ box pattern:'l*'.
+ box matchBlock:[:name |
+ box directory asString beginsWith:'lib'
+ ].
+ box open
+ box accepted ifTrue:[
+ Transcript showCr:'full path: ' , box pathName.
+ Transcript showCr:'files name: ' , box fileName.
+ Transcript showCr:'directory : ' , box directory.
+ ]
"
! !
@@ -304,24 +315,6 @@
!FileSelectionBox methodsFor:'accessing'!
-pathName
- "same as contents - return the full pathname of the selected file,
- or the pathname of the directory if nothing has been entered"
-
- ^ self contents
-!
-
-fileName
- "if some filename has been entered, return it (without the directory path)
- otherwise, return nil"
-
- |string|
-
- string := super contents.
- string isNil ifTrue:[^ nil].
- ^ self pathName
-!
-
contents
"return the current entered value (i.e. the enterFields string).
redefined to return the full pathname."
@@ -351,6 +344,17 @@
selectionList directory:directoryName
!
+fileName
+ "if some filename has been entered, return it (without the directory path)
+ otherwise, return nil"
+
+ |string|
+
+ string := super contents.
+ string isNil ifTrue:[^ nil].
+ ^ self pathName
+!
+
matchBlock:aBlock
"set the matchBlock (in the selectionList). Only files
for which the block returns true are shown.
@@ -367,6 +371,13 @@
self showAtPointer
!
+pathName
+ "same as contents - return the full pathname of the selected file,
+ or the pathname of the directory if nothing has been entered"
+
+ ^ self contents
+!
+
pattern:aPattern
"set the pattern - this also enables the PatternField
(if the pattern is non-nil) or hides it (if nil)."
@@ -402,6 +413,10 @@
windowGroup notNil ifTrue:[
windowGroup focusSequence:focusSequence
].
+!
+
+selectingDirectory:aBoolean
+ selectingDirectory := aBoolean
! !
!FileSelectionBox methodsFor:'change & update'!
@@ -458,6 +473,7 @@
|corner|
super initialize.
+ selectingDirectory := false.
label := resources string:'File dialog'.
@@ -467,16 +483,16 @@
patternField := EditField in:self.
self is3D ifTrue:[
- corner := (1.0 @ (labelField origin y+patternField heightIncludingBorder)).
+ corner := (1.0 @ (labelField origin y+patternField heightIncludingBorder)).
] ifFalse:[
- corner := [(width - ViewSpacing - (patternField borderWidth * 2)) @ (labelField origin y+patternField height"IncludingBorder")].
+ corner := [(width - ViewSpacing - (patternField borderWidth * 2)) @ (labelField origin y+patternField height"IncludingBorder")].
].
patternField origin:(0.7 @ labelField origin y) corner:corner.
patternField rightInset:ViewSpacing.
patternField initialText:'*'.
patternField leaveAction:[:reason |
- selectionList pattern:patternField contents.
- self updateList
+ selectionList pattern:patternField contents.
+ self updateList
].
patternField hiddenOnRealize:true. "delay showing, until a pattern is defined"
@@ -556,21 +572,29 @@
|dir string fname|
string := enterField contents.
- string notNil ifTrue:[
- string := string withoutSeparators.
- string asFilename isAbsolute ifTrue:[
- fname := string asFilename
- ] ifFalse:[
- dir := selectionList directory pathName asFilename.
- fname := dir construct:string
- ].
- fname isDirectory ifTrue:[
- selectionList directory:fname asString.
- self updateList.
- ^ self
- ]
+ (string notNil and:[string notEmpty]) ifTrue:[
+ string := string withoutSeparators.
+ string asFilename isAbsolute ifTrue:[
+ fname := string asFilename
+ ] ifFalse:[
+ dir := selectionList directory pathName asFilename.
+ fname := dir construct:string
+ ].
+ fname isDirectory ifTrue:[
+ selectingDirectory ifFalse:[
+ selectionList directory:fname asString.
+ self updateList.
+ ^ self
+ ]
+ ]
+ ] ifFalse:[
+ selectingDirectory ifTrue:[
+ enterField contents:(selectionList directory pathName).
+ ].
].
+
super okPressed
+
!
selectionChanged
@@ -583,5 +607,5 @@
!FileSelectionBox class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.27 1996-01-18 21:28:46 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.28 1996-02-10 09:36:47 ca Exp $'
! !