--- a/AbstractFileBrowser.st Tue Oct 08 21:29:16 2002 +0200
+++ b/AbstractFileBrowser.st Wed Oct 09 14:20:58 2002 +0200
@@ -36,7 +36,7 @@
!
OrderedCollection subclass:#DirectoryHistory
- instanceVariableNames:'backItem'
+ instanceVariableNames:'forwardList lastWasForwardAction'
classVariableNames:'HistorySize'
poolDictionaries:''
privateIn:AbstractFileBrowser
@@ -82,6 +82,7 @@
DirectoryHistory isNil ifTrue:[
DirectoryHistory := self directoryHistoryClass new.
+"/ DirectoryHistory inspect.
].
^ DirectoryHistory
!
@@ -1227,15 +1228,15 @@
#translateLabel: true
#hideMenuOnActivated: false
#choice: #sortBlockHolder
- #choiceValue: #timeAndDate
+ #choiceValue: #modificationTime
)
- #(#MenuItem
- #label: 'By Description'
- #translateLabel: true
- #hideMenuOnActivated: false
- #choice: #sortBlockHolder
- #choiceValue: #fileType
- )
+"/ #(#MenuItem
+"/ #label: 'By Description'
+"/ #translateLabel: true
+"/ #hideMenuOnActivated: false
+"/ #choice: #sortBlockHolder
+"/ #choiceValue: #fileType
+"/ )
#(#MenuItem
#label: '-'
)
@@ -1432,7 +1433,13 @@
gotoFile:aFilename
- self currentFileNameHolder value:(OrderedCollection with:(aFilename asAbsoluteFilename)).
+ " select only if the file is not already in selection"
+ | currentSel |
+
+ currentSel := self currentFileNameHolder value.
+ ((currentSel findFirst:[:aFile| aFile = aFilename]) == 0) ifTrue:[
+ self currentFileNameHolder value:(OrderedCollection with:(aFilename asAbsoluteFilename)).
+ ].
!
openApplByFileItem:aItem
@@ -1545,9 +1552,14 @@
doBack
- | fileName |
-
- fileName := self dirHistory goBack.
+ | fileName currentSel|
+
+ currentSel := self currentDirectories value.
+ currentSel size == 1 ifTrue:[
+ fileName := self dirHistory goBackFrom:(currentSel first asString).
+ ] ifFalse:[
+ fileName := self dirHistory goBackFrom:nil.
+ ].
fileName notNil ifTrue:[
self gotoFile:(fileName asFilename).
]
@@ -1555,7 +1567,8 @@
doForward
- | fileName |
+ | fileName|
+
fileName := self dirHistory goForward.
fileName notNil ifTrue:[
self gotoFile:(fileName asFilename).
@@ -1634,6 +1647,15 @@
^ self aspectFor:#currentFileNameHolder ifAbsent:[(OrderedCollection with:(Filename currentDirectory asAbsoluteFilename)) asValue]
!
+currentSortOrder
+
+ " returns a Ordered Collection of all directories currently selected
+ if only a file is selected currentDirectories holds the directory of the file
+ "
+
+ ^ self aspectFor:#currentSortOrder ifAbsent:[ Dictionary new ].
+!
+
enableDirectoryUp
^ self aspectFor:#enableDirectoryUp ifAbsent:[false asValue]
@@ -1768,7 +1790,6 @@
dirHistory
-"/ ^ self aspectFor:#dirHistory ifAbsent:[DirectoryHistory1 new]
^ self class directoryHistory
!
@@ -2539,11 +2560,21 @@
canBack
- ^ self dirHistory canBack.
+ | currentSelection |
+
+ currentSelection := self currentDirectories value.
+ currentSelection size ~~ 1 ifTrue:[ ^ false].
+
+ ^ self dirHistory canBackFrom:(currentSelection first asString).
!
canForward
+"/ | currentSelection |
+"/
+"/ currentSelection := self currentDirectories value.
+"/ currentSelection size ~~ 1 ifTrue:[ ^ false].
+
^ self dirHistory canForward.
!
@@ -2552,38 +2583,31 @@
"
<resource: #programMenu >
- |menu histCopy text removeItem|
+ |menu pathList currentSel currentPath|
menu := Menu new.
menu receiver:self.
self dirHistory isEmpty ifTrue:[^ nil].
- text := LabelAndIcon icon:(self class clearHistoryIcon) string:'Clear History'.
- removeItem := MenuItem new.
- removeItem label:text.
backOrForward == #back ifTrue:[
- removeItem value:[
- self dirHistory reset.
- self enableForward value:self dirHistory canForward.
- self enableBack value:self dirHistory canBack.
+ currentSel := self currentDirectories value.
+ currentSel size == 1 ifTrue:[
+ currentPath := currentSel first asString.
+ ] ifFalse:[
+ currentPath := nil.
].
- histCopy := self dirHistory getBackCollection.
+ pathList := self dirHistory getBackCollectionFrom:currentPath.
] ifFalse:[
- removeItem value:[
- self dirHistory resetForward.
- self enableForward value:self dirHistory canForward.
- self enableBack value:self dirHistory canBack.
- ].
- histCopy := self dirHistory getForwardCollection.
+ pathList := self dirHistory getForwardCollection.
].
- histCopy do:[:aFile|
- menu addItem:(MenuItem label:aFile asString value:[
- self currentFileNameHolder value:(OrderedCollection with:(aFile asFilename)).
- ]).
- ].
- backOrForward == #back ifTrue:[
- menu addItem:(MenuItem label:'-').
- menu addItem:removeItem.
+ pathList do:[:aPath|
+ | menuItem |
+ menuItem := MenuItem new.
+ menuItem label:aPath.
+ menuItem value:[
+ self currentFileNameHolder value:(OrderedCollection with:(aPath asFilename)).
+ ].
+ menu addItem:menuItem.
].
^ menu
!
@@ -2656,8 +2680,8 @@
removeItem label:text.
removeItem value:[
self dirHistory removeAll.
- self enableForward value:self dirHistory canForward.
- self enableBack value:self dirHistory canBack.
+ self enableForward value:self canForward.
+ self enableBack value:self canBack.
].
histCopy := self dirHistory.
histCopy do:[:aFile|
@@ -4235,6 +4259,45 @@
^ self application:#DirectoryContentsBrowser do:#getItemsFromSelection.
! !
+!AbstractFileBrowser methodsFor:'sorting'!
+
+sortList:instanceName
+
+ self sortList:instanceName withReverse:true
+!
+
+sortList:instanceName withReverse:aBoolean
+
+ | aSymbol sortCaselessLocal locCurrentSortOrder|
+
+ aSymbol := instanceName asSymbol.
+ locCurrentSortOrder := self currentSortOrder.
+ locCurrentSortOrder isEmpty ifTrue:[
+ locCurrentSortOrder at:#column put:aSymbol.
+ locCurrentSortOrder at:#reverse put:false.
+ locCurrentSortOrder at:#sortCaseless put:sortCaselessLocal.
+ ] ifFalse:[
+ (locCurrentSortOrder at:#sortCaseless) ~= sortCaselessLocal ifTrue:[
+ "/ sort caseless changed
+ locCurrentSortOrder at:#sortCaseless put:sortCaselessLocal.
+ ] ifFalse:[
+ (locCurrentSortOrder at:#column) = aSymbol ifTrue:[
+ "/ same column like before - change sort order ifReverse is true
+ aBoolean ifTrue:[
+ | isReverse |
+ isReverse := locCurrentSortOrder at:#reverse.
+ locCurrentSortOrder at:#reverse put:(isReverse not).
+ ].
+ ] ifFalse:[
+ "/ another column - remark column
+ locCurrentSortOrder at:#column put:aSymbol.
+ ]
+ ]
+ ].
+ self application:#DirectoryContentsBrowser do:#sortListChangedWith:and: withArg:locCurrentSortOrder withArg:instanceName.
+"/ self application:#DirectoryTreeBrowser do:#sortListChangedWith:and: withArg:true withArg:instanceName.
+! !
+
!AbstractFileBrowser methodsFor:'startup & release'!
makeDependent
@@ -4328,45 +4391,17 @@
!AbstractFileBrowser::DirectoryHistory methodsFor:'accessing'!
-backItem
- "return the value of the instance variable 'backItem' (automatically generated)"
-
- ^ backItem
-!
-
-backItem:something
- "set the value of the instance variable 'backItem' (automatically generated)"
-
- backItem := something.
+forwardList
+ "return the value of the instance variable 'forwardList' (automatically generated)"
+
+ forwardList isNil ifTrue:[
+ forwardList := OrderedCollection new.
+ ].
+ ^ forwardList
! !
!AbstractFileBrowser::DirectoryHistory methodsFor:'actions'!
-addToBackList:aItem
-
- | index|
-
- aItem isNil ifTrue:[
- index := 0.
- ] ifFalse:[
- index := self backList findFirst:[:item |
- item path = aItem path
- ]
- ].
- index == 0 ifTrue:[
- " not already in history"
- self backList size >= self class historySize ifTrue:[
- self backList removeLast.
- ].
- self forwardList removeAll.
- ] ifFalse:[
- "already been there before; move the entry to
- the beginning, so it will fall out later."
- self backList removeAtIndex:index.
- ].
- self backList addFirst:aItem
-!
-
addToHistory:aPath
| item|
@@ -4374,9 +4409,6 @@
item isNil ifTrue:[
" not already in history"
self size >= self class historySize ifTrue:[
- (self isBackItem:(self at:(self size))) ifTrue:[
- self backItem:(self at:(self size - 1)).
- ].
self removeLast.
].
item := DirectoryHistoryItem path:aPath.
@@ -4384,62 +4416,78 @@
] ifFalse:[
"already been there before; move the entry to
the beginning, so it will fall out later."
- (self isBackItem:item) ifTrue:[
+ lastWasForwardAction ifTrue:[
+ lastWasForwardAction := false.
+ ] ifFalse:[
self remove:item.
self addFirst:item
]
].
!
-goBack
-
-" set the instance variable backItem to the next backItem and return them pathname"
-
- | index newBackItem|
-
- self backItem notNil ifTrue:[
- index := self indexOf:(self backItem) ifAbsent:nil.
+forwardListAdd:aPath
+
+ | index |
+ index := self forwardList indexOf:aPath.
+ index == 0 ifTrue:[
+ " not already in history"
+ self size >= self class historySize ifTrue:[
+ self forwardList removeLast.
+ ].
+ self forwardList addFirst:aPath.
] ifFalse:[
- index := 0.
+ "already been there before; move the entry to
+ the beginning, so it will fall out later."
+ self forwardList remove:aPath.
+ self forwardList addFirst:aPath
].
- index = self size ifTrue:[^ nil].
- newBackItem := self at:index + 1.
- self backItem:newBackItem.
- ^ newBackItem path.
+!
+
+goBackFrom:aPath
+
+" search the item in the list and give back the next in the list"
+
+ | index retVal|
+
+ self isEmpty ifTrue:[ ^ nil].
+ aPath isNil ifTrue:[
+ retVal := self first path
+ ] ifFalse:[
+ index := self findFirst:[:item| item path = aPath].
+ index == 0 ifTrue:[
+ retVal := self first path
+ ] ifFalse:[
+ index < self size ifTrue:[
+ retVal := ((self at:index + 1) path).
+ ]
+ ].
+ ].
+ retVal := retVal ? self first path.
+ self forwardListAdd:aPath.
+ ^ retVal.
!
goForward
-" set the instance variable backItem to the next backItem and return them pathname"
-
- | index newForwItem|
-
- self backItem isNil ifTrue:[
- ^ nil
- ].
-
- index := self indexOf:(self backItem) ifAbsent:nil.
- (index isNil or:[index = 1]) ifTrue:[
- ^ nil
- ].
- newForwItem := self at:index - 1.
- self backItem:newForwItem.
- ^ newForwItem path.
-!
-
-reset
-
- self backItem:nil.
-!
-
-resetBack
-
- self forwardList removeAll.
-!
-
-resetForward
-
- self forwardList removeAll.
+" return first path of forward list"
+
+ | retVal|
+ lastWasForwardAction := true.
+ self forwardList isEmpty ifTrue:[ ^ nil].
+ retVal := self forwardList first.
+ self forwardList removeFirst.
+ ^ retVal.
+!
+
+goForwardFrom:aPath
+
+" get back first forward entry and remove him"
+
+ | retVal|
+ lastWasForwardAction := true.
+ retVal := self forwardList first.
+ self forwardList removeFirst.
+ ^ retVal.
!
setPosition:aPosition for:aPath
@@ -4453,45 +4501,38 @@
!AbstractFileBrowser::DirectoryHistory methodsFor:'queries'!
-canBack
-
- ^ self notEmpty and:[self backItem isNil or:[(self indexOf:(self backItem)) < (self size)]].
+canBackFrom:aPath
+
+ ^ ((self findFirst:[:item| item path = aPath]) < self size).
!
canForward
- ^ self backItem notNil and:[(self indexOf:(self backItem)) > 1].
-!
-
-getBackCollection
+ ^ self forwardList notEmpty.
+!
+
+getBackCollectionFrom:aPath
| backCol index |
backCol := OrderedCollection new.
- self backItem isNil ifTrue:[ ^ self collect:[:item | item path]].
- index := self indexOf:self backItem.
+ aPath isNil ifTrue:[
+ index := 0.
+ ] ifFalse:[
+ index := self findFirst:[:item| item path = aPath].
+ ].
+ "/ if aPath is not in collection starts from 1 with collect af path
index < self size ifTrue:[
self from:(index + 1) to:(self size) do:[:item |
backCol add:(item path).
].
].
-
^ backCol.
!
getForwardCollection
- | forwCol index |
-
- forwCol := OrderedCollection new.
- self backItem isNil ifTrue:[ ^ forwCol].
- index := self indexOf:self backItem.
- index > 1 ifTrue:[
- self from:1 to:(index - 1) reverseDo:[:item |
- forwCol add:(item path).
- ].
- ].
- ^ forwCol.
+ ^ self forwardList.
!
getItemFor:aPath
@@ -4516,12 +4557,6 @@
self do:[:item| item path = aPath ifTrue:[^ true]].
^ false.
-!
-
-isBackItem:aItem
-
- self backItem isNil ifTrue:[^ false].
- ^ self backItem path = aItem path
! !
!AbstractFileBrowser::DirectoryHistory::DirectoryHistoryItem class methodsFor:'instance creation'!
@@ -4625,5 +4660,5 @@
!AbstractFileBrowser class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libtool/AbstractFileBrowser.st,v 1.14 2002-10-08 19:29:16 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libtool/AbstractFileBrowser.st,v 1.15 2002-10-09 12:20:26 penk Exp $'
! !