--- a/Tools__NavigationHistory.st Thu Jun 13 12:23:07 2013 +0100
+++ b/Tools__NavigationHistory.st Fri Jun 21 19:05:40 2013 +0100
@@ -14,7 +14,7 @@
"{ NameSpace: Tools }"
Object subclass:#NavigationHistory
- instanceVariableNames:'items position isGlobalHistory'
+ instanceVariableNames:'items position isGlobalHistory maxNumberOfItems'
classVariableNames:''
poolDictionaries:''
category:'Interface-Browsers-New-History'
@@ -63,6 +63,34 @@
!NavigationHistory methodsFor:'accessing'!
+addFirst:anEntry
+ "list protocol"
+
+ maxNumberOfItems == 0 ifTrue:[^ self].
+
+ items addFirst:anEntry.
+ items size > maxNumberOfItems ifTrue:[
+ items removeLast
+ ].
+ self changed: #value with: anEntry.
+
+ "Created: / 03-07-2011 / 13:26:48 / cg"
+!
+
+addLast:anEntry
+ "list protocol"
+
+ maxNumberOfItems == 0 ifTrue:[^ self].
+
+ items addLast:anEntry.
+ items size > maxNumberOfItems ifTrue:[
+ items removeFirst
+ ].
+ self changed: #value with: anEntry.
+
+ "Created: / 03-07-2011 / 13:26:48 / cg"
+!
+
currentItem
^(position between:1 and: items size)
@@ -95,22 +123,19 @@
"Created: / 27-02-2008 / 11:52:26 / janfrog"
"Modified: / 03-07-2011 / 16:00:45 / cg"
+!
+
+maxItemsInHistory:aNumber
+ maxNumberOfItems := aNumber max:1.
+ maxNumberOfItems > items size ifTrue:[
+ items removeFromIndex:maxNumberOfItems+1 toIndex:items size.
+ position := maxNumberOfItems.
+ self changed.
+ ].
! !
!NavigationHistory methodsFor:'backward list compatibility'!
-addFirst:anEntry
- "backward compatible list protocol"
-
- items addFirst:anEntry.
- items size > 30 ifTrue:[
- items removeLast
- ].
- self changed: #value with: anEntry.
-
- "Created: / 03-07-2011 / 13:26:48 / cg"
-!
-
collect:aBlock
"backward compatible list protocol"
@@ -223,6 +248,7 @@
items := OrderedCollection new.
position := 0.
isGlobalHistory := false.
+ maxNumberOfItems := maxNumberOfItems ? 30.
"Created: / 21-02-2008 / 15:26:05 / janfrog"
"Modified: / 03-07-2011 / 14:43:08 / cg"
@@ -230,13 +256,23 @@
!NavigationHistory methodsFor:'menu & menu actions'!
+clearHistory
+ self removeAll.
+ position := 0.
+ self changed.
+!
+
goBackMenu
- |menu|
+ |menu any|
+ any := false.
menu := Menu new.
self goBackItems do:[:item |
- menu addItem:(MenuItem label:item displayString value:[ self goTo:item ])
+ menu addItem:(MenuItem label:item displayString itemValue:[ self goTo:item ]).
+ any := true.
].
+ menu addSeparator.
+ menu addItem:((MenuItem label:'Clear History' value:[ self clearHistory]) enabled:any).
^ menu
"Created: / 22-02-2008 / 16:57:46 / janfrog"
@@ -248,7 +284,7 @@
menu := Menu new.
self goForwardItems do:[:item |
- menu addItem:(MenuItem label:item displayString value:[ self goTo:item ])
+ menu addItem:(MenuItem label:item displayString itemValue:[ self goTo:item ])
].
^ menu
@@ -294,16 +330,21 @@
idx ~~ 0 ifTrue:[
items removeIndex:idx.
].
- items addFirst:navigationHistoryItem.
+ self addFirst:navigationHistoryItem.
] ifFalse:[
- idx == 0 ifFalse: [
+ idx ~~ 0 ifTrue: [
+ "/ already in list
position := idx
- ] ifTrue:[
+ ] ifFalse:[
position < items size ifTrue:[
items removeFromIndex: position + 1 toIndex: items size
].
items addLast: navigationHistoryItem.
- position := position + 1
+ items size > maxNumberOfItems ifTrue:[
+ items removeFirst
+ ] ifFalse:[
+ position := position + 1
+ ].
].
].
@@ -338,11 +379,11 @@
!NavigationHistory class methodsFor:'documentation'!
version_CVS
- ^ '$Header: /cvs/stx/stx/libtool/Tools__NavigationHistory.st,v 1.14 2012-11-13 09:07:18 mb Exp $'
+ ^ '$Header: /cvs/stx/stx/libtool/Tools__NavigationHistory.st,v 1.16 2013-06-21 00:43:18 cg Exp $'
!
version_CVS_jvrany
- ^ '§Header: /opt/data/cvs/stx/goodies/libtool3/Tools__NavigationHistory.st,v 1.2 2008-02-27 13:45:21 vranyj1 Exp §'
+ ^ '$Header: /cvs/stx/stx/libtool/Tools__NavigationHistory.st,v 1.16 2013-06-21 00:43:18 cg Exp $'
!
version_HG
@@ -351,6 +392,6 @@
!
version_SVN
- ^ '§Id: Tools__NavigationHistory.st 7486 2009-10-26 22:06:24Z vranyj1 §'
+ ^ '$Id: Tools__NavigationHistory.st,v 1.16 2013-06-21 00:43:18 cg Exp $'
! !