'From Squeak3.5 of ''11 April 2003'' [latest update: #5180] on 16 May 2003 at 9:15:34 pm'! "Change Set: FileList-mods Date: 13 May 2003 Author: Stephan B. Wessels Added a simple enhancement where the file name of the selected file can be copied to the clipboard. There is an existing menu operation which supports copying the whole file name path to the clipboard and this was left alone. Also provided a way to copy a file from either a local directory or a remote one to a local directory. No provision has been made to copy a local file to the remote at this time, however. Date Update ------------- ----------------------------------------------------------------------- 15-May-2003 Added support for copying files from remote location. 13-May-2003 Initial change set creation. " | prereqSMName continue cs prereqCSName prereqRevDateRqd | prereqCSName _ 'Dialogs-sbw'. prereqSMName _ 'FileList2 Dialogs Enhancement'. prereqRevDateRqd _ '15-apr-2003' asDate. continue _ (ChangeSorter respondsTo: #assurePrerequisiteChangeSetNamed:withSqueakMapName:revisionDate:) ifTrue: [ChangeSorter assurePrerequisiteChangeSetNamed: prereqCSName withSqueakMapName: prereqSMName revisionDate: prereqRevDateRqd] ifFalse: [cs _ ChangeSorter changeSetNamed: prereqCSName. cs isNil ifTrue: [(Object confirm: 'The package "' , prereqSMName , '" is not installed in your image. Do you want me to install it for you?. Please note that "' , prereqSMName , '" is required for the package you are about to install.') and: []. (Smalltalk at: #SMSqueakMap ifAbsent: []) ifNil: [Object error: 'You don''t have SqueakMap installed in your image. Either install SqueakMap or install the missing prerequisite change set.']. Utilities informUser: 'Installing "' , prereqSMName , '"...' during: [(Smalltalk at: #SMSqueakMap) default installPackageNamed: prereqSMName]. true] ifFalse: [true]]. continue ifFalse: [Object error: 'Unable to load prerequisite package.']. ! !FileDirectory methodsFor: 'file operations' stamp: 'sbw 5/14/2003 19:24'! copyFileNamed: fileName toDirectory: aDirectory "Copy the contents of the existing file into a directory." | file1 file2 | self = aDirectory ifTrue: [^ nil]. file1 := (self readOnlyFileNamed: fileName) binary. file2 := (aDirectory newFileNamed: fileName) binary. self copyFile: file1 toFile: file2. file1 close. file2 close ! ! !FileList methodsFor: 'to be transformed in registration' stamp: 'sbw 5/13/2003 18:59'! perform: selector orSendTo: otherTarget "Selector was just chosen from a menu by a user. If it's one of the three sort-by items, handle it specially. If I can respond myself, then perform it on myself. If not, send it to otherTarget, presumably the editPane from which the menu was invoked." ^ (#(#sortByDate #sortBySize #sortByName ) includes: selector) ifTrue: [self resort: selector] ifFalse: [(#(#get #getHex #copyName #copyJustFileName #openImageInWindow #importImage #renameFile #deleteFile #addNewFile ) includes: selector) ifTrue: [self perform: selector] ifFalse: [super perform: selector orSendTo: otherTarget]]! ! !FileList methodsFor: 'file list menu' stamp: 'sbw 5/14/2003 19:24'! copySelectedFileToDirectory: aDirectory directory copyFileNamed: fileName toDirectory: aDirectory! ! !FileList methodsFor: 'file list menu' stamp: 'sbw 5/15/2003 12:42'! copySelectedFileToNewLocation | result | listIndex = 0 ifTrue: [^ self]. (result _ FileList2 modalFolderSelectorWithPrompt: 'Choose folder') ifNotNil: [self copySelectedFileToDirectory: result]! ! !FileList methodsFor: 'file list menu' stamp: 'sbw 5/16/2003 19:44'! itemsForAnyFile "Answer a list of universal services that could apply to any file" | services | services _ OrderedCollection new: 5. services add: self serviceCopyName. services add: self serviceCopyJustFileName. services add: self serviceCopySelectedFileToNewLocation. services add: self serviceRenameFile. services add: self serviceDeleteFile. ^ services! ! !FileList methodsFor: 'menu messages' stamp: 'sbw 5/13/2003 18:57'! copyJustFileName listIndex = 0 ifTrue: [^ self]. Clipboard clipboardText: self fileName asText! ! !FileList methodsFor: 'own services' stamp: 'sbw 5/13/2003 18:57'! serviceCopyJustFileName ^ SimpleServiceEntry provider: self label: 'copy just file name to clipboard' selector: #copyJustFileName description: 'copy just name to clipboard'! ! !FileList methodsFor: 'own services' stamp: 'sbw 5/16/2003 19:38'! serviceCopySelectedFileToNewLocation ^ (SimpleServiceEntry provider: self label: 'copy file' selector: #copySelectedFileToNewLocation) description: 'copy the seleted item to a new location'! ! !FileListTest methodsFor: 'private' stamp: 'sbw 5/13/2003 20:21'! createTempDirectoryIn: aDirectory | time dname | time := Time now. dname := time hhmm24 , time seconds printString. (aDirectory directoryExists: dname) ifTrue: [aDirectory deleteDirectory: dname]. aDirectory createDirectory: dname. ^ dname ! ! !FileListTest methodsFor: 'private' stamp: 'sbw 5/13/2003 20:07'! createTempFileIn: aDirectory | time fname fstream | time := Time now. fname := time hhmm24 , time seconds printString , '.tmp'. (aDirectory fileExists: fname) ifTrue: [ aDirectory deleteFileNamed: fname]. fstream := aDirectory forceNewFileNamed: fname. fstream nextPutAll: self tempFileContents. fstream close. ^ fname ! ! !FileListTest methodsFor: 'private' stamp: 'sbw 5/13/2003 19:58'! fileListMorph: gui ^ ((gui allMorphs select: [:m | m isKindOf: PluggableListMorph]) select: [:m | m getListSelector = #fileList]) first ! ! !FileListTest methodsFor: 'private' stamp: 'sbw 5/13/2003 19:54'! tempFileContents ^ 'test file contents' ! ! !FileListTest methodsFor: 'private' stamp: 'sbw 5/13/2003 20:27'! testFileLocalCopy | dir dname subDir fname entry index listMorph originalFileStream copiedFileStream originalContents copiedContents gui | Smalltalk isMorphic ifFalse: [^ nil]. dir := FileDirectory default. dname := self createTempDirectoryIn: dir. subDir := dir directoryNamed: dname. fname := self createTempFileIn: dir. gui := FileList openAsMorph. "Since we just opened up the FileList we can assume it's directory is correct. " entry := gui model fileList detect: [:each | each includesSubString: fname] ifNone: []. index := gui model fileList indexOf: entry. listMorph := self fileListMorph: gui. listMorph selectionIndex: index. gui model fileListIndex: index. "Now that we faked the selection of our test file, ask our FileList to copy the file to our new sub-directory." gui model copySelectedFileToDirectory: subDir. "See if it's there." self assert: (subDir fileExists: fname). "How about it's contents?" originalFileStream := dir readOnlyFileNamed: fname. copiedFileStream := subDir readOnlyFileNamed: fname. originalContents := originalFileStream contentsOfEntireFile. copiedContents := copiedFileStream contentsOfEntireFile. originalFileStream close. copiedFileStream close. self assert: originalContents = copiedContents. "Done with the files and directory." dir deleteFileNamed: fname. subDir deleteFileNamed: fname. dir deleteDirectory: dname. gui delete ! ! !FileListTest methodsFor: 'test' stamp: 'sbw 5/13/2003 20:11'! testFileNameOperations | gui dir fname entry index listMorph string | Smalltalk isMorphic ifFalse: [^ nil]. dir _ FileDirectory default. fname _ self createTempFileIn: dir. gui _ FileList openAsMorph. "Since we just opened up the FileList we can assume it's directory is the same as ours." entry _ gui model fileList detect: [:each | each includesSubString: fname] ifNone: []. index _ gui model fileList indexOf: entry. listMorph _ self fileListMorph: gui. listMorph selectionIndex: index. gui model fileListIndex: index. "Now that we faked the selection of our test file, ask our FileList to copy the name." gui model copyName. string _ Clipboard clipboardText string. self assert: string = (dir fullNameFor: fname). gui model copyJustFileName. string _ Clipboard clipboardText string. self assert: string = fname. "Done with the file." dir deleteFileNamed: fname. gui delete! ! !ServerDirectory methodsFor: 'accessing' stamp: 'sbw 5/16/2003 20:07'! copyFile: fileStream1 toFile: fileStream2 | buffer | buffer := String new: 50000. [fileStream1 atEnd] whileFalse: [fileStream2 nextPutAll: (fileStream1 nextInto: buffer)]! ! !ServerDirectory methodsFor: 'accessing' stamp: 'sbw 5/16/2003 20:08'! copyFileNamed: fileName toDirectory: aDirectory "Copy the contents of the existing file into a directory." | file1 file2 | self = aDirectory ifTrue: [^ nil]. file1 := (self readOnlyFileNamed: fileName) binary. file2 := (aDirectory newFileNamed: fileName) binary. self copyFile: file1 toFile: file2. file1 close. file2 close ! ! FileListTest removeSelector: #createTempFile!