'From Cuis 1.0 of 2 July 2009 [latest update: #215] on 9 July 2009 at 8:47:11 am'!

!StandardFileMenu methodsFor: 'menu building' stamp: 'jmv 7/9/2009 08:43'!
fileNamesString: aDirectory
"Answer a string concatenating the file name strings in aDirectory, each string followed by a cr."

	^String streamContents:
		[:s | 
			aDirectory fileNames do: 
				[:fn |
					(self patternMatches: fn) ifTrue: [
						s nextPutAll: fn withBlanksTrimmed; cr]]]! !

!StandardFileMenu methodsFor: 'menu building' stamp: 'jmv 7/9/2009 08:44'!
makeFileMenuFor: aDirectory
"Initialize an instance of me to operate on aDirectory"

	| theMenu |
	pattern ifNil: [ self pattern: '*'].
	Cursor wait showWhile: 
		[self 
			labels: 	(self menuLabelsString: aDirectory)
			font: 	(MenuStyle fontAt: 1) 
			lines: 	(self menuLinesArray: aDirectory).
		theMenu _ self selections: (self menuSelectionsArray: aDirectory)].
	^theMenu! !

!StandardFileMenu methodsFor: 'menu building' stamp: 'jmv 7/9/2009 08:42'!
menuSelectionsArray: aDirectory
"Answer a menu selections object corresponding to aDirectory.  The object is an array corresponding to each item, each element itself constituting a two-element array, the first element of which contains a selector to operate on and the second element of which contains the parameters for that selector."

	|dirSize|
	dirSize _ aDirectory pathParts size.
	^Array streamContents: [:s |
		canTypeFileName ifTrue:
			[s nextPut: (StandardFileMenuResult
				directory: aDirectory
				name: nil)].
		s nextPut: (StandardFileMenuResult
			directory: (FileDirectory root)
			name: '').
		aDirectory pathParts doWithIndex: 
			[:d :i | s nextPut: (StandardFileMenuResult
					directory: (self 
						advance: dirSize - i
						containingDirectoriesFrom: aDirectory)
					name: '')].
		aDirectory directoryNames do: 
			[:dn |  s nextPut: (StandardFileMenuResult
						directory: (FileDirectory on: (aDirectory fullNameFor: dn))
						name: '')].
		aDirectory fileNames do: 
			[:fn | (self patternMatches: fn) ifTrue: [
					s nextPut: (StandardFileMenuResult
						directory: aDirectory
						name: fn)]]]! !

!StandardFileMenu methodsFor: 'private' stamp: 'jmv 7/9/2009 08:44'!
newFileFrom: aDirectory withPattern: aPattern

	canTypeFileName _ true.
	self pattern: aPattern.
	^self makeFileMenuFor: aDirectory! !

!StandardFileMenu methodsFor: 'private' stamp: 'jmv 7/9/2009 08:44'!
oldFileFrom: aDirectory withPattern: aPattern

	canTypeFileName _ false.
	self pattern: aPattern.
	^self makeFileMenuFor: aDirectory! !

!StandardFileMenu methodsFor: 'private' stamp: 'jmv 7/9/2009 08:44'!
pattern: patString
	" * for all files, or '*.cs' for changeSets, etc.  Just like fileLists
	jmv- Added support for multiple patterns, separated by spaces.
	For example '*.cs *.st' will show both changesets and fileouts."

	pattern _ patString substrings! !

!StandardFileMenu methodsFor: 'private' stamp: 'jmv 7/9/2009 08:45'!
patternMatches: aString

	^pattern anySatisfy: [ :pat | pat match: aString ]! !


!StandardFileMenu class methodsFor: 'instance creation' stamp: 'jmv 7/9/2009 08:36'!
newFileMenu: aDirectory withPattern: aPattern
	^ self new newFileFrom: aDirectory withPattern: aPattern! !

!StandardFileMenu class methodsFor: 'instance creation' stamp: 'jmv 7/9/2009 08:36'!
oldFileMenu: aDirectory

	^self new oldFileFrom: aDirectory! !

!StandardFileMenu class methodsFor: 'instance creation' stamp: 'jmv 7/9/2009 08:36'!
oldFileMenu: aDirectory withPattern: aPattern

	^self new oldFileFrom: aDirectory withPattern: aPattern! !

