diff -r b643875bda30 -r 6c9aaf7a84e7 FileSelectionList.st --- a/FileSelectionList.st Thu Apr 18 14:33:03 1996 +0200 +++ b/FileSelectionList.st Fri Apr 19 13:26:09 1996 +0200 @@ -15,7 +15,8 @@ directoryContents directoryFileTypes fileTypes realAction matchBlock stayInDirectory ignoreParentDirectory markDirectories ignoreDirectories directoryChangeCheckBlock quickDirectoryChange - directoryChangeAction' + directoryChangeAction directorySelectAction fileSelectAction + ignoreFiles' classVariableNames:'' poolDictionaries:'' category:'Views-Text' @@ -90,11 +91,24 @@ Makes sense to limit the user to choose among regular files. Default is false. + ignoreFiles if true, no regular files are shown at all. + Makes sense to limit the user to choose among directories 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). + directorySelectAction + if nonNil, a directory-select evaluate this block. + Possible hook for others (used with Boxes) + Defaults to nil. + + fileSelectAction + if nonNil, file-select evaluate this block. + Possible hook for others (used with Boxes) + Defaults to nil. " ! @@ -106,215 +120,324 @@ example (plain file-list): - |list| + |list| - list := FileSelectionList new. - list open + list := FileSelectionList new. + list open - example (scrolled & some action): + + scrolled & some action: - |top v list| + |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 + 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 ignore the parentDirectory: - |top v list| + |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 ignoreParentDirectory:true. - top open + 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 ignoreParentDirectory:true. + top open + + ignore all directories (i.e. regular files only): + + |top v list| - ignore all directories: + 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 ignoreDirectories:true. + top open - |top v list| + ignore all regular files (i.e. directories only): - 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 ignoreDirectories:true. - top open + |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 ignoreFiles:true. + top open dont show the directory arrow-mark: - |top v list| + |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 markDirectories:false. + top open + + adds a pattern, only showing .st files and directories: - 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 markDirectories:false. - top open + |top v list| - example (adds a pattern, only showing .st files and directories): + 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 - |top v list| + 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:'*.st'. - list action:[:index | Transcript showCr:'you selected: ' , list selectionValue]. - top open + 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 - example (a more complicated pattern): + adds a matchblock to show only writable files: - |top v list| + |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 + 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 - example (adds a matchblock to show only writable files): + adds a matchblock to suppress directories: + (this can be done easier with #ignoreDirectories) - |top v list| + |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 + 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 + + the above can be done more convenient: + + |top v list| - example (adds a matchblock to suppress directories): + 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 ignoreDirectories:true. + list action:[:index | Transcript showCr:'you selected: ' , list selectionValue]. + top open - |top v list| + adds a matchblock to block parent dirs (i.e. only allow files here & below): + (can be done easier with #ignoreParentDirectory) + + |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 asFilename isDirectory not - ]. - list action:[:index | Transcript showCr:'you selected: ' , list selectionValue]. - top open + 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 - example (the above can be done more convenient) + do not allow changing up AND show all .rc-files only: + (but allow going down) + + |top v list currentDir| + + currentDir := '.' asFilename pathName. - |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:'*.rc'. + list matchBlock:[:name | + ((name endsWith:'/..') and:[list directory pathName = currentDir]) not + ]. + list action:[:index | Transcript showCr:'you selected: ' , list selectionValue]. + top open - 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 ignoreDirectories:true. - list action:[:index | Transcript showCr:'you selected: ' , list selectionValue]. - top open + show only .rc-files in current directory: - example (adds a matchblock to block parent dirs (i.e. only allow files here & below): + |top v list currentDir| + + currentDir := '.' asFilename pathName. - |top v list currentDir| + 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 - currentDir := '.' asFilename pathName. + show only h*-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 matchBlock:[:name | - ((name endsWith:'/..') and:[list directory pathName = currentDir]) not - ]. - list action:[:index | Transcript showCr:'you selected: ' , list selectionValue]. - top open + 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:'h*'. + list matchBlock:[:name | name printNL. + name asFilename isDirectory not + ]. + list action:[:index | Transcript showCr:'you selected: ' , list selectionValue]. + top open - example (block moving up AND show all .rc-files only): + only allow changing into directories below the current one; i.e. not up; + but show it - |top v list currentDir| + |top v list here| - 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 directoryChangeCheckBlock:[:dirPath | + dirPath asFilename pathName + startsWith:Filename currentDirectory pathName]. + list action:[:index | Transcript showCr:'you selected: ' , list selectionValue]. + top open + + + living in a box: + + |box listView| - 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 + box := Dialog new. + box addTextLabel:'which file ?'. - example (show only .rc-files in current directory): + listView := box + addListBoxOn:nil + class:FileSelectionList + withNumberOfLines:10 + hScrollable:false + vScrollable:true. - |top v list currentDir| + box addAbortButton; addOkButton. + box open. + box accepted ifTrue:[ + Transcript showCr:listView selectedPathname + ] - currentDir := '.' asFilename pathName. + + living in a box (local files only, no directory change allowed): - 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 + |box listView| + + box := Dialog new. + box addTextLabel:'which file ?'. + + listView := box + addListBoxOn:nil + class:FileSelectionList + withNumberOfLines:10 + hScrollable:false + vScrollable:true. - example (show only h*-files in /etc; dont allow directory changes): + listView ignoreDirectories:true. + listView ignoreParentDirectory:true. - |top v list| + box addAbortButton; addOkButton. + box open. + box accepted ifTrue:[ + Transcript showCr:listView selectedPathname + ] + + + living in a box (local files only; immediately show owner in another field): + + |box listView lbl| + + box := Dialog new. + box addTextLabel:'which file ?'. - 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:'h*'. - list matchBlock:[:name | name printNL. - name asFilename isDirectory not - ]. - list action:[:index | Transcript showCr:'you selected: ' , list selectionValue]. - top open + listView := box + addListBoxOn:nil + class:FileSelectionList + withNumberOfLines:10 + hScrollable:false + vScrollable:true. + + lbl := box addTextLabel:''. + lbl adjust:#left. + + listView fileSelectAction:[:index | + |ownerId owner| - example (only allow changing into directories below the current one; i.e. not up; - but show it) + ownerId := listView selectedPathname asFilename info at:#uid. + ownerId == OperatingSystem getUserID ifTrue:[ + lbl label:('one of yours'). + ] ifFalse:[ + owner := OperatingSystem getUserNameFromID:ownerId. + lbl label:(owner , '''s property'). + ] + ]. - |top v list here| + listView directorySelectAction:[:index | + |ownerId owner| - 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 directoryChangeCheckBlock:[:dirPath | - dirPath asFilename pathName - startsWith:Filename currentDirectory pathName]. - list action:[:index | Transcript showCr:'you selected: ' , list selectionValue]. - top open + ownerId := listView selectedPathname asFilename info at:#uid. + ownerId == OperatingSystem getUserID ifTrue:[ + lbl label:('your files there'). + ] ifFalse:[ + owner := OperatingSystem getUserNameFromID:ownerId. + lbl label:(owner , '''s files there'). + ] + ]. + + box addAbortButton; addOkButton. + box open. + box accepted ifTrue:[ + Transcript showCr:listView selectedPathname + ] " ! ! @@ -341,6 +464,26 @@ directoryChangeCheckBlock := aBlock ! +directorySelectAction:aBlock + "set the action to be performed when a directory is selected. + Useful if someone else wants to show additional information + (readable/owner ...) somewhere." + + directorySelectAction := aBlock + + "Created: 18.4.1996 / 18:45:13 / cg" +! + +fileSelectAction:aBlock + "set the action to be performed when a file is selected. + Useful if someone else wants to show additional information + (readable/owner ...) somewhere." + + fileSelectAction := aBlock + + "Created: 18.4.1996 / 18:45:24 / cg" +! + ignoreDirectories:aBoolean "set/clear the flag which controls if directories are ignored (i.e. hidden). The default is false (i.e. dirs are shown)" @@ -348,6 +491,16 @@ ignoreDirectories := aBoolean ! +ignoreFiles:aBoolean + "set/clear the flag which controls if plain files are ignored + (i.e. hidden). The default is false (i.e. they are shown)" + + ignoreFiles := aBoolean + + "Created: 18.4.1996 / 18:48:43 / cg" + "Modified: 18.4.1996 / 18:49:23 / cg" +! + ignoreParentDirectory:aBoolean "set/clear the flag which controls if the parent directory (..) is shown in the list. The default is false (i.e. show it)" @@ -518,15 +671,22 @@ ] ifFalse:[ self changeDirectory ] + ] ifFalse:[ + directorySelectAction notNil ifTrue:[ + directorySelectAction value:self selection + ] ] ] ifFalse:[ realAction notNil ifTrue:[ realAction value:self selection + ]. + fileSelectAction notNil ifTrue:[ + fileSelectAction value:self selection ] ] ] - "Modified: 5.3.1996 / 02:37:58 / cg" + "Modified: 18.4.1996 / 18:44:30 / cg" ! sizeChanged:how @@ -543,7 +703,7 @@ initialize directory := FileDirectory currentDirectory. stayInDirectory := ignoreParentDirectory := ignoreDirectories := false. - quickDirectoryChange := false. + ignoreFiles := quickDirectoryChange := false. markDirectories := true. super initialize. @@ -558,7 +718,7 @@ (HVScrollableView for:FileSelectionList) open " - "Modified: 4.3.1996 / 17:36:29 / cg" + "Modified: 18.4.1996 / 18:49:19 / cg" ! initializeAction @@ -698,23 +858,25 @@ ] ] ] ifFalse:[ - matching := true. + ignoreFiles ifFalse:[ + matching := true. - (pattern isNil - or:[pattern isEmpty]) ifFalse:[ - pattern = '*' ifFalse:[ - (pattern includes:$;) ifTrue:[ - patternList := pattern asCollectionOfSubstringsSeparatedBy:$;. - matching := (patternList findFirst:[:subPattern | subPattern match:name]) ~~ 0. - ] ifFalse:[ - matching := pattern match:name + (pattern isNil + or:[pattern isEmpty]) ifFalse:[ + pattern = '*' ifFalse:[ + (pattern includes:$;) ifTrue:[ + patternList := pattern asCollectionOfSubstringsSeparatedBy:$;. + matching := (patternList findFirst:[:subPattern | subPattern match:name]) ~~ 0. + ] ifFalse:[ + matching := pattern match:name + ] ] + ]. + + matching ifTrue:[ + newList add:name. + fileTypes add:type ] - ]. - - matching ifTrue:[ - newList add:name. - fileTypes add:type ] ]. ]. @@ -723,6 +885,8 @@ super list:newList. self cursor:oldCursor. + + "Modified: 18.4.1996 / 18:49:48 / cg" ! visibleLineNeedsSpecialCare:visLineNr @@ -762,5 +926,5 @@ !FileSelectionList class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libwidg/FileSelectionList.st,v 1.26 1996-03-05 01:38:29 cg Exp $' + ^ '$Header: /cvs/stx/stx/libwidg/FileSelectionList.st,v 1.27 1996-04-19 11:26:09 cg Exp $' ! !