diff -r e878bd3b227e -r ecf956d44135 FileSelectionList.st --- a/FileSelectionList.st Mon Mar 04 23:32:09 1996 +0100 +++ b/FileSelectionList.st Tue Mar 05 01:08:59 1996 +0100 @@ -14,7 +14,7 @@ instanceVariableNames:'pattern directory timeStamp directoryId directoryName directoryContents directoryFileTypes fileTypes realAction matchBlock stayInDirectory ignoreParentDirectory markDirectories - ignoreDirectories directoryChangeCheckBlock' + ignoreDirectories directoryChangeCheckBlock quickDirectoryChange' classVariableNames:'' poolDictionaries:'' category:'Views-Text' @@ -51,20 +51,48 @@ exclusively used with FileSelectionBoxes (see examples there). Instance variables: - pattern the matchpattern + 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 + + directoryName the path when it was taken - directory the current directory + 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 - timeStamp the time, when directoryContents was last taken - directoryId the directories id (inode-nr) when it was taken - directoryName the path when it was taken - 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. + quickDirectoryChange if true, directories can be changed with a single click + if false (the default), they need a double click. + Makes sense if a directory is what we are interrested in, + for files its better to leave it as false. + + stayInDirectory if true, no directoryChanges are allowed. + Makes sense to limit the user to choose among certain files. + The default is false. - realAction (internal) the action to perform when a file is selected + ignoreParentDirectory if true, the parent directory is not shown. + Makes sense to limit the user to files below the initial + directory. Default is false. + + ignoreDirectories if true, no directories are shown at all. + Makes sense to limit the user to choose among regular files. + Default is false. + + directoryChangeCheckBlock + if nonNil, directoryChanges are only allowed if this block + returns true. It is evaluated with one argument, the pathName. + Defaults to nil (i.e. no checks). " ! @@ -289,7 +317,7 @@ " ! ! -!FileSelectionList methodsFor:'accessing'! +!FileSelectionList methodsFor:'accessing-behavior'! action:aBlock "set the action to be performed on a selection" @@ -297,41 +325,6 @@ realAction := aBlock ! -directory - "return the shown directory" - - ^ directory -! - -directory:nameOrDirectory - "set the lists contents to the filenames in the directory. - This does not validate the change with any directoryChangeBlock." - - |oldPath name| - - nameOrDirectory isString ifTrue:[ - name := nameOrDirectory - ] ifFalse:[ - nameOrDirectory isNil ifTrue:[ - directory := nil. - ^ self updateList - ]. - name := nameOrDirectory pathName - ]. - directory isNil ifTrue:[ - directory := FileDirectory new. - oldPath := nil - ] ifFalse:[ - oldPath := directory pathName. - ]. - directory pathName:name. - realized ifTrue:[ - (directory pathName = oldPath) ifFalse:[ - self updateList - ] - ] -! - directoryChangeCheckBlock:aBlock "set the directoryChangeCheckBlock - if non-nil, it controls if a directory change is legal." @@ -378,6 +371,61 @@ ]. ! +quickDirectoryChange:aBoolean + "set/clear quick change (i.e. chdir with single click). + The default is false (i.e. double click is required)" + + quickDirectoryChange := aBoolean + + "Created: 4.3.1996 / 17:37:58 / cg" +! + +stayInDirectory:aBoolean + "set/clear the flag which controls if selecting a directory + should locally change (if false) or be handled just like + the selection of a file (if true). + The default is false (i.e. change and do not tell via action)" + + stayInDirectory := aBoolean +! ! + +!FileSelectionList methodsFor:'accessing-contents'! + +directory + "return the shown directory" + + ^ directory +! + +directory:nameOrDirectory + "set the lists contents to the filenames in the directory. + This does not validate the change with any directoryChangeBlock." + + |oldPath name| + + nameOrDirectory isString ifTrue:[ + name := nameOrDirectory + ] ifFalse:[ + nameOrDirectory isNil ifTrue:[ + directory := nil. + ^ self updateList + ]. + name := nameOrDirectory pathName + ]. + directory isNil ifTrue:[ + directory := FileDirectory new. + oldPath := nil + ] ifFalse:[ + oldPath := directory pathName. + ]. + directory pathName:name. + realized ifTrue:[ + (directory pathName = oldPath) ifFalse:[ + self updateList + ] + ] +! + selectedPathname "if there is a selection, return its full pathname. Of there is no selection, return nil." @@ -388,15 +436,6 @@ sel isNil ifTrue:[^ nil]. ^ directory pathName , Filename separator asString , sel. -! - -stayInDirectory:aBoolean - "set/clear the flag which controls if selecting a directory - should locally change (if false) or be handled just like - the selection of a file (if true). - The default is false (i.e. change and do not tell via action)" - - stayInDirectory := aBoolean ! ! !FileSelectionList methodsFor:'drawing'! @@ -439,6 +478,40 @@ !FileSelectionList methodsFor:'events'! +doubleClicked + self selectionIsDirectory ifTrue:[ + stayInDirectory not ifTrue:[ + quickDirectoryChange ifFalse:[ + self changeDirectory + ] + ]. + ^ self + ]. + super doubleClicked + + "Created: 4.3.1996 / 17:39:58 / cg" + "Modified: 4.3.1996 / 17:50:11 / cg" +! + +selectionChanged + "if the selection changed, check for it being a directory + and possibly go there. If its not a directory, perform the realAction." + + self selection isCollection ifFalse:[ + self selectionIsDirectory ifTrue:[ + (stayInDirectory not and:[quickDirectoryChange]) ifTrue:[ + self changeDirectory + ] + ] ifFalse:[ + realAction notNil ifTrue:[ + realAction value:self selection + ] + ] + ] + + "Modified: 4.3.1996 / 17:44:44 / cg" +! + sizeChanged:how "redraw marks if any" @@ -453,6 +526,7 @@ initialize directory := FileDirectory currentDirectory. stayInDirectory := ignoreParentDirectory := ignoreDirectories := false. + quickDirectoryChange := false. markDirectories := true. super initialize. @@ -466,6 +540,8 @@ (ScrollableView for:FileSelectionList) open (HVScrollableView for:FileSelectionList) open " + + "Modified: 4.3.1996 / 17:36:29 / cg" ! initializeAction @@ -473,6 +549,9 @@ a directory; otherwise directory is changed" actionBlock := [:lineNr | self selectionChanged]. +"/ doubleClickActionBlock := [:lineNr | self selectionChanged]. + + "Modified: 4.3.1996 / 17:39:08 / cg" ! reinitialize @@ -482,48 +561,63 @@ !FileSelectionList methodsFor:'private'! -selectionChanged - "if the selection changed, check for it being a directory - and possibly go there. If its not a directory, perform the realAction." +changeDirectory + "change directory to the selected one" - |entry ok newDir warnMessage| + |entry ok newDir warnMessage oldDir| + + entry := self selectionValue. + (entry isNil or:[entry isEmpty]) ifTrue:[ ^ false]. - self selection isCollection ifFalse:[ - entry := self selectionValue. - (entry endsWith:' ...') ifTrue:[ - entry := entry copyWithoutLast:4. - ]. - (stayInDirectory not - and:[(directory typeOf:entry) == #directory]) ifTrue:[ - ok := false. - newDir := directory pathName , Filename separator asString , entry. + (entry endsWith:' ...') ifTrue:[ + entry := entry copyWithoutLast:4. + ]. + + ok := false. + oldDir := directory pathName asFilename baseName. + + newDir := directory pathName , Filename separator asString , entry. - (directoryChangeCheckBlock isNil - or:[directoryChangeCheckBlock value:newDir]) ifTrue:[ - (directory isReadable:entry) ifFalse:[ - warnMessage := 'not allowed to read directory %1' - ] ifTrue:[ - (directory isExecutable:entry) ifFalse:[ - warnMessage := 'not allowed to change to directory %1' - ] ifTrue:[ - ok := true. - ] - ]. - ]. - ok ifFalse:[ - warnMessage notNil ifTrue:[ - self warn:(resources string:warnMessage with:entry). - ]. - self deselect - ] ifTrue:[ - self directory:newDir. - ]. - ] ifFalse:[ - realAction notNil ifTrue:[ - realAction value:self selection - ] - ] - ] + (directoryChangeCheckBlock isNil + or:[directoryChangeCheckBlock value:newDir]) ifTrue:[ + (directory isReadable:entry) ifFalse:[ + warnMessage := 'not allowed to read directory %1' + ] ifTrue:[ + (directory isExecutable:entry) ifFalse:[ + warnMessage := 'not allowed to change to directory %1' + ] ifTrue:[ + ok := true. + ] + ]. + ]. + ok ifFalse:[ + warnMessage notNil ifTrue:[ + self warn:(resources string:warnMessage with:entry). + ]. + self deselect + ] ifTrue:[ + self directory:newDir. + entry = '..' ifTrue:[ + self selectElement:oldDir + ]. + ]. + + "Created: 4.3.1996 / 17:45:18 / cg" + "Modified: 4.3.1996 / 18:10:17 / cg" +! + +selectionIsDirectory + |entry| + + entry := self selectionValue. + (entry isNil or:[entry isEmpty]) ifTrue:[ ^ false]. + + (entry endsWith:' ...') ifTrue:[ + entry := entry copyWithoutLast:4. + ]. + ^ (directory typeOf:entry) == #directory + + "Created: 4.3.1996 / 17:43:26 / cg" ! updateList @@ -651,5 +745,5 @@ !FileSelectionList class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libwidg/FileSelectionList.st,v 1.24 1996-02-10 09:32:49 ca Exp $' + ^ '$Header: /cvs/stx/stx/libwidg/FileSelectionList.st,v 1.25 1996-03-05 00:08:59 cg Exp $' ! !