Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Enable/Disable plugin.xml generated menus
Enable/Disable plugin.xml generated menus [message #336638] Thu, 25 June 2009 16:32 Go to next message
Javier Der Derian is currently offline Javier Der DerianFriend
Messages: 2
Registered: July 2009
Junior Member
Hi!

This is my first email to this list.
I'm working on qbzr-eclipse, a plugin to integrate qbzr [
http://bazaar-vcs.org/QBzr ] with eclipse.

Right now I'm working on refectoring the main qbzr-eclipse menu, which
used to be just a long plain menu. Now it's divided in submenus.
What I need to do now is to enable/disable some menuitems according to one
simple variable: the selected project is versioned in bazaar [
http://bazaar-vcs.org/ ] or not.

I've tried like 20 ways of doing this...but I can't find a way to actually
access the menuitem from inside the plugin's code. None of the examples I
found on the web helped me =(

ANY input on how to do this would be great, I have no problem on
refactoring the code I've already written.


Thanks!
Re: Enable/Disable plugin.xml generated menus [message #336640 is a reply to message #336638] Thu, 25 June 2009 18:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: christopher.oezbek.fu-berlin.de

Hi Javier,

> What I need to do now is to enable/disable some menuitems according to
> one simple variable: the selected project is versioned in bazaar [
> http://bazaar-vcs.org/ ] or not.
>
> I've tried like 20 ways of doing this...but I can't find a way to
> actually access the menuitem from inside the plugin's code.

How about doing it the other way around: In the associated action of the
menuitem you set the action to enabled/disabled.

For instance we have a action directly in the popup menu for IResources

<extension
point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
id="de.fu_berlin.inf.dpp.ui.popupmenu"
objectClass="org.eclipse.core.resources.IResource">
....
<action
class="de.fu_berlin.inf.dpp.ui.actions.NewSessionAction"
icon="icons/transmit.png"
id="Saros.action1"
label="Share project...">
</action>

In the NewSessionAction, we then enable/disable based on the selection:

public class NewSessionAction implements IObjectActionDelegate {
....
public void selectionChanged(IAction action, ISelection selection) {
// Set to enabled if not already in a session
action.setEnabled(getProject(selection) == null);
}
....

Hope this helps,
Christopher
Re: Enable/Disable plugin.xml generated menus [message #336643 is a reply to message #336640] Thu, 25 June 2009 19:57 Go to previous messageGo to next message
Javier Der Derian is currently offline Javier Der DerianFriend
Messages: 2
Registered: July 2009
Junior Member
> Hi Javier,
Hi!
>> What I need to do now is to enable/disable some menuitems according to
>> one simple variable: the selected project is versioned in bazaar [
>> http://bazaar-vcs.org/ ] or not.
>>
>> I've tried like 20 ways of doing this...but I can't find a way to
>> actually access the menuitem from inside the plugin's code.

> How about doing it the other way around: In the associated action of the
> menuitem you set the action to enabled/disabled.

> For instance we have a action directly in the popup menu for IResources

> <extension
> point="org.eclipse.ui.popupMenus">
> <objectContribution
> adaptable="true"
> id="de.fu_berlin.inf.dpp.ui.popupmenu"
> objectClass="org.eclipse.core.resources.IResource">
> ....
> <action
> class="de.fu_berlin.inf.dpp.ui.actions.NewSessionAction"
> icon="icons/transmit.png"
> id="Saros.action1"
> label="Share project...">
> </action>

> In the NewSessionAction, we then enable/disable based on the selection:

> public class NewSessionAction implements IObjectActionDelegate {
> ....
> public void selectionChanged(IAction action, ISelection selection) {
> // Set to enabled if not already in a session
> action.setEnabled(getProject(selection) == null);
> }
> ....

> Hope this helps,
> Christopher


That sounds like a very simple solution.
My "problem" is that i'm actually using commands and handlers, not actions.
IE:
<handler
class="org.bazaar_vcs.qbzr_eclipse.handlers.InitCommandHandler "
commandId="qbzr_eclipse.commands.initCommand">
</handler>
is the handler
and then

<command
commandId="qbzr_eclipse.commands.initCommand"
icon="icons/init.png"
id="qbzr_eclipse.menus.initCommand"
mnemonic="I"
>

Is the command.

Any Idea how to move forward from here?
Re: Enable/Disable plugin.xml generated menus [message #336648 is a reply to message #336643] Fri, 26 June 2009 05:08 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
Javier Der Derian wrote:

> My "problem" is that i'm actually using commands and handlers, not actions.

Good, then you can use the activeWhen of the handlers. When there are
no active handlers, then the command will be disabled.

See: http://wiki.eclipse.org/Platform_Command_Framework

- Prakash
---
http://blog.eclipse-tips.com
Re: Enable/Disable plugin.xml generated menus [message #336669 is a reply to message #336638] Fri, 26 June 2009 15:24 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

When your project is versioned under qbzr, you should set a property on
the project.

Then you can use your visibleWhen to test that property. There is an
objectContribution example at
http://wiki.eclipse.org/Menu_Contributions/IFile_objectContr ibution

http://wiki.eclipse.org/Command_Core_Expressions#Property_Te sters has a
list of property tester, including one that can work on a persistent
property on a project.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Previous Topic:Eclipse 3.5M6 Update behind proxy not working anymore
Next Topic:WHere to download releng basebuilder for 3.4.2
Goto Forum:
  


Current Time: Fri Apr 19 07:22:15 GMT 2024

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

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

Back to the top