Tools__NavigationHistory.st
author Claus Gittinger <cg@exept.de>
Sun, 30 Jan 2011 10:56:43 +0100
changeset 9722 14be18de210f
parent 8818 ffb1e1c2215f
child 9989 e1478a1b9495
permissions -rw-r--r--
care for metaClass in class wizard

"{ Package: 'cvut:stx/goodies/libtool3' }"

"{ NameSpace: Tools }"

Object subclass:#NavigationHistory
	instanceVariableNames:'items position'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-History'
!


!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.3 2009-09-30 12:09:44 fm Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/libtool/Tools__NavigationHistory.st,v 1.3 2009-09-30 12:09:44 fm 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 '
! !