View | Details | Raw Unified | Return to bug 177806 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/Workbench.java (+13 lines)
Lines 140-145 Link Here
140
import org.eclipse.ui.internal.intro.IIntroRegistry;
140
import org.eclipse.ui.internal.intro.IIntroRegistry;
141
import org.eclipse.ui.internal.intro.IntroDescriptor;
141
import org.eclipse.ui.internal.intro.IntroDescriptor;
142
import org.eclipse.ui.internal.keys.BindingService;
142
import org.eclipse.ui.internal.keys.BindingService;
143
import org.eclipse.ui.internal.menus.FocusControlSourceProvider;
143
import org.eclipse.ui.internal.menus.WorkbenchMenuService;
144
import org.eclipse.ui.internal.menus.WorkbenchMenuService;
144
import org.eclipse.ui.internal.misc.Policy;
145
import org.eclipse.ui.internal.misc.Policy;
145
import org.eclipse.ui.internal.misc.StatusUtil;
146
import org.eclipse.ui.internal.misc.StatusUtil;
Lines 169-174 Link Here
169
import org.eclipse.ui.internal.util.Util;
170
import org.eclipse.ui.internal.util.Util;
170
import org.eclipse.ui.intro.IIntroManager;
171
import org.eclipse.ui.intro.IIntroManager;
171
import org.eclipse.ui.keys.IBindingService;
172
import org.eclipse.ui.keys.IBindingService;
173
import org.eclipse.ui.menus.IFocusService;
172
import org.eclipse.ui.menus.IMenuService;
174
import org.eclipse.ui.menus.IMenuService;
173
import org.eclipse.ui.operations.IWorkbenchOperationSupport;
175
import org.eclipse.ui.operations.IWorkbenchOperationSupport;
174
import org.eclipse.ui.progress.IProgressService;
176
import org.eclipse.ui.progress.IProgressService;
Lines 1625-1636 Link Here
1625
				contextService.addSourceProvider(currentSelectionSourceProvider);
1627
				contextService.addSourceProvider(currentSelectionSourceProvider);
1626
				menuService.addSourceProvider(currentSelectionSourceProvider);
1628
				menuService.addSourceProvider(currentSelectionSourceProvider);
1627
				sourceProviderService.registerProvider(currentSelectionSourceProvider);
1629
				sourceProviderService.registerProvider(currentSelectionSourceProvider);
1630
				
1628
				actionSetSourceProvider = new ActionSetSourceProvider();
1631
				actionSetSourceProvider = new ActionSetSourceProvider();
1629
				evaluationService.addSourceProvider(actionSetSourceProvider);
1632
				evaluationService.addSourceProvider(actionSetSourceProvider);
1630
				handlerService[0].addSourceProvider(actionSetSourceProvider);
1633
				handlerService[0].addSourceProvider(actionSetSourceProvider);
1631
				contextService.addSourceProvider(actionSetSourceProvider);
1634
				contextService.addSourceProvider(actionSetSourceProvider);
1632
				menuService.addSourceProvider(actionSetSourceProvider);
1635
				menuService.addSourceProvider(actionSetSourceProvider);
1633
				sourceProviderService.registerProvider(actionSetSourceProvider);
1636
				sourceProviderService.registerProvider(actionSetSourceProvider);
1637
				
1638
				FocusControlSourceProvider focusControl = new FocusControlSourceProvider();
1639
				serviceLocator.registerService(IFocusService.class, focusControl);
1640
				evaluationService.addSourceProvider(focusControl);
1641
				handlerService[0].addSourceProvider(focusControl);
1642
				contextService.addSourceProvider(focusControl);
1643
				menuService.addSourceProvider(focusControl);
1644
				sourceProviderService.registerProvider(focusControl);
1645
				
1646
				
1634
				menuSourceProvider = new MenuSourceProvider();
1647
				menuSourceProvider = new MenuSourceProvider();
1635
				evaluationService.addSourceProvider(menuSourceProvider);
1648
				evaluationService.addSourceProvider(menuSourceProvider);
1636
				handlerService[0].addSourceProvider(menuSourceProvider);
1649
				handlerService[0].addSourceProvider(menuSourceProvider);
(-)Eclipse UI/org/eclipse/ui/internal/Perspective.java (-4 / +11 lines)
Lines 1166-1175 Link Here
1166
        for (int x = 0; x < actions.length; x++) {
1166
        for (int x = 0; x < actions.length; x++) {
1167
            String actionSetID = actions[x]
1167
            String actionSetID = actions[x]
1168
                    .getString(IWorkbenchConstants.TAG_ID);
1168
                    .getString(IWorkbenchConstants.TAG_ID);
1169
            IActionSetDescriptor d = WorkbenchPlugin.getDefault()
1169
            final IActionSetDescriptor d = WorkbenchPlugin.getDefault()
1170
                    .getActionSetRegistry().findActionSet(actionSetID);
1170
                    .getActionSetRegistry().findActionSet(actionSetID);
1171
            if (d != null) {
1171
            if (d != null) {
1172
                addAlwaysOn(d);
1172
                StartupThreading.runWithoutExceptions(new StartupRunnable() {
1173
        			public void runWithException() throws Throwable {
1174
                        addAlwaysOn(d);
1175
        			}});
1176
1173
                knownActionSetIds.add(actionSetID);
1177
                knownActionSetIds.add(actionSetID);
1174
            }
1178
            }
1175
        }
1179
        }
Lines 1180-1189 Link Here
1180
        for (int x = 0; x < actions.length; x++) {
1184
        for (int x = 0; x < actions.length; x++) {
1181
            String actionSetID = actions[x]
1185
            String actionSetID = actions[x]
1182
                    .getString(IWorkbenchConstants.TAG_ID);
1186
                    .getString(IWorkbenchConstants.TAG_ID);
1183
            IActionSetDescriptor d = WorkbenchPlugin.getDefault()
1187
            final IActionSetDescriptor d = WorkbenchPlugin.getDefault()
1184
                    .getActionSetRegistry().findActionSet(actionSetID);
1188
                    .getActionSetRegistry().findActionSet(actionSetID);
1185
            if (d != null) {
1189
            if (d != null) {
1186
                addAlwaysOff(d);
1190
                StartupThreading.runWithoutExceptions(new StartupRunnable() {
1191
        			public void runWithException() throws Throwable {
1192
                        addAlwaysOff(d);
1193
        			}});
1187
                knownActionSetIds.add(actionSetID);
1194
                knownActionSetIds.add(actionSetID);
1188
            }
1195
            }
1189
        }
1196
        }
(-)Eclipse UI/org/eclipse/ui/ISources.java (+16 lines)
Lines 281-284 Link Here
281
	 * @since 3.3
281
	 * @since 3.3
282
	 */
282
	 */
283
	public static final String ACTIVE_MENU_EDITOR_INPUT_NAME = "activeMenuEditorInput";  //$NON-NLS-1$
283
	public static final String ACTIVE_MENU_EDITOR_INPUT_NAME = "activeMenuEditorInput";  //$NON-NLS-1$
284
285
	/**
286
	 * The variable name for the active focus Control, which is sometimes
287
	 * available.
288
	 * 
289
	 * @since 3.3
290
	 */
291
	public static final String ACTIVE_FOCUS_CONTROL_NAME = "activeFocusControl"; //$NON-NLS-1$
292
293
	/**
294
	 * The variable name for the active focus Control id, which is sometimes
295
	 * available.
296
	 * 
297
	 * @since 3.3
298
	 */
299
	public static final String ACTIVE_FOCUS_CONTROL_ID_NAME = "activeFocusControlId"; //$NON-NLS-1$
284
}
300
}
(-)Eclipse UI/org/eclipse/ui/internal/services/SourcePriorityNameMapping.java (+2 lines)
Lines 72-77 Link Here
72
		addMapping(ACTIVE_MENU_NAME, ACTIVE_MENU);
72
		addMapping(ACTIVE_MENU_NAME, ACTIVE_MENU);
73
		addMapping(ACTIVE_MENU_SELECTION_NAME, ACTIVE_MENU);
73
		addMapping(ACTIVE_MENU_SELECTION_NAME, ACTIVE_MENU);
74
		addMapping(ACTIVE_MENU_EDITOR_INPUT_NAME, ACTIVE_MENU);
74
		addMapping(ACTIVE_MENU_EDITOR_INPUT_NAME, ACTIVE_MENU);
75
		addMapping(ACTIVE_FOCUS_CONTROL_ID_NAME, ACTIVE_MENU);
76
		addMapping(ACTIVE_FOCUS_CONTROL_NAME, ACTIVE_MENU);
75
		addMapping(ACTIVE_PART_NAME, ACTIVE_PART);
77
		addMapping(ACTIVE_PART_NAME, ACTIVE_PART);
76
		addMapping(ACTIVE_PART_ID_NAME, ACTIVE_PART_ID);
78
		addMapping(ACTIVE_PART_ID_NAME, ACTIVE_PART_ID);
77
		addMapping(ACTIVE_SHELL_NAME, ACTIVE_SHELL);
79
		addMapping(ACTIVE_SHELL_NAME, ACTIVE_SHELL);
