|
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,72 @@ 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 | + // no-ops for the other methods: |
| 309 | + @Override |
| 310 | + public void partOpened(IWorkbenchPartReference r) { |
| 311 | + } |
| 312 | + |
| 313 | + @Override |
| 314 | + public void partClosed(IWorkbenchPartReference r) { |
| 315 | + } |
| 316 | + |
| 317 | + @Override |
| 318 | + public void partBroughtToTop(IWorkbenchPartReference r) { |
| 319 | + } |
| 320 | + |
| 321 | + @Override |
| 322 | + public void partHidden(IWorkbenchPartReference r) { |
| 323 | + } |
| 324 | + |
| 325 | + @Override |
| 326 | + public void partVisible(IWorkbenchPartReference r) { |
| 327 | + } |
| 328 | + |
| 329 | + @Override |
| 330 | + public void partInputChanged(IWorkbenchPartReference r) { |
| 331 | + } |
| 332 | + }; |
| 333 | + getSite().getPage().addPartListener(partListener); |
| 334 | + |
258 | 335 | stats.endRun(); |
259 | 336 | } |
260 | 337 |
|
@@ -308,13 +385,17 @@ public String getFrameToolTipText(Object anElement) { |
308 | 385 | */ |
309 | 386 | @Override |
310 | 387 | public void dispose() { |
311 | | - if (commonManager != null) { |
312 | | - commonManager.dispose(); |
313 | | - } |
314 | | - if (commonActionGroup != null) { |
315 | | - commonActionGroup.dispose(); |
| 388 | + try { |
| 389 | + getSite().getPage().removePartListener(partListener); |
| 390 | + if (commonManager != null) { |
| 391 | + commonManager.dispose(); |
| 392 | + } |
| 393 | + if (commonActionGroup != null) { |
| 394 | + commonActionGroup.dispose(); |
| 395 | + } |
| 396 | + } finally { |
| 397 | + super.dispose(); |
316 | 398 | } |
317 | | - super.dispose(); |
318 | 399 | } |
319 | 400 |
|
320 | 401 | /** |
|
0 commit comments