Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » editor actions that do not disable?
editor actions that do not disable? [message #296878] Tue, 03 January 2006 22:40 Go to next message
Eclipse UserFriend
Hi there,

I was wondering if there is any know good way to make editor actions
(org.eclipse.ui.editorActions) which do not automatically disable when a
view part is activated?

The idea is that I want to add a document-specific menu to the top-level
menu. This menu should only appear when the active editor is of the right
type (which is why I'm using the editorAction extension). However, when a
view, such as Outline or Navigator is activated, I still want all of the
document menu items to be enabled. Currently, the Eclipse implementation is
to always disable menu actions when the editor is deactivated ... I'd rather
that it disable the menu only if getActiveEdtor() returns null.

Any suggestions are welcome!

Thanks
Damian
Re: editor actions that do not disable? [message #296905 is a reply to message #296878] Wed, 04 January 2006 08:43 Go to previous messageGo to next message
Eclipse UserFriend
Another possible way:

Use an actionSet for your actions. Add an IPartListener2 to the
IWorkbenchPage, so you can listen for part activation events. Then you
can check the active editor, and use IWorkbenchPage#showActionSet(*) and
IWorkbenchPage#hideActionSet(*) to show and hide the actions.

Later,
PW
Re: editor actions that do not disable? [message #549869 is a reply to message #296878] Wed, 28 July 2010 05:40 Go to previous message
Eclipse UserFriend
Another possibility is to implement a EditorActionBarContributor which contributes your menu and or toolbar actions when your editor is active.

Within this EditorActionBarContributor, implement the contributeToMenu(IMenuManager menuManager)
like the the following:

    public void contributeToMenu(IMenuManager menubar) {
        
        MenuManager manager = new MenuManager("My Menu");
        manager.setRemoveAllWhenShown(true);//must be set true when the menu manger is dynamically filled
        manager.setOverrides(new IContributionManagerOverrides(){
            public Integer getAccelerator(IContributionItem item) {
                return null;
                
            }
            
            public String getAcceleratorText(IContributionItem item) {
                return null;
                
            }

            public Boolean getEnabled(IContributionItem item) {
                return Boolean.TRUE;
            }

            public String getText(IContributionItem item) {
                return null;
                
            }

            public Boolean getVisible(IContributionItem item) {
                return null;
            }
            
        });
        menubar.insertAfter(IWorkbenchActionConstants.MB_ADDITIONS, manager);
}

Note: some action need to be added to see the effect Smile

By setting a custom IContributionManagerOverrides implemented class to your menu manager,
you have the ability to decide if the menu manager contents should be enabled or not.
If this is not set, your menu manager will use IContributionManagerOverrides implemented class of its parent,
which disables your actions at the moment when your editor is not selected.
Previous Topic:Use double quote in External tool
Next Topic:modifying icons for launch config entries
Goto Forum:
  


Current Time: Wed Jul 23 13:16:14 EDT 2025

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

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

Back to the top