Skip to content

Commit 8cb6e80

Browse files
committed
Trigger Show In on Enter/double-click for projects in Open Resource
When a project (or other non-file resource) is selected in the Open Resource dialog, the OK button was disabled and Enter/double-click had no effect. Enable OK in that case and route it to the first available Show In target (MRU-sorted, same ordering as the Show In dropdown), passing the selection as a ShowInContext. Falls back to today's silent close when no Show In target is available.
1 parent c0f8768 commit 8cb6e80

1 file changed

Lines changed: 64 additions & 1 deletion

File tree

bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/OpenResourceDialog.java

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.internal.ide.dialogs;
1515

16+
import java.util.ArrayList;
1617
import java.util.Collections;
1718

1819
import org.eclipse.core.resources.IContainer;
@@ -57,12 +58,14 @@
5758
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
5859
import org.eclipse.ui.internal.ShowInMenu;
5960
import org.eclipse.ui.internal.WorkbenchImages;
61+
import org.eclipse.ui.internal.WorkbenchPage;
6062
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
6163
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
6264
import org.eclipse.ui.part.IShowInTarget;
6365
import org.eclipse.ui.part.ShowInContext;
6466
import org.eclipse.ui.statushandlers.StatusManager;
6567
import org.eclipse.ui.views.IViewDescriptor;
68+
import org.eclipse.ui.views.IViewRegistry;
6669

6770

6871
/**
@@ -293,13 +296,73 @@ protected void updateButtonsEnableState(IStatus status) {
293296
openWithButton.setEnabled(getSelectedItems().size() == 1);
294297
showInButton.setEnabled(true);
295298
} else {
296-
okButton.setEnabled(false);
299+
// Exactly one non-file resource (typically a project): OK triggers
300+
// the first available Show In target. Multiple non-file resources
301+
// don't make sense for Show In, so leave OK disabled there.
302+
okButton.setEnabled(getSelectedItems().size() == 1);
297303
openWithButton.setEnabled(false);
298304
showInButton.setEnabled(true);
299305
}
300306
}
301307
}
302308

309+
@Override
310+
protected void okPressed() {
311+
IStructuredSelection selected = getSelectedItems();
312+
Button okButton = getOkButton();
313+
if (selected.size() == 1 && !(selected.getFirstElement() instanceof IFile)
314+
&& okButton != null && okButton.isEnabled()) {
315+
if (showSelectionInFirstShowInTarget(selected)) {
316+
return;
317+
}
318+
}
319+
super.okPressed();
320+
}
321+
322+
/** Shows the selection in the first available Show In target. */
323+
private boolean showSelectionInFirstShowInTarget(IStructuredSelection selection) {
324+
IWorkbenchPage activePage = getActivePage();
325+
if (!(activePage instanceof WorkbenchPage)) {
326+
return false;
327+
}
328+
WorkbenchPage workbenchPage = (WorkbenchPage) activePage;
329+
330+
ArrayList<String> ids = new ArrayList<>(workbenchPage.getShowInPartIds());
331+
if (ids.isEmpty()) {
332+
return false;
333+
}
334+
workbenchPage.sortShowInPartIds(ids);
335+
336+
IViewRegistry registry = PlatformUI.getWorkbench().getViewRegistry();
337+
IViewDescriptor descriptor = null;
338+
for (String id : ids) {
339+
IViewDescriptor candidate = registry.find(id);
340+
if (candidate != null) {
341+
descriptor = candidate;
342+
break;
343+
}
344+
}
345+
if (descriptor == null) {
346+
return false;
347+
}
348+
349+
computeResult();
350+
setResult(Collections.EMPTY_LIST);
351+
close();
352+
353+
try {
354+
IViewPart view = activePage.showView(descriptor.getId());
355+
IShowInTarget target = Adapters.adapt(view, IShowInTarget.class);
356+
if (target == null || !target.show(new ShowInContext(null, selection))) {
357+
activePage.getWorkbenchWindow().getShell().getDisplay().beep();
358+
}
359+
} catch (PartInitException e) {
360+
StatusManager.getManager().handle(new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH,
361+
IStatus.ERROR, "", e)); //$NON-NLS-1$
362+
}
363+
return true;
364+
}
365+
303366
private boolean isButtonReady(Button button) {
304367
return button != null && !button.isDisposed();
305368
}

0 commit comments

Comments
 (0)