Commit c6f5fce6 authored by Miklos Magyari's avatar Miklos Magyari Committed by Arpad Lovassy
Browse files

Fixed cursor navigation for outline selection (issue #488)

parent 3068817d
...@@ -40,7 +40,12 @@ import org.eclipse.titan.designer.parsers.GlobalParser; ...@@ -40,7 +40,12 @@ import org.eclipse.titan.designer.parsers.GlobalParser;
import org.eclipse.titan.designer.parsers.ProjectSourceParser; import org.eclipse.titan.designer.parsers.ProjectSourceParser;
import org.eclipse.titan.designer.preferences.PreferenceConstants; import org.eclipse.titan.designer.preferences.PreferenceConstants;
import org.eclipse.ui.IActionBars; import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.texteditor.AbstractTextEditor; import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.ui.views.contentoutline.ContentOutline;
import org.eclipse.ui.views.contentoutline.ContentOutlinePage; import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
/** /**
...@@ -341,24 +346,31 @@ public final class OutlinePage extends ContentOutlinePage { ...@@ -341,24 +346,31 @@ public final class OutlinePage extends ContentOutlinePage {
public void selectionChanged(final SelectionChangedEvent event) { public void selectionChanged(final SelectionChangedEvent event) {
super.selectionChanged(event); super.selectionChanged(event);
final ISelection selection = event.getSelection(); final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (selection.isEmpty()) { if (page == null) {
return; return;
} }
final IWorkbenchPart part = page.getActivePart();
final Object selectedElement = ((IStructuredSelection) selection).getFirstElement(); if (part instanceof ContentOutline) {
Identifier identifier = null; final ISelection selection = event.getSelection();
if (selectedElement instanceof IOutlineElement) { if (selection.isEmpty()) {
identifier = ((IOutlineElement) selectedElement).getIdentifier(); return;
} }
if (identifier == null || identifier.getLocation() == null) { final Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
return; Identifier identifier = null;
if (selectedElement instanceof IOutlineElement) {
identifier = ((IOutlineElement) selectedElement).getIdentifier();
}
if (identifier == null || identifier.getLocation() == null) {
return;
}
final Location location = identifier.getLocation();
editor.selectAndReveal(location.getOffset(), location.getEndOffset() - location.getOffset());
} }
final Location location = identifier.getLocation();
editor.selectAndReveal(location.getOffset(), location.getEndOffset() - location.getOffset());
} }
private Module getModule() { private Module getModule() {
......
...@@ -37,10 +37,13 @@ import org.eclipse.jface.viewers.ISelection; ...@@ -37,10 +37,13 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import org.eclipse.titan.designer.Activator; import org.eclipse.titan.designer.Activator;
import org.eclipse.titan.designer.HeadlessStorage; import org.eclipse.titan.designer.HeadlessStorage;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.Module; import org.eclipse.titan.designer.AST.Module;
import org.eclipse.titan.designer.declarationsearch.Declaration; import org.eclipse.titan.designer.declarationsearch.Declaration;
import org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor; import org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor;
...@@ -463,10 +466,15 @@ public final class TTCN3Editor extends AbstractDecoratedTextEditor implements IS ...@@ -463,10 +466,15 @@ public final class TTCN3Editor extends AbstractDecoratedTextEditor implements IS
if (declaration == null) { if (declaration == null) {
return; return;
} }
TreeSelection selection = (TreeSelection)outlinePage.getSelection();
Object segments[] = new Object[2]; TreePath[] paths = selection.getPaths();
segments[1] = declaration.getAssignment(); TreePath tp = paths.length > 0 ? paths[0] : null;
outlinePage.setSelection(new StructuredSelection(segments));
if (tp == null || ! tp.getLastSegment().equals(declaration.getAssignment())) {
Object segments[] = new Object[2];
segments[1] = declaration.getAssignment();
outlinePage.setSelection(new StructuredSelection(segments));
}
} }
@Override @Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment