'From Cuis 2.6 of 10 August 2010 [latest update: #540] on 27 August 2010 at 9:25:06 am'!

!FileList methodsFor: 'volume list and pattern' stamp: 'jmv 8/27/2010 09:24'!
fileNameFormattedFrom: entry namePad: namePad sizePad: sizePad sizeWithCommasPad: sizeWithCommasPad
	"entry is a 5-element array of the form:
		(name creationTime modificationTime dirFlag fileSize)"
	| sizeStr nameStr paddedNameStr 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.
	paddedNameStr _ 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:
		[^ paddedNameStr, someSpaces, '( ', dateStr, someSpaces, sizeStr, ' )'].
	sortMode = #date ifTrue:
		[^ '( ', dateStr, someSpaces, sizeStr, ' )', someSpaces, nameStr].
	sortMode = #size ifTrue:
		[^  '( ', sizeStr, someSpaces, dateStr, ' )', someSpaces, nameStr].
! !

