'From Cuis 2.6 of 10 August 2010 [latest update: #540] on 11 August 2010 at 3:56:59 pm'!

!FileList methodsFor: 'volume list and pattern' stamp: 'jmv 8/11/2010 15:55'!
fileNameFormattedFrom: entry namePad: namePad sizePad: sizePad sizeWithCommasPad: sizeWithCommasPad
	"entry is a 5-element array of the form:
		(name creationTime modificationTime dirFlag fileSize)"
	| sizeStr nameStr dateStr someSpaces sizeDigits sizeDigitsAndCommas spacesToAdd font spaceWidth |
	font _ Preferences standardListFont.
	spaceWidth _ font widthOf: $ .
	nameStr _ (entry at: 4)
		ifTrue: [entry first , self folderString]
		ifFalse: [entry first].
	spacesToAdd _ namePad - (font widthOfString: nameStr) // spaceWidth.
	nameStr _ nameStr, (String new: spacesToAdd withAll: $ ).

	dateStr _ ((Date fromSeconds: (entry at: 3) )
					printFormat: #(3 2 1 $/ 1 1 2)) , '  ' ,
				(String streamContents: [:s |
					(Time fromSeconds: (entry at: 3) \\ 86400)
						print24: true on: s]).

	sizeDigits _ (entry at: 5) printString size.
	sizeStr _ (entry at: 5) asStringWithCommas.
	sizeDigitsAndCommas _ sizeStr size.
	"Usually a space takes the same space as a comma, and half the space of a digit.
	Pad with 2 spaces for each missing digit and 1 space for each missing comma"
	spacesToAdd _ sizeWithCommasPad - sizeDigitsAndCommas + sizePad - sizeDigits.
	sizeStr _ (String new: spacesToAdd withAll: $ ), sizeStr.

	someSpaces _ String new: 6 withAll: $ .
	sortMode = #name ifTrue:
		[^ nameStr, someSpaces, '( ', dateStr, someSpaces, sizeStr, ' )'].
	sortMode = #date ifTrue:
		[^ '( ', dateStr, someSpaces, sizeStr, ' )', someSpaces, nameStr].
	sortMode = #size ifTrue:
		[^  '( ', sizeStr, someSpaces, dateStr, ' )', someSpaces, nameStr].
! !

!FileList methodsFor: 'private' stamp: 'jmv 8/11/2010 15:33'!
listForPatterns: anArray
	"Make the list be those file names which match the pattern."

	| sizePad newList namePad sizeWithCommasPad font |
	newList _ Set new.
	anArray do: [ :pat | newList addAll: (self entriesMatching: pat) ].
	newList _ (SortedCollection sortBlock: self sortBlock) addAll: newList; yourself.
	font _ Preferences standardListFont.
	namePad _ newList inject: 0 into: [ :mx :entry | mx max: (font widthOfString: entry first)].
	sizePad _ (newList inject: 0 into: [ :mx :entry | mx max: (entry at: 5)]) printString size.
	sizeWithCommasPad _ (newList inject: 0 into: [ :mx :entry | mx max: (entry at: 5)]) asStringWithCommas size.
	newList _ newList collect: [ :e | self fileNameFormattedFrom: e namePad: namePad sizePad: sizePad sizeWithCommasPad: sizeWithCommasPad ].

	^ newList asArray! !


!FileList2 methodsFor: 'volume list and pattern' stamp: 'jmv 8/11/2010 15:34'!
listForPatterns: anArray
	"Make the list be those file names which match the patterns."

	| sizePad newList namePad sizeWithCommasPad font |
	directory ifNil: [^#()].
	(fileSelectionBlock isKindOf: MessageSend) ifTrue: [
		fileSelectionBlock arguments: {directory entries}.
		newList _ fileSelectionBlock value.
		fileSelectionBlock arguments: #().
	] ifFalse: [
		newList _ Set new.
		anArray do: [ :pat |
			newList addAll: (directory entries select: [:entry | fileSelectionBlock value: entry value: pat]) ].
	].
	newList _ newList asSortedCollection: self sortBlock.
	font _ Preferences standardListFont.
	namePad _ newList inject: 0 into: [ :mx :entry | mx max: (font widthOfString: entry first)].
	sizePad _ (newList inject: 0 into: [ :mx :entry | mx max: (entry at: 5)]) printString size.
	sizeWithCommasPad _ (newList inject: 0 into: [ :mx :entry | mx max: (entry at: 5)]) asStringWithCommas size.
	newList _ newList collect: [ :e | self fileNameFormattedFrom: e namePad: namePad sizePad: sizePad sizeWithCommasPad: sizeWithCommasPad ].
	^ newList asArray! !


!Integer methodsFor: 'printing' stamp: 'jmv 8/11/2010 14:59'!
asStringThousandSeparator: aString includePlusSign: aBoolean
	"123456789 asStringThousandSeparator: '.'  "
	"-123456789 asStringThousandSeparator: ';' "
	| digits |
	digits _ self abs printString.
	^ String streamContents:
		[ :strm | 
		self sign = -1
			ifTrue: [ strm nextPut: $- ]
			ifFalse: [ aBoolean ifTrue: [ strm nextPut: $+ ]].
		1 to: digits size do: 
			[:i | strm nextPut: (digits at: i).
			(i < digits size and: [(i - digits size) \\ 3 = 0])
				ifTrue: [strm nextPutAll: aString]]]! !

!Integer methodsFor: 'printing' stamp: 'jmv 8/11/2010 15:00'!
asStringWithCommas
	"123456789 asStringWithCommas"
	"-123456789 asStringWithCommas"
	^self asStringThousandSeparator: ',' includePlusSign: false! !

!Integer methodsFor: 'printing' stamp: 'jmv 8/11/2010 15:00'!
asStringWithCommasSigned
	"123456789 asStringWithCommasSigned"
	"-123456789 asStringWithCommasSigned"
	^self asStringThousandSeparator: ',' includePlusSign: true! !

FileList removeSelector: #fileNameFormattedFrom:sizePad:!
