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.) |
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 |
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.) |
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 |
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 |
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. |
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.) |
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 |
Free forum by Nabble | Edit this page |