ViewWithAcceptAndCancelBar.st
author Claus Gittinger <cg@exept.de>
Thu, 10 Feb 2011 22:53:19 +0100
changeset 9760 095b379e7a43
parent 8842 a2fc5fdbd5ae
child 10919 5b83c014a5ae
permissions -rw-r--r--
added: #nameFilter:

"
 COPYRIGHT (c) 2006 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libtool' }"

SimpleView subclass:#ViewWithAcceptAndCancelBar
	instanceVariableNames:'slaveView bar reallyModifiedHolder acceptAction cancelAction
		compareAction'
	classVariableNames:''
	poolDictionaries:''
	category:'Views-Basic'
!

SimpleView subclass:#AcceptAndCancelBar
	instanceVariableNames:'acceptButton cancelButton compareButton'
	classVariableNames:''
	poolDictionaries:''
	privateIn:ViewWithAcceptAndCancelBar
!

Button subclass:#ButtonWithHelpText
	instanceVariableNames:'helpText'
	classVariableNames:''
	poolDictionaries:''
	privateIn:ViewWithAcceptAndCancelBar::AcceptAndCancelBar
!

!ViewWithAcceptAndCancelBar class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2006 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    experimental - self like accept/cancel bar in the browsers
    code view.
    Enable with:
         UserPreferences current showAcceptCancelBarInBrowser:true
"
! !

!ViewWithAcceptAndCancelBar methodsFor:'accessing'!

acceptAction:something
    acceptAction := something.
!

cancelAction:something
    cancelAction := something.
!

compareAction:something
    compareAction := something.
!

reallyModifiedHolder:aValueHolder
    reallyModifiedHolder := aValueHolder.
    reallyModifiedHolder addDependent:self.
!

scrolledView
    "for protocol compatibility"

    ^ slaveView scrolledView
! !

!ViewWithAcceptAndCancelBar methodsFor:'action'!

accept
    acceptAction value
!

cancel
    cancelAction notNil ifTrue:[
        cancelAction value
    ]
!

compare
    compareAction notNil ifTrue:[
        compareAction value
    ]
! !

!ViewWithAcceptAndCancelBar methodsFor:'change & update'!

hideBar
    bar unmap.
    bar hiddenOnRealize:true.
    slaveView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
!

showBar
    slaveView origin:(20 @ 0.0) corner:(1.0 @ 1.0).
    bar hiddenOnRealize:false.
    bar realize.
!

update:something with:aParameter from:changedObject
    |app|

    slaveView notNil ifTrue:[
        changedObject == reallyModifiedHolder ifTrue:[
            (app := self application) notNil ifTrue:[
                app
                    enqueueMessage:#updateBarVisibility
                    for:self 
                    arguments:#().
            ].
        ].

        changedObject == slaveView modifiedChannel ifTrue:[
            (app := self application) notNil ifTrue:[
                app
                    enqueueMessage:#updateBarVisibility
                    for:self 
                    arguments:#().
            ].
        ].
    ].
    super update:something with:aParameter from:changedObject

    "Modified: / 18-09-2006 / 22:46:49 / cg"
!

updateBarVisibility
    |modified|

     modified := reallyModifiedHolder notNil 
                ifTrue:[ reallyModifiedHolder value ]
                ifFalse:[ slaveView modifiedChannel value ].

    modified ifTrue:[
        self showBar
    ] ifFalse:[
        self hideBar
    ].
! !

!ViewWithAcceptAndCancelBar methodsFor:'initialization'!

initialize
    super initialize.

    bar := AcceptAndCancelBar in:self.
    bar origin:(0.0 @ 0.0) corner:(20 @ 1.0).
    bar hiddenOnRealize:true.

    bar acceptButton action:[ self accept ].
    bar cancelButton action:[ self cancel ].
    bar compareButton action:[ self compare ].

    acceptAction := [ slaveView notNil ifTrue:[ slaveView accept ] ].
    cancelAction := [  ].

    "
     self new open
    "
!

slaveView:aView
    self add:aView.
    slaveView := aView.
    aView origin:(0.0@0.0) corner:(1.0@1.0).
    aView modifiedChannel addDependent:self.

    "
     |v|

     v := self new.
     v slaveView:CodeView new.
     v open
    "
! !

!ViewWithAcceptAndCancelBar::AcceptAndCancelBar methodsFor:'accessing'!

acceptButton
    ^ acceptButton
!

cancelButton
    ^ cancelButton
!

compareButton
    ^ compareButton
! !

!ViewWithAcceptAndCancelBar::AcceptAndCancelBar methodsFor:'help'!

flyByHelpTextAt:srcPoint
    "return the helpText for aPoint (i.e. when mouse-pointer is moved over an item)."

    (acceptButton bounds containsPoint:srcPoint) ifTrue:[
        ^ 'Accept'
    ].
    (cancelButton bounds containsPoint:srcPoint) ifTrue:[
        ^ 'Cancel'
    ].
    (compareButton bounds containsPoint:srcPoint) ifTrue:[
        ^ 'Compare against Original'
    ].
    ^ nil
! !

!ViewWithAcceptAndCancelBar::AcceptAndCancelBar methodsFor:'initialization'!

initialize
    super initialize.

    acceptButton := ButtonWithHelpText new.
    acceptButton origin:0.0 @ 0.0 corner:1.0@0.7.
    acceptButton backgroundColor:Color green.
    acceptButton flyByHelpText:'Accept'.
    self add:acceptButton.

    cancelButton := ButtonWithHelpText new.
    cancelButton origin:0.0 @ 0.7 corner:1.0@0.9.
    cancelButton backgroundColor:Color red.
    cancelButton flyByHelpText:'Cancel'.
    self add:cancelButton.

    compareButton := ButtonWithHelpText new.
    compareButton origin:0.0 @ 0.9 corner:1.0@1.0.
    compareButton backgroundColor:Color yellow.
    compareButton flyByHelpText:'Compare against Original'.
    compareButton label:'?'.
    self add:compareButton.

    "
     AcceptAndCancelBar new open
    "
! !

!ViewWithAcceptAndCancelBar::AcceptAndCancelBar::ButtonWithHelpText methodsFor:'accessing'!

flyByHelpText
    ^ helpText
!

flyByHelpText:something
    helpText := something.
! !

!ViewWithAcceptAndCancelBar class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libtool/ViewWithAcceptAndCancelBar.st,v 1.8 2009-10-01 16:23:57 cg Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/libtool/ViewWithAcceptAndCancelBar.st,v 1.8 2009-10-01 16:23:57 cg Exp $'
! !