ApplicationCommandListener


#1

Hello JUCErs,

I have registered a button to listen to my ApplicationCommandManager in order to synchronize the toggle state of the button with a command which can also be invoked by a key command. In the applicationCommandListChanged() method, I had a hell of a time figuring out how to get the up-to-date status of the command. Here’s what I ended up with:

ApplicationCommandInfo cmdInfo(AppCommandIDs::globalDisable); getCommandManager()->getTargetForCommand(AppCommandIDs::globalDisable, cmdInfo);

That seems unusually oblique for JUCE… is there an easier way that I am overlooking? I tried using getCommandForID() but the resulting ApplicationCommandInfo is not up to date, since invoking the command disabled it until the globalEnable command is invoked.

Oh well, it works at least. It’s just not as pretty as I’m used to, and that’s meant as a compliment :smiley:


#2

It’s not that bad! It’s actually a tough method to run, because to get the info, it needs to go off, find the current target, and ask it to fill in all the details. It fills in your own structure, rather than returning its cached one, because the cached one could change while you’re using it. I guess there could be a convenience method that does the same thing with a different name and doesn’t return a target, but it’d only be a wrapper on this method.


#3

OK, well in that case, I’m glad that I apparently hit on the correct way of doing it!

Perhaps this could use a mention in the documentation of getCommandForID() , which really seems like it should do the job, but doesn’t.


#4

[quote=“scooper72”]

Perhaps this could use a mention in the documentation of getCommandForID() , which really seems like it should do the job, but doesn’t.[/quote]

Gotta agree with that. IIRC, I resorted to looking at how the button class handled toggle state to work out how to do stuff like this.