Skip to content

Commit

Permalink
Prevent filemanager from stealing focus of project explorer's "Show in"
Browse files Browse the repository at this point in the history
Part of #18

Signed-off-by: Andrew Obuchowicz <[email protected]>
  • Loading branch information
AObuchow committed Aug 5, 2020
1 parent b80c2ac commit 496a80e
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.views.IViewDescriptor;

import com.aobuchow.sample.commander.editor.ContainerEditorInput;

Expand Down Expand Up @@ -92,13 +96,19 @@ private IResource getResourceByParameter(ExecutionEvent event) {
}

private IResource getSelectionResource(ExecutionEvent event) {
IStructuredSelection selection = HandlerUtil.getCurrentStructuredSelection(event);
// Prioritize project explorer selection if its active
// TODO: If this handler gets used in other context menus, this will likely change
// IStructuredSelection selection = HandlerUtil.getCurrentStructuredSelection(event);

ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

TreeSelection selection = (TreeSelection) selectionService.getSelection("org.eclipse.ui.navigator.ProjectExplorer");

if ((selection == null) || (selection.isEmpty())) {
return null;
}

Object selectedObject = selection
.getFirstElement();
Object selectedObject = selection.getFirstElement();
return Adapters.adapt(selectedObject, IResource.class);
}

Expand Down

0 comments on commit 496a80e

Please sign in to comment.