Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Check type menuitems
Check type menuitems [message #731352] Fri, 30 September 2011 17:32 Go to next message
Missing name Missing name is currently offline Missing name Missing nameFriend
Messages: 18
Registered: September 2011
Junior Member
I've added a command that toggles a two state view preference in my app. I created a HandledMenuItem for this command and set the type to Check. I also added this to a menu and added a Handler for the command and a keybinding.

The menuitem shows up in the menu with a checkbox and the state of the check is remembered correctly. Also, my handler is called when I activate the menuitem or via the keybinding. So far so good.

Here's the problem: I need to know what the state of the check is both in my handler and in my view code that consumes this preference. But I can't figure out how to access the check state either in the handler or elsewhere.

What's the correct way to get at this info?


Re: Check type menuitems [message #732138 is a reply to message #731352] Tue, 04 October 2011 02:06 Go to previous messageGo to next message
Missing name Missing name is currently offline Missing name Missing nameFriend
Messages: 18
Registered: September 2011
Junior Member
I found an answer and it's easy of course. Just inject handler with (MMenuItem item) and call item.isSelected().
Re: Check type menuitems [message #736575 is a reply to message #731352] Fri, 14 October 2011 05:58 Go to previous messageGo to next message
Missing name Missing name is currently offline Missing name Missing nameFriend
Messages: 18
Registered: September 2011
Junior Member
Unfortunately, the answer I found is incomplete.

While it works when the handler is activated by the menuitem, it fails when it's activated by a keybinding. In the case of a keybinding activation, the MMenuItem will be not be resolved. How is the handler supposed to get at the state which the menuitem holds in this situation?

I suppose the situation gets even worse if there are multiple menuitems bound to the same handler, and with different types.
Re: Check type menuitems [message #736595 is a reply to message #736575] Fri, 14 October 2011 06:27 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
If it is a preference why don't you set one? You can get preferences
injected using @Preference("myprefvalue") in the @Execute and in views
using @Inject @Preference("myprefvalue")

Tom

Am 14.10.11 07:58, schrieb grillo321:
> Unfortunately, the answer I found is incomplete.
>
> While it works when the handler is activated by the menuitem, it fails
> when it's activated by a keybinding. In the case of a keybinding
> activation, the MMenuItem will be not be resolved. How is the handler
> supposed to get at the state which the menuitem holds in this situation?
>
> I suppose the situation gets even worse if there are multiple menuitems
> bound to the same handler, and with different types.
Re: Check type menuitems [message #909072 is a reply to message #736595] Thu, 06 September 2012 13:42 Go to previous message
Marco Descher is currently offline Marco DescherFriend
Messages: 194
Registered: October 2010
Location: Austria
Senior Member
I got that one working to synchronize from the HandledMenuItem to the Code! But how could I initialize the state of the HandledMenuItem at start given the Preference?

Or more generally, how can I set the state of a HandledMenuItem given by the state of the code at all?

Thanks!

[Updated on: Thu, 06 September 2012 14:02]

Report message to a moderator

Previous Topic:Tycho build has different runtime behavior as the Run Configuration
Next Topic:Looking for (open source) projects based on Eclipse4
Goto Forum:
  


Current Time: Thu Mar 28 13:02:22 GMT 2024

Powered by FUDForum. Page generated in 0.02965 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top