2
|
1 |
package com.nokia.carbide.cpp;
|
|
2 |
|
|
3 |
import java.lang.reflect.InvocationHandler;
|
|
4 |
import java.lang.reflect.Method;
|
|
5 |
import java.lang.reflect.Proxy;
|
|
6 |
|
|
7 |
import org.eclipse.jface.action.ActionContributionItem;
|
|
8 |
import org.eclipse.jface.action.IAction;
|
|
9 |
import org.eclipse.jface.action.IContributionItem;
|
|
10 |
import org.eclipse.jface.action.MenuManager;
|
|
11 |
import org.eclipse.jface.preference.IPreferenceStore;
|
|
12 |
import org.eclipse.swt.widgets.Display;
|
|
13 |
import org.eclipse.ui.IStartup;
|
|
14 |
import org.eclipse.ui.IWindowListener;
|
|
15 |
import org.eclipse.ui.IWorkbenchWindow;
|
|
16 |
import org.eclipse.ui.PlatformUI;
|
|
17 |
import org.eclipse.ui.internal.WorkbenchWindow;
|
|
18 |
|
|
19 |
public class ProductStartup implements IStartup {
|
|
20 |
|
|
21 |
|
|
22 |
public void replaceAboutAction(final IWorkbenchWindow window)
|
|
23 |
{
|
|
24 |
|
|
25 |
if (window == null || !(window instanceof WorkbenchWindow))
|
|
26 |
return;
|
|
27 |
MenuManager manager = ((WorkbenchWindow)window).getMenuManager();
|
|
28 |
final IPreferenceStore store = ProductPlugin.getDefault().getPreferenceStore();
|
|
29 |
|
|
30 |
for (IContributionItem item : manager.getItems()) {
|
|
31 |
if (item instanceof MenuManager) {
|
|
32 |
MenuManager mgr = (MenuManager) item;
|
|
33 |
if (item.getId().equals("help"))
|
|
34 |
{
|
|
35 |
final IContributionItem contrib = mgr.remove("about");
|
|
36 |
|
|
37 |
if (contrib instanceof ActionContributionItem) {
|
|
38 |
final IAction about = ((ActionContributionItem) contrib)
|
|
39 |
.getAction();
|
|
40 |
mgr.add(new ActionContributionItem((IAction) Proxy
|
|
41 |
.newProxyInstance(about.getClass()
|
|
42 |
.getClassLoader(),
|
|
43 |
new Class[] { IAction.class },
|
|
44 |
new InvocationHandler() {
|
|
45 |
|
|
46 |
public Object invoke(Object arg0, Method method, Object[] arg2) throws Throwable {
|
|
47 |
|
|
48 |
if ("runWithEvent"
|
|
49 |
.equals(method
|
|
50 |
.getName())
|
|
51 |
|| "run".equals(method
|
|
52 |
.getName())) {
|
|
53 |
new CustomAboutDialog(
|
|
54 |
window.getShell())
|
|
55 |
.open();
|
|
56 |
return null;
|
|
57 |
}
|
|
58 |
return method.invoke(about,
|
|
59 |
arg2);
|
|
60 |
}
|
|
61 |
})));
|
|
62 |
}
|
|
63 |
|
|
64 |
}
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
}
|
|
69 |
|
|
70 |
public void initializeMenus() {
|
|
71 |
|
|
72 |
PlatformUI.getWorkbench().addWindowListener(new IWindowListener() {
|
|
73 |
|
|
74 |
public void windowActivated(IWorkbenchWindow window) {
|
|
75 |
}
|
|
76 |
|
|
77 |
public void windowClosed(IWorkbenchWindow window) {
|
|
78 |
}
|
|
79 |
|
|
80 |
public void windowDeactivated(IWorkbenchWindow window) {
|
|
81 |
}
|
|
82 |
|
|
83 |
public void windowOpened(IWorkbenchWindow window) {
|
|
84 |
replaceAboutAction(window);
|
|
85 |
}
|
|
86 |
});
|
|
87 |
|
|
88 |
Display.getDefault().asyncExec(new Runnable() {
|
|
89 |
public void run() {
|
|
90 |
replaceAboutAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
|
|
91 |
}
|
|
92 |
});
|
|
93 |
|
|
94 |
}
|
|
95 |
|
|
96 |
public void earlyStartup() {
|
|
97 |
|
|
98 |
initializeMenus();
|
|
99 |
|
|
100 |
}
|
|
101 |
|
|
102 |
}
|