Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 391481 - Contributing perspectiveExtension, hiddenMenuItem removes a menu from multiple perspectives
Summary: Contributing perspectiveExtension, hiddenMenuItem removes a menu from multipl...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.3 M7   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-09 16:13 EDT by Dobrin Alexiev CLA
Modified: 2013-05-20 07:12 EDT (History)
5 users (show)

See Also:


Attachments
Sample project showing the issue (5.15 KB, application/x-zip-compressed)
2012-10-09 16:13 EDT, Dobrin Alexiev CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dobrin Alexiev CLA 2012-10-09 16:13:12 EDT
Created attachment 222083 [details]
Sample project showing the issue

I noticed a problem in the perspective contributions, particularly perspectiveExtension, hiddenMenuItem, when I tried updating our product to Eclipse 4.2. 
  
I define two perspectives. 
I want one menu removed from one of the perspective. That works. 
The problem is that the menu is also removed from the other perspective. 
  
Is this a known issue? If so, it is planned to be addressed and when? 
  
I attached a small project demonstration the issues, and here are the steps to reproduce it: 
Import the attached plugin project in Eclipse 4.2 SDK. 
Start a launch configuration that clears the workspace. 
Open “My Edit Perspective” – see the “Run/Resume” menu is not there as expected by the contribution. 
Open “My Debug Perspective” – see the “Run/Resume” menu is not there. 
That is not what I expected. I only specified the menu to be removed from “My Edit Perspective”, not from “My Debug Perspective”. 
  
Thanks 
Dobrin
Comment 1 Eric Moffatt CLA 2012-10-10 09:18:44 EDT
Thanks Dobrin. I took a quick look yesterday and it appears that I can get it to either appear or not on both depending on the order that I open the perspectives in. If I open the MyDebugPerspective first then it's always there.

I've also verified that we only call the ModeledageLayout#addHiddenMenuItemId for the 'Edit' perspective so I'm not really sure what's up...
Comment 2 Dobrin Alexiev CLA 2012-10-12 11:13:36 EDT
Out of curiosity: If we remove the check for isDynamic() in MenuManager#update(boolean, boolean)  (line 790) the bug seems to disappear.  
But again, I have little understanding of the code at this moment.
Comment 3 Patrick Chuong CLA 2013-02-26 11:40:28 EST
I debug this issue by comparing 4.x with 3.8, it looks like the top level menu wasn't rebuild on perspective activation.
I put back the code from 3.8 to rebuild the menu manager in WorkbenchWindow and it seems to resolved this issue.

Here is what I did. Is this the correct fix for this issue?

firePerspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
    IMenuManager windowManager = ((WorkbenchPage)page).getActionBars().getMenuManager();
    allowUpdates(windowManager);
    windowManager.update(false);

    UIListenerLogging.logPerspectiveEvent(this, page, perspective, UIListenerLogging.PLE_PERSP_ACTIVATED);
    perspectiveListeners.firePerspectiveActivated(page, perspective);
}

private void allowUpdates(IMenuManager menuManager) {
    menuManager.markDirty();
    final IContributionItem[] items = menuManager.getItems();
    for (int i = 0; i < items.length; i++) {
        if (items[i] instanceof IMenuManager) {
            allowUpdates((IMenuManager) items[i]);
        } else if (items[i] instanceof SubContributionItem) {
            final IContributionItem innerItem = ((SubContributionItem) items[i]).getInnerItem();
            if (innerItem instanceof IMenuManager) {
                allowUpdates((IMenuManager) innerItem);
            }
        }
    }
}
Comment 4 Paul Webster CLA 2013-04-04 12:55:57 EDT
(In reply to comment #3)
> I debug this issue by comparing 4.x with 3.8, it looks like the top level
> menu wasn't rebuild on perspective activation.
> I put back the code from 3.8 to rebuild the menu manager in WorkbenchWindow
> and it seems to resolved this issue.
> 
> Here is what I did. Is this the correct fix for this issue?

The fix doesn't look like it will hurt anything (it's just marking the hierarchy dirty and that won't matter until the menus are shown).

If it solves the problem, that might be it.

See http://wiki.eclipse.org/Platform_UI/How_to_Contribute for submitting changes through Gerrit:  http://git.eclipse.org/r/

PW
Comment 5 Patrick Chuong CLA 2013-04-05 15:58:25 EDT
Thanks Paul. 

I have pushed to Gerrit - https://git.eclipse.org/r/#/c/11694/
Comment 7 Dave Nice CLA 2013-04-12 10:18:20 EDT
Has this made it into a build, yet?
Comment 8 Paul Webster CLA 2013-04-12 10:24:19 EDT
It should be in http://download.eclipse.org/eclipse/downloads/drops4/I20130409-0900/

It might not help your bug which mentions hiddenToolItems, but the fix should be similar.

PW
Comment 9 Paul Webster CLA 2013-05-17 10:46:34 EDT
Patrick, does this work for you now in the latest 4.3 builds?

PW
Comment 10 Daniel Rolka CLA 2013-05-20 07:12:19 EDT
Verified in the build: I20130516-2200