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

Collapse All | Expand All

(-)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 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/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, when provided by the
287
	 * IFocusService.
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, when provided by the
295
	 * IFocusService.
296
	 * 
297
	 * @since 3.3
298
	 */
299
	public static final String ACTIVE_FOCUS_CONTROL_ID_NAME = "activeFocusControlId"; //$NON-NLS-1$
284
}
300
}
(-)Eclipse (+93 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
 * <p>
21
 * This service provides 2 variables, activeFocusControl (a Control) and
22
 * activeFocusControlId (the ID registered with the service).
23
 * </p>
24
 * <p>
25
 * You can use this service to provide default cut/copy/paste/selectAll for
26
 * specific text controls outside of the normal workbench part lifecycle, like a
27
 * control contributed to the trim. For example:
28
 * </p>
29
 * <p>
30
 * 
31
 * <pre>
32
 * &lt;handler
33
 *      class=&quot;org.eclipse.ui.internal.handlers.WidgetMethodHandler:paste&quot;
34
 *      commandId=&quot;org.eclipse.ui.edit.paste&quot;&gt;
35
 *   &lt;activeWhen&gt;
36
 *      &lt;with variable=&quot;activeFocusControlId&quot;&gt;
37
 *         &lt;equals value=&quot;org.eclipse.ui.tests.focusText&quot;/&gt;
38
 *      &lt;/with&gt;
39
 *   &lt;/activeWhen&gt;
40
 * &lt;/handler&gt;
41
 * </pre>
42
 * 
43
 * </p>
44
 * 
45
 * @see org.eclipse.ui.ISources
46
 * @since 3.3
47
 */
48
public interface IFocusService {
49
	/**
50
	 * Use the value to provide default copy behaviour in a handler element
51
	 * class attribute.
52
	 */
53
	public static final String COPY_HANDLER = "org.eclipse.ui.internal.handlers.WidgetMethodHandler:copy"; //$NON-NLS-1$
54
55
	/**
56
	 * Use the value to provide default paste behaviour in a handler element
57
	 * class attribute.
58
	 */
59
	public static final String PASTE_HANDLER = "org.eclipse.ui.internal.handlers.WidgetMethodHandler:paste"; //$NON-NLS-1$
60
61
	/**
62
	 * Use the value to provide default cut behaviour in a handler element class
63
	 * attribute.
64
	 */
65
	public static final String CUT_HANDLER = "org.eclipse.ui.internal.handlers.WidgetMethodHandler:cut"; //$NON-NLS-1$
66
67
	/**
68
	 * Use the value to provide default select all behaviour in a handler
69
	 * element class attribute.
70
	 */
71
	public static final String SELECT_ALL_HANDLER = "org.eclipse.ui.internal.handlers.SelectAllHandler"; //$NON-NLS-1$
72
73
	/**
74
	 * A Control for the service to track. We will remove ourselves as a
75
	 * listener on a dispose.
76
	 * 
77
	 * @param control
78
	 *            the control. Must not be <code>null</code>.
79
	 * @param id
80
	 *            the unique ID for this control. Must not be <code>null</code>.
81
	 */
82
	public void addFocusTracker(Control control, String id);
83
84
	/**
85
	 * No longer track focus events for this control. Use this method when the
86
	 * control should no longer be tracked, but is not disposed.
87
	 * 
88
	 * @param control
89
	 *            the control registered with the service. Must not be
90
	 *            <code>null</code>.
91
	 */
92
	public void removeFocusTracker(Control control);
93
}
(-)Eclipse (+172 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 addFocusTracker(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 removeFocusTracker(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
				c.removeDisposeListener(getDisposeListener());
144
			}
145
		}
146
		controlToId.clear();
147
		controlToId = null;
148
		focusListener = null;
149
		disposeListener = null;
150
	}
151
152
	/*
153
	 * (non-Javadoc)
154
	 * 
155
	 * @see org.eclipse.ui.ISourceProvider#getCurrentState()
156
	 */
157
	public Map getCurrentState() {
158
		Map m = new HashMap();
159
		m.put(ISources.ACTIVE_FOCUS_CONTROL_ID_NAME, currentId);
160
		m.put(ISources.ACTIVE_FOCUS_CONTROL_NAME, currentControl);
161
		return m;
162
	}
163
164
	/*
165
	 * (non-Javadoc)
166
	 * 
167
	 * @see org.eclipse.ui.ISourceProvider#getProvidedSourceNames()
168
	 */
169
	public String[] getProvidedSourceNames() {
170
		return PROVIDED_SOURCE_NAMES;
171
	}
172
}

Return to bug 177806