| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com> |
| 3 |
* |
| 4 |
* This program and the accompanying materials are made available |
| 5 |
* under the terms of the Eclipse Public License v1.0 |
| 6 |
* which accompanies this distribution, and is available at |
| 7 |
* http://www.eclipse.org/legal/epl-v10.html |
| 8 |
*******************************************************************************/ |
| 9 |
package org.wesnoth.product; |
| 10 |
|
| 11 |
import org.eclipse.swt.widgets.Display; |
| 12 |
import org.eclipse.swt.widgets.Menu; |
| 13 |
import org.eclipse.swt.widgets.MenuItem; |
| 14 |
import org.eclipse.ui.IPerspectiveDescriptor; |
| 15 |
import org.eclipse.ui.IPerspectiveListener; |
| 16 |
import org.eclipse.ui.IStartup; |
| 17 |
import org.eclipse.ui.IWorkbenchPage; |
| 18 |
import org.eclipse.ui.IWorkbenchWindow; |
| 19 |
import org.eclipse.ui.PlatformUI; |
| 20 |
import org.wesnoth.Messages; |
| 21 |
|
| 22 |
public class ActionWiper implements IStartup, IPerspectiveListener |
| 23 |
{ |
| 24 |
private static final String[] ACTIONS_2_WIPE = new String[] { |
| 25 |
"org.eclipse.search.searchActionSet", //$NON-NLS-1$ |
| 26 |
"org.eclipse.debug.ui.breakpointActionSet", //$NON-NLS-1$ |
| 27 |
"org.eclipse.debug.ui.debugActionSet", //$NON-NLS-1$ |
| 28 |
"org.eclipse.debug.ui.launchActionSet", //$NON-NLS-1$ |
| 29 |
"org.eclipse.debug.ui.profileActionSet", //$NON-NLS-1$ |
| 30 |
"org.eclipse.ui.externaltools.ExternalToolsSet" //$NON-NLS-1$ |
| 31 |
// "org.eclipse.ui.edit.text.actionSet.presentation", |
| 32 |
// "org.eclipse.ui.edit.text.actionSet.openExternalFile", |
| 33 |
// "org.eclipse.ui.edit.text.actionSet.annotationNavigation", |
| 34 |
// "org.eclipse.ui.edit.text.actionSet.navigation", |
| 35 |
// "org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo", |
| 36 |
// "org.eclipse.update.ui.softwareUpdates" |
| 37 |
}; |
| 38 |
|
| 39 |
public void earlyStartup() |
| 40 |
{ |
| 41 |
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); |
| 42 |
for (int i = 0; i < windows.length; i++) |
| 43 |
{ |
| 44 |
IWorkbenchPage page = windows[i].getActivePage(); |
| 45 |
if (page != null) |
| 46 |
{ |
| 47 |
wipeActions(page); |
| 48 |
} |
| 49 |
windows[i].addPerspectiveListener(this); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
private void wipeActions(final IWorkbenchPage page) |
| 54 |
{ |
| 55 |
Display.getDefault().syncExec(new Runnable() { |
| 56 |
public void run() |
| 57 |
{ |
| 58 |
// remove the run menu |
| 59 |
Menu menu = page.getWorkbenchWindow().getShell().getMenuBar(); |
| 60 |
for (MenuItem item : menu.getItems()) |
| 61 |
{ |
| 62 |
if (item.getText().equals(Messages.ActionWiper_6)) |
| 63 |
{ |
| 64 |
item.dispose(); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
for (int i = 0; i < ACTIONS_2_WIPE.length; i++) |
| 69 |
{ |
| 70 |
page.hideActionSet(ACTIONS_2_WIPE[i]); |
| 71 |
} |
| 72 |
} |
| 73 |
}); |
| 74 |
} |
| 75 |
|
| 76 |
public void perspectiveActivated(IWorkbenchPage page, |
| 77 |
IPerspectiveDescriptor perspective) |
| 78 |
{ |
| 79 |
wipeActions(page); |
| 80 |
} |
| 81 |
|
| 82 |
public void perspectiveChanged(IWorkbenchPage page, |
| 83 |
IPerspectiveDescriptor perspective, String changeId) |
| 84 |
{ |
| 85 |
} |
| 86 |
} |