--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Tools__NavigationHistory.st Wed Sep 23 19:03:26 2009 +0200
@@ -0,0 +1,163 @@
+"{ Package: 'cvut:stx/goodies/libtool3' }"
+
+"{ NameSpace: Tools }"
+
+Object subclass:#NavigationHistory
+ instanceVariableNames:'items position'
+ classVariableNames:''
+ poolDictionaries:''
+ category:'Interface-History'
+!
+
+!NavigationHistory class methodsFor:'documentation'!
+
+version_SVN
+ ^ '$Header: /cvs/stx/stx/libtool/Tools__NavigationHistory.st,v 1.1 2009-09-23 17:03:26 fm Exp $'
+! !
+
+!NavigationHistory class methodsFor:'instance creation'!
+
+new
+ ^ self basicNew initialize.
+
+ "Created: / 21-02-2008 / 15:26:05 / janfrog"
+! !
+
+!NavigationHistory methodsFor:'accessing'!
+
+currentItem
+
+ ^(position between:1 and: items size)
+ ifTrue:[items at: position]
+ ifFalse:[nil]
+
+ "Created: / 27-02-2008 / 08:46:37 / janfrog"
+!
+
+currentItem: anObject
+
+ self goTo: anObject
+
+ "Created: / 27-02-2008 / 08:47:04 / janfrog"
+!
+
+goBackItems
+ ^ (items copyTo:position - 1) reverse
+
+ "Created: / 27-02-2008 / 11:52:12 / janfrog"
+!
+
+goForwardItems
+ ^ items copyFrom:position + 1
+
+ "Created: / 27-02-2008 / 11:52:26 / janfrog"
+! !
+
+!NavigationHistory methodsFor:'initialization'!
+
+initialize
+ "Invoked when a new instance is created."
+
+ "/ please change as required (and remove this comment)
+ "/ items := nil.
+ "/ position := nil.
+
+ "/ super initialize. -- commented since inherited method does nothing
+ items := OrderedCollection new.
+ position := 0
+
+ "Created: / 21-02-2008 / 15:26:05 / janfrog"
+! !
+
+!NavigationHistory methodsFor:'menu & menu actions'!
+
+goBackMenu
+ |menu|
+
+ menu := Menu new.
+ self goBackItems do:[:item |
+ menu addItem:(MenuItem label:item displayString value:[ self goTo:item ])
+ ].
+ ^ menu
+
+ "Created: / 22-02-2008 / 16:57:46 / janfrog"
+ "Modified: / 27-02-2008 / 11:52:12 / janfrog"
+!
+
+goForwardMenu
+ |menu|
+
+ menu := Menu new.
+ self goForwardItems do:[:item |
+ menu addItem:(MenuItem label:item displayString value:[ self goTo:item ])
+ ].
+ ^ menu
+
+ "Created: / 22-02-2008 / 16:58:11 / janfrog"
+ "Modified: / 27-02-2008 / 11:52:26 / janfrog"
+! !
+
+!NavigationHistory methodsFor:'navigation'!
+
+goBack
+
+ | value |
+ position := (position - 1) max: 1.
+ self changed: #currentItem with: (value := self currentItem).
+ ^value
+
+ "Created: / 21-02-2008 / 16:37:37 / janfrog"
+ "Modified: / 27-02-2008 / 08:48:14 / janfrog"
+!
+
+goForward
+
+ | value |
+ position := (position + 1) min: items size.
+ self changed: #currentItem with: (value := self currentItem).
+ ^value
+
+ "Created: / 21-02-2008 / 16:37:37 / janfrog"
+ "Modified: / 27-02-2008 / 08:48:24 / janfrog"
+!
+
+goTo: navigationHistoryItem
+
+ | idx |
+ idx := items indexOf:navigationHistoryItem.
+ idx isZero
+ ifFalse:
+ [position := idx]
+ ifTrue:
+ [position < items size ifTrue:
+ [items removeFromIndex: position + 1 toIndex: items size].
+ items addLast: navigationHistoryItem.
+ position := position + 1].
+ self changed: #value with: navigationHistoryItem.
+ ^navigationHistoryItem
+
+ "Created: / 21-02-2008 / 16:40:39 / janfrog"
+ "Modified: / 21-02-2008 / 19:12:35 / janfrog"
+! !
+
+!NavigationHistory methodsFor:'queries'!
+
+canGoBack
+
+ ^position > 1
+
+ "Created: / 21-02-2008 / 16:40:48 / janfrog"
+!
+
+canGoForward
+
+ ^position < items size
+
+ "Created: / 21-02-2008 / 16:40:48 / janfrog"
+! !
+
+!NavigationHistory class methodsFor:'documentation'!
+
+version
+ ^ '$Header: /cvs/stx/stx/libtool/Tools__NavigationHistory.st,v 1.1 2009-09-23 17:03:26 fm Exp $'
+! !