Skip to content

Commit 41c3a5c

Browse files
committed
Revised the fix as per the suggestion.
1 parent 0890b8f commit 41c3a5c

File tree

3 files changed

+54
-63
lines changed

3 files changed

+54
-63
lines changed

bundles/org.eclipse.ui.navigator/plugin.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,16 @@
1313
id="org.eclipse.ui.navigator.PluginDropAction">
1414
</action>
1515
</extension>
16-
16+
<extension
17+
point="org.eclipse.ui.handlers">
18+
<handler
19+
commandId="org.eclipse.ui.edit.selectAll"
20+
class="org.eclipse.ui.navigator.CommonNavigatorSelectAllHandler">
21+
<activeWhen>
22+
<with variable="activePartId">
23+
<equals value="org.eclipse.ui.navigator.ProjectExplorer"/>
24+
</with>
25+
</activeWhen>
26+
</handler>
27+
</extension>
1728
</plugin>

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

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

19-
import org.eclipse.core.commands.AbstractHandler;
20-
import org.eclipse.core.commands.ExecutionEvent;
2119
import org.eclipse.core.runtime.IProgressMonitor;
2220
import org.eclipse.core.runtime.PerformanceStats;
2321
import org.eclipse.core.runtime.SafeRunner;
@@ -31,25 +29,18 @@
3129
import org.eclipse.jface.viewers.TreeViewer;
3230
import org.eclipse.jface.viewers.ViewerFilter;
3331
import org.eclipse.swt.SWT;
34-
import org.eclipse.swt.events.KeyAdapter;
35-
import org.eclipse.swt.events.KeyEvent;
3632
import org.eclipse.swt.widgets.Composite;
3733
import org.eclipse.ui.IEditorInput;
3834
import org.eclipse.ui.IMemento;
39-
import org.eclipse.ui.IPartListener2;
4035
import org.eclipse.ui.ISaveablePart;
4136
import org.eclipse.ui.ISaveablesLifecycleListener;
4237
import org.eclipse.ui.ISaveablesSource;
4338
import org.eclipse.ui.IViewSite;
44-
import org.eclipse.ui.IWorkbenchCommandConstants;
45-
import org.eclipse.ui.IWorkbenchPartReference;
4639
import org.eclipse.ui.PartInitException;
4740
import org.eclipse.ui.PlatformUI;
4841
import org.eclipse.ui.Saveable;
4942
import org.eclipse.ui.SaveablesLifecycleEvent;
5043
import org.eclipse.ui.actions.ActionGroup;
51-
import org.eclipse.ui.handlers.IHandlerActivation;
52-
import org.eclipse.ui.handlers.IHandlerService;
5344
import org.eclipse.ui.internal.navigator.CommonNavigatorActionGroup;
5445
import org.eclipse.ui.internal.navigator.NavigatorContentService;
5546
import org.eclipse.ui.internal.navigator.NavigatorPlugin;
@@ -169,8 +160,6 @@ public class CommonNavigator extends ViewPart implements ISetSelectionTarget, IS
169160

170161
private LinkHelperService linkService;
171162

172-
private IPartListener2 partListener;
173-
174163
public CommonNavigator() {
175164
super();
176165
}
@@ -266,47 +255,6 @@ public void handleLifecycleEvent(SaveablesLifecycleEvent event) {
266255
ColumnViewerToolTipSupport.enableFor(commonViewer);
267256
}
268257

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-
310258
stats.endRun();
311259
}
312260

@@ -360,17 +308,13 @@ public String getFrameToolTipText(Object anElement) {
360308
*/
361309
@Override
362310
public void 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();
311+
if (commonManager != null) {
312+
commonManager.dispose();
313+
}
314+
if (commonActionGroup != null) {
315+
commonActionGroup.dispose();
373316
}
317+
super.dispose();
374318
}
375319

376320
/**
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2003, 2026 IBM Corporation and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.ui.navigator;
15+
16+
import org.eclipse.core.commands.AbstractHandler;
17+
import org.eclipse.core.commands.ExecutionEvent;
18+
import org.eclipse.ui.IWorkbenchPart;
19+
import org.eclipse.ui.handlers.HandlerUtil;
20+
21+
/**
22+
* CommonNavigatorSelectAllHandler is the handler for the select all action.
23+
*
24+
* @since 3.14
25+
*
26+
*/
27+
public class CommonNavigatorSelectAllHandler extends AbstractHandler {
28+
@Override
29+
public Object execute(ExecutionEvent event) {
30+
IWorkbenchPart part = HandlerUtil.getActivePart(event);
31+
if (part instanceof CommonNavigator navigator) {
32+
navigator.getCommonViewer().getTree().selectAll();
33+
}
34+
return null;
35+
}
36+
}

0 commit comments

Comments
 (0)