How to show a check mark for a dynamically generated menu item?

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

How to show a check mark for a dynamically generated menu item?

Bernhard Kohlhaas-3
Hello,

I am generating a menu dynamically in the #onAboutToDisplayMenu: method
and would like to add check mark to certain menu items.

The problem is that the #queryCommand: method of my shell is only called
for the menu name itself, but not for each menu item. (See below for my
coding in those two methods).

How can I enable check marks for the menu items?

Bernhard


queryCommand: aCommandQuery


(aCommandQuery command == #drives) ifTrue: [
        aCommandQuery isEnabled: true. ^true.
].
self halt.
(aCommandQuery command == #toggleDriveMonitoring: )
        ifTrue: [ aCommandQuery checked: true. ^true ].

super queryCommand: aCommandQuery




MyShell>>onAboutToDisplayMenu: aMenu

super onAboutToDisplayMenu: aMenu.
aMenu name == #drives ifTrue: [
        aMenu clear.
        File drives do: [ :eachDrive |
                (aMenu
                        addCommand: (MessageSend
                                receiver: self
                                selector: #toggleDriveMonitoring:
                                argument: eachDrive )
                        description: eachDrive).
        ]
].

--
(This email address is only temporarily valid, due to the heavy amount
of spam a post generates. For a permanently valid email address, just
remove all numerical digits from the address.)


Reply | Threaded
Open this post in threaded view
|

Re: How to show a check mark for a dynamically generated menu item?

Chris Uppal-3
Bernhard Kohlhaas wrote:

> (aCommandQuery command == #toggleDriveMonitoring: )
> ifTrue: [ aCommandQuery checked: true. ^true ].

Try:

     (aCommandQuery command asSymbol == #toggleDriveMonitoring: )

the result of #command is the MessageSend you created in the menu creation
code.

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: How to show a check mark for a dynamically generated menu item?

Bernhard Kohlhaas-3
Chris,

the breakpoint before this statement isn't even reached, so the
queryCommand: method isn't invoked at all.

Bernhard

Chris Uppal wrote:

> Bernhard Kohlhaas wrote:
>
>
>>(aCommandQuery command == #toggleDriveMonitoring: )
>>ifTrue: [ aCommandQuery checked: true. ^true ].
>
>
> Try:
>
>      (aCommandQuery command asSymbol == #toggleDriveMonitoring: )
>
> the result of #command is the MessageSend you created in the menu creation
> code.
>
>     -- chris
>
>

--
(This email address is only temporarily valid, due to the heavy amount
of spam a post generates. For a permanently valid email address, just
remove all numerical digits from the address.)


Reply | Threaded
Open this post in threaded view
|

Re: How to show a check mark for a dynamically generated menu item?

Chris Uppal-3
In reply to this post by Chris Uppal-3
I wrote:

>      (aCommandQuery command asSymbol == #toggleDriveMonitoring: )

I forgot to mention that CommandQuery>>command can sometimes answer nil.  It's
sporadic, and I've never been able to find a reproducible example, so I don't
know whether it's actually a bug or a feature.  I just put an early #isNil test
into #queryCommand: implementations where I'm using #asSymbol.

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: How to show a check mark for a dynamically generated menu item?

Chris Uppal-3
In reply to this post by Bernhard Kohlhaas-3
Bernhard,
>
> the breakpoint before this statement isn't even reached, so the
> queryCommand: method isn't invoked at all.

Ah, right.

I think that may be because you are using a MessageSend rather than a Message.

Since MessageSends "know" what their receiver is, the command framework will
try their #queryCommand: before that of the Presenter, and I suspect (without
having worked out the details) that that is what's going wrong for you.

If you use a Message, then the framework will still assume that the intended
receiver of the command is the MVP component and will use your Presenter's
#queryCommand.

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: How to show a check mark for a dynamically generated menu item?

Ian Bartholomew-18
In reply to this post by Chris Uppal-3
Chris,


> I forgot to mention that CommandQuery>>command can sometimes answer
> nil.  It's sporadic, and I've never been able to find a reproducible
> example, so I don't know whether it's actually a bug or a feature.  I
> just put an early #isNil test into #queryCommand: implementations
> where I'm using #asSymbol.

Just FYI, CommandQuery>>commandSymbol automatically does a nil check for
you.

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: How to show a check mark for a dynamically generated menu item?

Bernhard Kohlhaas-3
In reply to this post by Chris Uppal-3
That was indeed the problem. It works now with a Message instead of a
MessageSend.

Thanks so much,

Bernhard


Chris Uppal wrote:

> Bernhard,
>
>>the breakpoint before this statement isn't even reached, so the
>>queryCommand: method isn't invoked at all.
>
>
> Ah, right.
>
> I think that may be because you are using a MessageSend rather than a Message.
>
> Since MessageSends "know" what their receiver is, the command framework will
> try their #queryCommand: before that of the Presenter, and I suspect (without
> having worked out the details) that that is what's going wrong for you.
>
> If you use a Message, then the framework will still assume that the intended
> receiver of the command is the MVP component and will use your Presenter's
> #queryCommand.
>
>     -- chris
>
>
>

--
(This email address is only temporarily valid, due to the heavy amount
of spam a post generates. For a permanently valid email address, just
remove all numerical digits from the address.)


Reply | Threaded
Open this post in threaded view
|

Re: How to show a check mark for a dynamically generated menu item?

Chris Uppal-3
In reply to this post by Ian Bartholomew-18
Ian,

> Just FYI, CommandQuery>>commandSymbol automatically does a nil check for
> you.

Useful.  Thank you.

    -- chris