Remove Import menu item [message #1275014] |
Sat, 22 March 2014 06:34  |
Eclipse User |
|
|
|
I am maintaining a large Eclipse 4 project (which I did not write) where it turns out that the File/Import menu item is extremely dangerous, so I need to remove it.
I can do this by hand from the running project using Window/Customize Perspective so I know it is possible, but I need to get the same effect automatically each time the project starts.
I have searched for articles about this and have found several that give extremely complicated or esoteric methods (which I have been unable to get to work), or reference things that seem to be suggestions for future changes to Eclipse.
In there a straightforward way to remove a menu item by program?
I am by no means an expert in Eclipse.
|
|
|
Re: Remove Import menu item [message #1288423 is a reply to message #1275014] |
Tue, 08 April 2014 10:47  |
Eclipse User |
|
|
|
I have found a way of doing this.
private void hideMenu(MenuManager M, String main, String sub) {
IContributionItem item = M.find(main);
if (item != null) {
MenuManager S = (MenuManager)item;
item = S.find(sub);
if (item != null) item.setVisible(false);
}
}
private void removeMenuItems() {
IWorkbenchWindow window = Workbench.getInstance().getActiveWorkbenchWindow();
if (window instanceof WorkbenchWindow) {
WorkbenchWindow WW = (WorkbenchWindow) window;
MenuManager menuManager = WW.getMenuManager();
hideMenu(menuManager, "file", "import");
...
It works, but comes up with a bunch of 'Discouraged access' warnings.
After a lot of internet searching I am still trying to find out exactly what they mean and how to get rid of them.
I am from the old school of programming where all warnings should be treated as errors, so simply turning them off is anathema.
|
|
|
Powered by
FUDForum. Page generated in 0.03136 seconds