Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Edit menu options do not get enabled for all views
Edit menu options do not get enabled for all views [message #333487] Mon, 15 December 2008 12:12 Go to next message
Prasanna K is currently offline Prasanna KFriend
Messages: 78
Registered: July 2009
Member
I have three views in my plug-in.
I want to make available Edit menu options (cut / copy / paste) to the
user based on current selection.

I have written a method called initializeEditOptions() in a class that is
not a view nor an editor. This method gets called only when each of the
three views of my perspective is up.
It has the code to initialize copy / cut / paste Action variables like :

public void initializeEditOptions() {
// create actions for edit menu options
copyEAction = new org.eclipse.jface.action.Action() {
@Override
public void run() {
//copy stuff
super.run();
}
};

// similarly for cut and paste

// code to create actionBars
final IActionBars[] actionBars = new IActionBars[1];
Display display = Display.getDefault();
display.syncExec(new Runnable() {
@Override
public void run() {
IWorkbenchPartSite site =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().getActivePart().getSite();
if(site instanceof IViewSite)
actionBars[0] = (IViewSite)site).getActionBars();
else if (site instanceof IEditorSite)
actionBars[0] = ((IEditorSite)site).getActionBars();
}
});

actionBars[0].setGlobalActionHandler(ActionFactory.COPY.getI d(),
copyEAction);
copyEAction.setEnabled(false);
// similarly for copy and paste
}

There is a different method called updateMenus() in which I set enable
property of cut / copy actions to true based on some conditions and
selections.

The edit menu options get enabled only when a certain view (among three)
becomes the active part and not when the other views are active.

What could be the problem and how do I solve this?
Re: Edit menu options do not get enabled for all views [message #333501 is a reply to message #333487] Mon, 15 December 2008 19:41 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

kaprasi wrote:
> I have three views in my plug-in.
> I want to make available Edit menu options (cut / copy / paste) to the
> user based on current selection.
>
> I have written a method called initializeEditOptions() in a class that
> is not a view nor an editor. This method gets called only when each of
> the three views of my perspective is up.
> It has the code to initialize copy / cut / paste Action variables like :
>
> public void initializeEditOptions() {

> }
>
> There is a different method called updateMenus() in which I set enable
> property of cut / copy actions to true based on some conditions and
> selections.
>
> The edit menu options get enabled only when a certain view (among three)
> becomes the active part and not when the other views are active.
>
> What could be the problem and how do I solve this?

How many times is that method called? Basically, you are registering
your actions for 1 part, ....getActivePage().getActivePart().getSite()

If you really want to use 3 common handlers for the different views,
activate the handler for the command when the view is created:

initialize(IViewPart part) {
IHandlerService hs = (IHandlerService)
part.getSite().getService(IHandlerService.class);
hs.activateHandler("org.eclipse.ui.edit.copy", commonCopyHandler);
hs.activateHandler("org.eclipse.ui.edit.cut", commonCutHandler);
// etc
}

IHandlers support setEnabled(true/false) and as long as they fire the
change event (usually subclasses off of AbstractHandler) they will
update the commands correctly.

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:rcp and plugin startup code
Next Topic:How to enable debug in plugin
Goto Forum:
  


Current Time: Thu Jul 18 03:41:20 GMT 2024

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

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

Back to the top