How to change the text on a push button at run time ?

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

How to change the text on a push button at run time ?

Joseph Frippiat-2
I have a view with a presenter for a boolean value and a push button to
toggle it.

I want that the text on the button change in function of the boolean:
when the value is true, I want the text on the button to be 'Open' and
when the value is false I want it to be 'Close'.

How to do that ?  As I don't create a component for the button, I don't
have access to it (I tried to create a PushButton component but I got an
error :-) ... )

Thanks,

Joseph


Reply | Threaded
Open this post in threaded view
|

Re: How to change the text on a push button at run time ?

Ian Bartholomew-21
Joseph,

> How to do that ?  As I don't create a component for the button, I don't
> have access to it (I tried to create a PushButton component but I got an
> error :-) ... )

Use the #queryCommand: method.  You've probably only used that to
enable/disable the button but you can also use it to change the text.
Something like (completely untested)

MyPresenter>>queryCommand: aCommandQuery
aCommandQuery commandSymbol == #openOrClose
ifTrue: [
        aCommandQuery text: (
                self isClosed
                        ifTrue: ['Open']
                        ifFalse: ['Close']).
        ^true]

There are some examples in the image. Search for senders of #text: from
within #queryCommand methods.

--
Ian

Use the Reply-To address to contact me (limited validity).
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: How to change the text on a push button at run time ?

Joseph Frippiat-2
Ian Bartholomew a écrit :
[..]
> MyPresenter>>queryCommand: aCommandQuery
> aCommandQuery commandSymbol == #openOrClose
> ifTrue: [
>     aCommandQuery text: (
>         self isClosed
>             ifTrue: ['Open']
>             ifFalse: ['Close']).
>     ^true]
[..]

It's working!
I had to remove the "^true" or the button was inactive.

Thanks,

Joseph


Reply | Threaded
Open this post in threaded view
|

Re: How to change the text on a push button at run time ?

Ian Bartholomew-21
Joseph,

> It's working!
> I had to remove the "^true" or the button was inactive.

Ah yes, that could well be the case.  Rather than using the default
processing changing the code to enable the button yourself would
probably be the best way to go ...

MyPresenter>>queryCommand: aCommandQuery
aCommandQuery commandSymbol == #openOrClose
ifTrue: [
     aCommandQuery
         beEnabled;
         text: (
             self isClosed
                 ifTrue: ['Open']
                 ifFalse: ['Close']).
     ^true]

--
Ian

Use the Reply-To address to contact me (limited validity).
Mail sent to the From address is ignored.