[ENH] PluggableButtonWithArg

ducasse at iam.unibe.ch ducasse at iam.unibe.ch
Thu Feb 14 17:51:09 UTC 2002


from preamble:

"Change Set:		PluggableButtonWithArg
Date:			14 February 2002
Author:			stephane ducasse

add the possibility for a pluggableButtonMorph to pass argument to the
message sent to the one getting messaged when the button is pressed. The
logic is the following one:

The arguments passed should not be specified at button creation but at
button action time. So I was thinking passing a selector to get the
arguments. However, the arguments can be generated from another object
that the one receiving the actionSelector.

For example in the RegisteringFileList, the fileList needs to call for
example FileStream with fileIn: and passing as argument the currently
selected file. So this argument is asked to the fileList and serves as
argument of the FileStream message. So I chose to pass a block.
Furthermore, it may happen that the computation of the arguments just
failed for contextual reason (in the file list that no file is selected)
but still the action is performed. So I needed a way to cancel the
action when the arguments were not satisfactory. So I pass a block which
may return nil to cancel the arguments or should return an array.

The logic is summarized in the following method: 

performAction
    Inform the model that this button has been pressed. Sent by the
controller when this button is pressed. If the button should pass
argument, when its agrsGettingBlock is not nil, the block is evaluated
and should return an array containing the arguments passed. The block
may return nil in case of need for cancelling the action for external
reasons

    askBeforeChanging ifTrue: [model okToChange ifFalse: [^ self]].
    actionSelector ifNotNil: [
            argsGettingBlock isNil
                ifTrue: [model perform: actionSelector]
                ifFalse: [ | args| 
                        args := argsGettingBlock value.
                        args isNil ifTrue: [^ self].
                        model perform: actionSelector withArguments:
args]]


"!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PluggableButtonWithArg.cs.gz
Type: application/octet-stream
Size: 1580 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20020214/48ec4f65/PluggableButtonWithArg.cs.obj


More information about the Squeak-dev mailing list