|
16 | 16 | *******************************************************************************/ |
17 | 17 | package org.eclipse.ui.navigator; |
18 | 18 |
|
| 19 | +import org.eclipse.core.commands.AbstractHandler; |
| 20 | +import org.eclipse.core.commands.ExecutionEvent; |
19 | 21 | import org.eclipse.core.runtime.IProgressMonitor; |
20 | 22 | import org.eclipse.core.runtime.PerformanceStats; |
21 | 23 | import org.eclipse.core.runtime.SafeRunner; |
|
29 | 31 | import org.eclipse.jface.viewers.TreeViewer; |
30 | 32 | import org.eclipse.jface.viewers.ViewerFilter; |
31 | 33 | import org.eclipse.swt.SWT; |
| 34 | +import org.eclipse.swt.events.KeyAdapter; |
| 35 | +import org.eclipse.swt.events.KeyEvent; |
32 | 36 | import org.eclipse.swt.widgets.Composite; |
33 | 37 | import org.eclipse.ui.IEditorInput; |
34 | 38 | import org.eclipse.ui.IMemento; |
| 39 | +import org.eclipse.ui.IPartListener2; |
35 | 40 | import org.eclipse.ui.ISaveablePart; |
36 | 41 | import org.eclipse.ui.ISaveablesLifecycleListener; |
37 | 42 | import org.eclipse.ui.ISaveablesSource; |
38 | 43 | import org.eclipse.ui.IViewSite; |
| 44 | +import org.eclipse.ui.IWorkbenchCommandConstants; |
| 45 | +import org.eclipse.ui.IWorkbenchPartReference; |
39 | 46 | import org.eclipse.ui.PartInitException; |
40 | 47 | import org.eclipse.ui.PlatformUI; |
41 | 48 | import org.eclipse.ui.Saveable; |
42 | 49 | import org.eclipse.ui.SaveablesLifecycleEvent; |
43 | 50 | import org.eclipse.ui.actions.ActionGroup; |
| 51 | +import org.eclipse.ui.handlers.IHandlerActivation; |
| 52 | +import org.eclipse.ui.handlers.IHandlerService; |
44 | 53 | import org.eclipse.ui.internal.navigator.CommonNavigatorActionGroup; |
45 | 54 | import org.eclipse.ui.internal.navigator.NavigatorContentService; |
46 | 55 | import org.eclipse.ui.internal.navigator.NavigatorPlugin; |
@@ -160,6 +169,8 @@ public class CommonNavigator extends ViewPart implements ISetSelectionTarget, IS |
160 | 169 |
|
161 | 170 | private LinkHelperService linkService; |
162 | 171 |
|
| 172 | + private IPartListener2 partListener; |
| 173 | + |
163 | 174 | public CommonNavigator() { |
164 | 175 | super(); |
165 | 176 | } |
@@ -255,6 +266,47 @@ public void handleLifecycleEvent(SaveablesLifecycleEvent event) { |
255 | 266 | ColumnViewerToolTipSupport.enableFor(commonViewer); |
256 | 267 | } |
257 | 268 |
|
| 269 | + // Immediate fallback: handle Ctrl+A at the Tree level |
| 270 | + commonViewer.getTree().addKeyListener(new KeyAdapter() { |
| 271 | + @Override |
| 272 | + public void keyPressed(KeyEvent e) { |
| 273 | + // MOD1 = Ctrl on Win/Linux, Command on macOS |
| 274 | + if ((e.stateMask & SWT.MOD1) != 0 && (e.keyCode == 'a' || e.keyCode == 'A')) { |
| 275 | + commonViewer.getTree().selectAll(); |
| 276 | + e.doit = false; |
| 277 | + } |
| 278 | + } |
| 279 | + }); |
| 280 | + |
| 281 | + // Activate the 'Select All' command handler when the view is active |
| 282 | + partListener = new IPartListener2() { |
| 283 | + private IHandlerActivation activation; |
| 284 | + |
| 285 | + @Override |
| 286 | + public void partActivated(IWorkbenchPartReference ref) { |
| 287 | + if (ref.getPart(false) == CommonNavigator.this) { |
| 288 | + IHandlerService hs = getSite().getService(IHandlerService.class); |
| 289 | + activation = hs.activateHandler(IWorkbenchCommandConstants.EDIT_SELECT_ALL, new AbstractHandler() { |
| 290 | + @Override |
| 291 | + public Object execute(ExecutionEvent event) { |
| 292 | + commonViewer.getTree().selectAll(); |
| 293 | + return null; |
| 294 | + } |
| 295 | + }); |
| 296 | + } |
| 297 | + } |
| 298 | + |
| 299 | + @Override |
| 300 | + public void partDeactivated(IWorkbenchPartReference ref) { |
| 301 | + if (ref.getPart(false) == CommonNavigator.this && activation != null) { |
| 302 | + IHandlerService hs = getSite().getService(IHandlerService.class); |
| 303 | + hs.deactivateHandler(activation); |
| 304 | + activation = null; |
| 305 | + } |
| 306 | + } |
| 307 | + }; |
| 308 | + getSite().getPage().addPartListener(partListener); |
| 309 | + |
258 | 310 | stats.endRun(); |
259 | 311 | } |
260 | 312 |
|
@@ -308,13 +360,17 @@ public String getFrameToolTipText(Object anElement) { |
308 | 360 | */ |
309 | 361 | @Override |
310 | 362 | public void dispose() { |
311 | | - if (commonManager != null) { |
312 | | - commonManager.dispose(); |
313 | | - } |
314 | | - if (commonActionGroup != null) { |
315 | | - commonActionGroup.dispose(); |
| 363 | + try { |
| 364 | + getSite().getPage().removePartListener(partListener); |
| 365 | + if (commonManager != null) { |
| 366 | + commonManager.dispose(); |
| 367 | + } |
| 368 | + if (commonActionGroup != null) { |
| 369 | + commonActionGroup.dispose(); |
| 370 | + } |
| 371 | + } finally { |
| 372 | + super.dispose(); |
316 | 373 | } |
317 | | - super.dispose(); |
318 | 374 | } |
319 | 375 |
|
320 | 376 | /** |
|
0 commit comments