Enable/Disable pushbuttons

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Enable/Disable pushbuttons

Keith  Lander
Hi

I have a dialog in which a pushbutton should be disabled unless some
condition is true. I can see that the state of a pushbutton is somehow
linked to the dialog presenter (if there is no command method, then the
button is disabled). Is there someway I can link into this mechanism to
dynamically change the state? If not, what is the DST way of dealing with
this.

Thanks
Keith


Reply | Threaded
Open this post in threaded view
|

Re: Enable/Disable pushbuttons

Ian Bartholomew-18
Keith,

> I have a dialog in which a pushbutton should be disabled unless some
> condition is true. I can see that the state of a pushbutton is somehow
> linked to the dialog presenter (if there is no command method, then
> the button is disabled). Is there someway I can link into this
> mechanism to dynamically change the state? If not, what is the DST
> way of dealing with this.

This is done using the #queryCommand: method.  There are a lot of examples
in the image that you can browse and it has been mentioned a number of times
in this newsgroup.  A Google search or browse of the newsgroup archive
(search for queryCommand) should find more details, but ask again if you
can't locate anything.

Basically (Smalltalkally?) you provide a method called #queryCommand: that
is automatically called, at appropriate times, with each command that can be
generated by a Shell or Dialog.  You can then select whether the command
should be enabled/disabled, checked/unchecked etc. As in...

YourDialog>>queryCommand: aCommandQuery
    super queryCommand: aCommandQuery.
    aCommandQuery command == #aSymbol
        ifTrue: [aCommandQuery isEnabled: self shouldEnableASymbol]

where aSymbol is the command sent by the button (and therefore the selector
for the method that is to be executed) and shouldEnableASymbol is a method
that answers a Boolean.

--
Ian


Reply | Threaded
Open this post in threaded view
|

Re: Enable/Disable pushbuttons

Bill Schwab
In reply to this post by Keith Lander
Keith,

> I have a dialog in which a pushbutton should be disabled unless some
> condition is true. I can see that the state of a pushbutton is somehow
> linked to the dialog presenter (if there is no command method, then the
> button is disabled). Is there someway I can link into this mechanism to
> dynamically change the state? If not, what is the DST way of dealing with
> this.

Look at #queryCommand: in the image and in Ian's archives of this newsgroup.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Enable/Disable pushbuttons

Keith  Lander
Wow, that was fast. Thank's Bill.

"Bill Schwab" <[hidden email]> wrote in message
news:b3cvni$f0j$[hidden email]...
> Keith,
>
> > I have a dialog in which a pushbutton should be disabled unless some
> > condition is true. I can see that the state of a pushbutton is somehow
> > linked to the dialog presenter (if there is no command method, then the
> > button is disabled). Is there someway I can link into this mechanism to
> > dynamically change the state? If not, what is the DST way of dealing
with
> > this.
>
> Look at #queryCommand: in the image and in Ian's archives of this
newsgroup.

>
> Have a good one,
>
> Bill
>
> --
> Wilhelm K. Schwab, Ph.D.
> [hidden email]
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Enable/Disable pushbuttons

Andy Bower
In reply to this post by Keith Lander
Keith,

> I have a dialog in which a pushbutton should be disabled unless some
> condition is true. I can see that the state of a pushbutton is somehow
> linked to the dialog presenter (if there is no command method, then the
> button is disabled). Is there someway I can link into this mechanism to
> dynamically change the state? If not, what is the DST way of dealing with
> this.

As you've found out, in Dolphin you don't have to enable/disable push
buttons explicity. Instead Dolphin first sends a #commandQuery: message to
all the locations that could possibly execute the command. These locations
are determined by the default command routing policy but, at this stage, you
probably don't need to concern yourself with this level of detail. Suffice
it to say that your dialog presenter will receive one of these
#queryCommand: messages for each push button (and each menu command in your
dialog). All you need to do is to isolate whether the CommandQuery parameter
is actually for your push button and then use #isEnabled: as appropriate.
Take a look at any #queryCommand: method for examples:

e.g.

MyDialog>>queryCommand: query
    "Private - Enters details about a potential command for the receiver
into the
    <CommandQuery>, query."
    | command |
    command := query commandSymbol.
   command == #myPushButtonCommand ifTrue: [ "Your command here"
        query isEnabled: self canExecuteMyCommand. "Your test here"
        ^true].
    ^super queryCommand: query

Don't forget the supersend at the end.

A great advantage of this scheme is that it works for menu commands as well
as push buttons, i.e. you don't have to know where a command originates for
it to be enabled/disabled properly. You can also use #queryCommand: to set
whether a menu item is checked our not by using CommandQuery>>isChecked:.

Best Regards,

Andy Bower
Dolphin Support
http://www.object-arts.com
---
Are you trying too hard?
http://www.object-arts.com/Relax.htm
---


Reply | Threaded
Open this post in threaded view
|

Re: Enable/Disable pushbuttons

Ian Bartholomew-18
In reply to this post by Keith Lander
Keith,
> Wow, that was fast. Thank's Bill.

Not as fast as your reply :-)

Bills: Date: Mon, 24 Feb 2003 06:33:40 -0500
Yours: Date: Mon, 24 Feb 2003 11:32:35 -0000

--
Ian