(-)Eclipse (+44 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.ui.menus;
13
14
import org.eclipse.swt.widgets.Control;
15
16
/**
17
 * Tracks focusGained and focusLost events for a Control registered with this
18
 * service, and provides them as variables to the application evaluation context
19
 * for evaluation be the various services.
20
 * 
21
 * @since 3.3
22
 */
23
public interface IFocusService {
24
	/**
25
	 * A Control for the service to track. We will remove ourselves as a
26
	 * listener on a dispose.
27
	 * 
28
	 * @param control
29
	 *            the control. Must not be <code>null</code>.
30
	 * @param id
31
	 *            the unique ID for this control. Must not be <code>null</code>.
32
	 */
33
	public void addTrackerFor(Control control, String id);
34
35
	/**
36
	 * No longer track focus events for this control. Use this method when the
37
	 * control should no longer be tracked, but is not disposed.
38
	 * 
39
	 * @param control
40
	 *            the control registered with the service. Must not be
41
	 *            <code>null</code>.
42
	 */
43
	public void removeTrackerFor(Control control);
44
}
(-)Eclipse (+170 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.ui.internal.menus;
13
14
import java.util.HashMap;
15
import java.util.Iterator;
16
import java.util.Map;
17
18
import org.eclipse.swt.events.DisposeEvent;
19
import org.eclipse.swt.events.DisposeListener;
20
import org.eclipse.swt.events.FocusEvent;
21
import org.eclipse.swt.events.FocusListener;
22
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.swt.widgets.Widget;
24
import org.eclipse.ui.AbstractSourceProvider;
25
import org.eclipse.ui.ISources;
26
import org.eclipse.ui.menus.IFocusService;
27
28
/**
29
 * @since 3.3
30
 * 
31
 */
32
public class FocusControlSourceProvider extends AbstractSourceProvider
33
		implements IFocusService {
34
35
	/**
36
	 * The names of the sources supported by this source provider.
37
	 */
38
	private static final String[] PROVIDED_SOURCE_NAMES = new String[] {
39
			ISources.ACTIVE_FOCUS_CONTROL_ID_NAME,
40
			ISources.ACTIVE_FOCUS_CONTROL_NAME };
41
42
	Map controlToId = new HashMap();
43
	private FocusListener focusListener;
44
45
	private String currentId;
46
47
	private Control currentControl;
48
49
	private DisposeListener disposeListener;
50
51
	/*
52
	 * (non-Javadoc)
53
	 * 
54
	 * @see org.eclipse.ui.menus.IFocusService#addTrackerFor(org.eclipse.swt.widgets.Control,
55
	 *      java.lang.String)
56
	 */
57
	public void addTrackerFor(Control control, String id) {
58
		if (control.isDisposed()) {
59
			return;
60
		}
61
		controlToId.put(control, id);
62
		control.addFocusListener(getFocusListener());
63
		control.addDisposeListener(getDisposeListener());
64
	}
65
66
	/**
67
	 * @return
68
	 */
69
	private DisposeListener getDisposeListener() {
70
		if (disposeListener == null) {
71
			disposeListener = new DisposeListener() {
72
				public void widgetDisposed(DisposeEvent e) {
73
					controlToId.remove(e.widget);
74
				}
75
			};
76
		}
77
		return disposeListener;
78
	}
79
80
	/**
81
	 * @return
82
	 */
83
	private FocusListener getFocusListener() {
84
		if (focusListener == null) {
85
			focusListener = new FocusListener() {
86
				public void focusGained(FocusEvent e) {
87
					focusIn(e.widget);
88
				}
89
90
				public void focusLost(FocusEvent e) {
91
					focusIn(null);
92
				}
93
			};
94
		}
95
		return focusListener;
96
	}
97
98
	/**
99
	 * @param widget
100
	 */
101
	private void focusIn(Widget widget) {
102
		String id = (String) controlToId.get(widget);
103
		if (currentId != id) {
104
			if (id == null) {
105
				currentId = null;
106
				currentControl = null;
107
			} else {
108
				currentId = id;
109
				currentControl = (Control) widget;
110
			}
111
			Map m = new HashMap();
112
			m.put(ISources.ACTIVE_FOCUS_CONTROL_ID_NAME, currentId);
113
			m.put(ISources.ACTIVE_FOCUS_CONTROL_NAME, currentControl);
114
			fireSourceChanged(ISources.ACTIVE_MENU, m);
115
		}
116
	}
117
118
	/*
119
	 * (non-Javadoc)
120
	 * 
121
	 * @see org.eclipse.ui.menus.IFocusService#removeTrackerFor(org.eclipse.swt.widgets.Control)
122
	 */
123
	public void removeTrackerFor(Control control) {
124
		controlToId.remove(control);
125
		if (control.isDisposed()) {
126
			return;
127
		}
128
		control.removeFocusListener(getFocusListener());
129
		control.removeDisposeListener(getDisposeListener());
130
	}
131
132
	/*
133
	 * (non-Javadoc)
134
	 * 
135
	 * @see org.eclipse.ui.ISourceProvider#dispose()
136
	 */
137
	public void dispose() {
138
		Iterator i = controlToId.keySet().iterator();
139
		while (i.hasNext()) {
140
			Control c = (Control) i.next();
141
			if (!c.isDisposed()) {
142
				c.removeFocusListener(getFocusListener());
143
			}
144
		}
145
		controlToId.clear();
146
		controlToId = null;
147
		focusListener = null;
148
	}
149
150
	/*
151
	 * (non-Javadoc)
152
	 * 
153
	 * @see org.eclipse.ui.ISourceProvider#getCurrentState()
154
	 */
155
	public Map getCurrentState() {
156
		Map m = new HashMap();
157
		m.put(ISources.ACTIVE_FOCUS_CONTROL_ID_NAME, currentId);
158
		m.put(ISources.ACTIVE_FOCUS_CONTROL_NAME, currentControl);
159
		return m;
160
	}
161
162
	/*
163
	 * (non-Javadoc)
164
	 * 
165
	 * @see org.eclipse.ui.ISourceProvider#getProvidedSourceNames()
166
	 */
167
	public String[] getProvidedSourceNames() {
168
		return PROVIDED_SOURCE_NAMES;
169
	}
170
}

Return to bug 177806