Skip to content

Commit a3fe77d

Browse files
committed
In Project Explorer, ensure "Select All" (Ctrl+A and menu) works
reliably irrespective of first or subsequent selections.
1 parent 933b741 commit a3fe77d

File tree

1 file changed

+62
-6
lines changed

1 file changed

+62
-6
lines changed

bundles/org.eclipse.ui.navigator/src/org/eclipse/ui/navigator/CommonNavigator.java

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*******************************************************************************/
1717
package org.eclipse.ui.navigator;
1818

19+
import org.eclipse.core.commands.AbstractHandler;
20+
import org.eclipse.core.commands.ExecutionEvent;
1921
import org.eclipse.core.runtime.IProgressMonitor;
2022
import org.eclipse.core.runtime.PerformanceStats;
2123
import org.eclipse.core.runtime.SafeRunner;
@@ -29,18 +31,25 @@
2931
import org.eclipse.jface.viewers.TreeViewer;
3032
import org.eclipse.jface.viewers.ViewerFilter;
3133
import org.eclipse.swt.SWT;
34+
import org.eclipse.swt.events.KeyAdapter;
35+
import org.eclipse.swt.events.KeyEvent;
3236
import org.eclipse.swt.widgets.Composite;
3337
import org.eclipse.ui.IEditorInput;
3438
import org.eclipse.ui.IMemento;
39+
import org.eclipse.ui.IPartListener2;
3540
import org.eclipse.ui.ISaveablePart;
3641
import org.eclipse.ui.ISaveablesLifecycleListener;
3742
import org.eclipse.ui.ISaveablesSource;
3843
import org.eclipse.ui.IViewSite;
44+
import org.eclipse.ui.IWorkbenchCommandConstants;
45+
import org.eclipse.ui.IWorkbenchPartReference;
3946
import org.eclipse.ui.PartInitException;
4047
import org.eclipse.ui.PlatformUI;
4148
import org.eclipse.ui.Saveable;
4249
import org.eclipse.ui.SaveablesLifecycleEvent;
4350
import org.eclipse.ui.actions.ActionGroup;
51+
import org.eclipse.ui.handlers.IHandlerActivation;
52+
import org.eclipse.ui.handlers.IHandlerService;
4453
import org.eclipse.ui.internal.navigator.CommonNavigatorActionGroup;
4554
import org.eclipse.ui.internal.navigator.NavigatorContentService;
4655
import org.eclipse.ui.internal.navigator.NavigatorPlugin;
@@ -160,6 +169,8 @@ public class CommonNavigator extends ViewPart implements ISetSelectionTarget, IS
160169

161170
private LinkHelperService linkService;
162171

172+
private IPartListener2 partListener;
173+
163174
public CommonNavigator() {
164175
super();
165176
}
@@ -255,6 +266,47 @@ public void handleLifecycleEvent(SaveablesLifecycleEvent event) {
255266
ColumnViewerToolTipSupport.enableFor(commonViewer);
256267
}
257268

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+
258310
stats.endRun();
259311
}
260312

@@ -308,13 +360,17 @@ public String getFrameToolTipText(Object anElement) {
308360
*/
309361
@Override
310362
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();
316373
}
317-
super.dispose();
318374
}
319375

320376
/**

0 commit comments

Comments
 (0)