[ENH] PluggableButton Tweak

ducasse ducasse at iam.unibe.ch
Thu Feb 14 17:47:48 UTC 2002


on 14/02/02 9:21 AM, Bijan Parsia at bparsia at email.unc.edu wrote:

> from preamble:
> 
> "Change Set:        PluggableButton Tweak
> Date:            14 February 2002
> Author:            Bijan Parsia
> 
> Adds the ability to have actions with arguments. I didn't test the View
> at all, but the code is exactly the same in both.
> 
> PluggableButtonView>>performAction didn't have the askBeforeChanging
> test. That should probably go in no matter what.
> 
> Oh, this recompiled both PluggableButton classes."!
> 

Hi Bijan

My solution is like that

performAction
    "Inform the model that this button has been pressed. Sent by the
controller when this button is pressed."

    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]]

Because what I need is the button that can perform action on another object
and pass arguments to this object. However the arguments should not be
specified at button creation but at button click. 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 I need 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
messages. So I chose to passa 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.

Stef









More information about the Squeak-dev mailing list