Skip to content

Commit

Permalink
also highlight opened resource
Browse files Browse the repository at this point in the history
  • Loading branch information
koentsje committed Apr 5, 2014
1 parent 77a3b7e commit bebddf2
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,24 @@ private void selectFile(File file) {
IFileStore fileStore = EFS.getLocalFileSystem().getStore(path);
IFileInfo fileInfo = fileStore.fetchInfo();
if (!fileInfo.exists()) return;
IResource resource = null;
if (fileInfo.isDirectory()) {
IContainer container = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(path);
if (container != null) {
expandWorkspaceDirectory(container);
} else {
expandSystemDirectory(fileStore);
}
resource = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(path);
} else {
resource = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
openFileInEditor(fileStore);
}
if (resource != null) {
expandWorkspaceResource(resource);
} else {
expandSystemDirectory(fileStore);
}
} catch (IOException e) {
ForgeUIPlugin.log(e);
}
}

private void expandWorkspaceDirectory(IContainer container) {
private void expandWorkspaceResource(IResource container) {
IWorkbenchPage workbenchPage = getActiveWorkbenchPage();
if (workbenchPage != null) {
IViewPart projectExplorer = workbenchPage.findView("org.eclipse.ui.navigator.ProjectExplorer");
Expand All @@ -165,13 +167,13 @@ private IWorkbenchPage getActiveWorkbenchPage() {
return result;
}

private void expandInProjectExplorer(CommonNavigator projectExplorer, IContainer container) {
private void expandInProjectExplorer(CommonNavigator projectExplorer, IResource container) {
projectExplorer.selectReveal(new StructuredSelection(container));
TreeViewer treeViewer = projectExplorer.getCommonViewer();
treeViewer.expandToLevel(container, 1);
}

private void expandInPackageExplorer(IViewPart packageExplorer, IContainer container) {
private void expandInPackageExplorer(IViewPart packageExplorer, IResource container) {
if (packageExplorer instanceof ISetSelectionTarget) {
((ISetSelectionTarget)packageExplorer).selectReveal(new StructuredSelection(container));
}
Expand Down

0 comments on commit bebddf2

Please sign in to comment.