From c98bcb88f43c0784e2878e918d1f5cdda6eb71b0 Mon Sep 17 00:00:00 2001 From: Jonas Berlin Date: Fri, 1 Mar 2013 20:28:21 +0200 Subject: [PATCH 1/5] Outline with dummy content --- plugin/META-INF/MANIFEST.MF | 3 +- .../editors/RobotFrameworkTextfileEditor.java | 17 ++++++ .../editors/outline/ParsedStringEntry.java | 23 ++++++++ .../outline/RobotContentOutlinePage.java | 40 ++++++++++++++ .../outline/RobotOutlineContentProvider.java | 55 +++++++++++++++++++ .../editors/outline/RootCategoryEntry.java | 35 ++++++++++++ 6 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/ParsedStringEntry.java create mode 100644 plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotContentOutlinePage.java create mode 100644 plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotOutlineContentProvider.java create mode 100644 plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RootCategoryEntry.java diff --git a/plugin/META-INF/MANIFEST.MF b/plugin/META-INF/MANIFEST.MF index c55d132..f804657 100644 --- a/plugin/META-INF/MANIFEST.MF +++ b/plugin/META-INF/MANIFEST.MF @@ -10,7 +10,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.ui.editors, org.eclipse.core.resources, org.eclipse.ui.ide, - org.junit;resolution:=optional + org.junit;resolution:=optional, + org.eclipse.ui.views Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Export-Package: com.nitorcreations.robotframework.eclipseide, diff --git a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/RobotFrameworkTextfileEditor.java b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/RobotFrameworkTextfileEditor.java index 5fe713c..c90d745 100644 --- a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/RobotFrameworkTextfileEditor.java +++ b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/RobotFrameworkTextfileEditor.java @@ -25,10 +25,12 @@ import org.eclipse.ui.editors.text.FileDocumentProvider; import org.eclipse.ui.editors.text.TextEditor; import org.eclipse.ui.texteditor.ChainedPreferenceStore; +import org.eclipse.ui.views.contentoutline.IContentOutlinePage; import com.nitorcreations.robotframework.eclipseide.Activator; import com.nitorcreations.robotframework.eclipseide.PluginContext; import com.nitorcreations.robotframework.eclipseide.builder.parser.RobotFile; +import com.nitorcreations.robotframework.eclipseide.editors.outline.RobotContentOutlinePage; /** * https://robotframework.googlecode.com/hg/doc/userguide/ RobotFrameworkUserGuide.html?r=2.6.1 http:/ @@ -43,6 +45,8 @@ public class RobotFrameworkTextfileEditor extends TextEditor { private final ColorManager colorManager; + private RobotContentOutlinePage outlinePage; + public RobotFrameworkTextfileEditor() { colorManager = new ColorManager(); setSourceViewerConfiguration(new RobotSourceViewerConfiguration(colorManager)); @@ -124,6 +128,19 @@ protected void initializeEditor() { IPreferenceStore ourPreferenceStore = Activator.getDefault().getPreferenceStore(); setPreferenceStore(new ChainedPreferenceStore(new IPreferenceStore[] { ourPreferenceStore, baseEditorPreferenceStore })); } + + @Override + public Object getAdapter(Class required) { + if (IContentOutlinePage.class.equals(required)) { + if (outlinePage == null) { + outlinePage = new RobotContentOutlinePage(getDocumentProvider(), this); + if (getEditorInput() != null) + outlinePage.setInput(getEditorInput()); + } + return outlinePage; + } + return super.getAdapter(required); + } } // 190312 1720 xxxx diff --git a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/ParsedStringEntry.java b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/ParsedStringEntry.java new file mode 100644 index 0000000..7892ee3 --- /dev/null +++ b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/ParsedStringEntry.java @@ -0,0 +1,23 @@ +package com.nitorcreations.robotframework.eclipseide.editors.outline; + +import com.nitorcreations.robotframework.eclipseide.structure.ParsedString; + +public class ParsedStringEntry { + final RootCategoryEntry parent; + final ParsedString parsedString; + + public ParsedStringEntry(RootCategoryEntry parent, ParsedString parsedString) { + this.parent = parent; + this.parsedString = parsedString; + } + + public RootCategoryEntry getParent() { + assert parent != null; + return parent; + } + + @Override + public String toString() { + return parsedString.getValue(); + } +} \ No newline at end of file diff --git a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotContentOutlinePage.java b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotContentOutlinePage.java new file mode 100644 index 0000000..f85d143 --- /dev/null +++ b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotContentOutlinePage.java @@ -0,0 +1,40 @@ +package com.nitorcreations.robotframework.eclipseide.editors.outline; + +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.views.contentoutline.ContentOutlinePage; + +import com.nitorcreations.robotframework.eclipseide.editors.RobotFrameworkTextfileEditor; + +public class RobotContentOutlinePage extends ContentOutlinePage { + + // private final RobotFrameworkTextfileEditor robotFrameworkTextfileEditor; + // private final IDocumentProvider documentProvider; + private IEditorInput editorInput; + + public RobotContentOutlinePage(IDocumentProvider documentProvider, RobotFrameworkTextfileEditor robotFrameworkTextfileEditor) { + // this.documentProvider = documentProvider; + // this.robotFrameworkTextfileEditor = robotFrameworkTextfileEditor; + } + + public void setInput(IEditorInput editorInput) { + this.editorInput = editorInput; + } + + @Override + public void createControl(Composite parent) { + super.createControl(parent); + TreeViewer viewer = getTreeViewer(); + viewer.setContentProvider(new RobotOutlineContentProvider()); + viewer.setLabelProvider(new LabelProvider()); + viewer.addSelectionChangedListener(this); + + if (editorInput != null) { + viewer.setInput(editorInput); + } + } + +} diff --git a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotOutlineContentProvider.java b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotOutlineContentProvider.java new file mode 100644 index 0000000..afdd3e7 --- /dev/null +++ b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotOutlineContentProvider.java @@ -0,0 +1,55 @@ +package com.nitorcreations.robotframework.eclipseide.editors.outline; + +import java.util.Collections; + +import org.eclipse.jface.viewers.IContentProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +import com.nitorcreations.robotframework.eclipseide.structure.ParsedString; + +final class RobotOutlineContentProvider implements IContentProvider, ITreeContentProvider { + + @Override + public void dispose() { + + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // System.out.println("InputChanged V " + viewer + " DP " + documentProvider + " EI " + + // robotContentOutlinePage.editorInput); + System.out.println("OLD: " + oldInput); + System.out.println("NEW: " + newInput); + } + + @Override + public Object[] getElements(Object inputElement) { + return new Object[] {// + new RootCategoryEntry(inputElement, "Test cases", Collections.singleton(new ParsedString("User should be able to log in", 1))), // + new RootCategoryEntry(inputElement, "Keywords", Collections.singleton(new ParsedString("Go to login page", 1))),// + new RootCategoryEntry(inputElement, "Variables", Collections.singleton(new ParsedString("${FOO}", 1))),// + }; + } + + @Override + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof RootCategoryEntry) { + return ((RootCategoryEntry) parentElement).getEntries().toArray(); + } + return new Object[0]; + } + + @Override + public Object getParent(Object element) { + if (element instanceof ParsedStringEntry) { + return ((ParsedStringEntry) element).getParent(); + } + return null; + } + + @Override + public boolean hasChildren(Object element) { + return element instanceof RootCategoryEntry; + } +} \ No newline at end of file diff --git a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RootCategoryEntry.java b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RootCategoryEntry.java new file mode 100644 index 0000000..47e5afc --- /dev/null +++ b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RootCategoryEntry.java @@ -0,0 +1,35 @@ +package com.nitorcreations.robotframework.eclipseide.editors.outline; + +import java.util.HashSet; +import java.util.Set; + +import com.nitorcreations.robotframework.eclipseide.structure.ParsedString; + +public class RootCategoryEntry { + final Object input; + final String category; + final Set entries; + + public RootCategoryEntry(Object input, String category, Set parsedStrings) { + this.input = input; + this.category = category; + this.entries = new HashSet(parsedStrings.size()); + for (ParsedString parsedString : parsedStrings) { + ParsedStringEntry entry = new ParsedStringEntry(this, parsedString); + entries.add(entry); + } + } + + public Object getInput() { + return input; + } + + public Set getEntries() { + return entries; + } + + @Override + public String toString() { + return category; + } +} \ No newline at end of file From 78a45e0af7cabbbccaa3a790f993d1a01018d4c0 Mon Sep 17 00:00:00 2001 From: Jonas Berlin Date: Fri, 1 Mar 2013 21:01:29 +0200 Subject: [PATCH 2/5] Outline initialized with proper data when file is updated - no updates yet when file changes --- .../editors/RobotFrameworkTextfileEditor.java | 6 +-- .../outline/RobotOutlineContentProvider.java | 39 +++++++++++++++++-- ...OutlinePage.java => RobotOutlinePage.java} | 24 ++++++------ 3 files changed, 51 insertions(+), 18 deletions(-) rename plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/{RobotContentOutlinePage.java => RobotOutlinePage.java} (55%) diff --git a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/RobotFrameworkTextfileEditor.java b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/RobotFrameworkTextfileEditor.java index c90d745..4509b27 100644 --- a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/RobotFrameworkTextfileEditor.java +++ b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/RobotFrameworkTextfileEditor.java @@ -30,7 +30,7 @@ import com.nitorcreations.robotframework.eclipseide.Activator; import com.nitorcreations.robotframework.eclipseide.PluginContext; import com.nitorcreations.robotframework.eclipseide.builder.parser.RobotFile; -import com.nitorcreations.robotframework.eclipseide.editors.outline.RobotContentOutlinePage; +import com.nitorcreations.robotframework.eclipseide.editors.outline.RobotOutlinePage; /** * https://robotframework.googlecode.com/hg/doc/userguide/ RobotFrameworkUserGuide.html?r=2.6.1 http:/ @@ -45,7 +45,7 @@ public class RobotFrameworkTextfileEditor extends TextEditor { private final ColorManager colorManager; - private RobotContentOutlinePage outlinePage; + private RobotOutlinePage outlinePage; public RobotFrameworkTextfileEditor() { colorManager = new ColorManager(); @@ -133,7 +133,7 @@ protected void initializeEditor() { public Object getAdapter(Class required) { if (IContentOutlinePage.class.equals(required)) { if (outlinePage == null) { - outlinePage = new RobotContentOutlinePage(getDocumentProvider(), this); + outlinePage = new RobotOutlinePage(getDocumentProvider()); if (getEditorInput() != null) outlinePage.setInput(getEditorInput()); } diff --git a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotOutlineContentProvider.java b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotOutlineContentProvider.java index afdd3e7..22a01df 100644 --- a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotOutlineContentProvider.java +++ b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotOutlineContentProvider.java @@ -1,15 +1,26 @@ package com.nitorcreations.robotframework.eclipseide.editors.outline; -import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Set; +import org.eclipse.jface.text.IDocument; import org.eclipse.jface.viewers.IContentProvider; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; +import org.eclipse.ui.texteditor.IDocumentProvider; +import com.nitorcreations.robotframework.eclipseide.builder.parser.RobotFile; +import com.nitorcreations.robotframework.eclipseide.builder.parser.RobotLine; import com.nitorcreations.robotframework.eclipseide.structure.ParsedString; final class RobotOutlineContentProvider implements IContentProvider, ITreeContentProvider { + private final IDocumentProvider documentProvider; + + public RobotOutlineContentProvider(IDocumentProvider documentProvider) { + this.documentProvider = documentProvider; + } + @Override public void dispose() { @@ -19,16 +30,36 @@ public void dispose() { public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { // System.out.println("InputChanged V " + viewer + " DP " + documentProvider + " EI " + // robotContentOutlinePage.editorInput); + System.out.println("V " + viewer); System.out.println("OLD: " + oldInput); System.out.println("NEW: " + newInput); } @Override public Object[] getElements(Object inputElement) { + System.out.println("getElements() " + inputElement); + IDocument document = documentProvider.getDocument(inputElement); + RobotFile rf = RobotFile.get(document); + Set testCases = new LinkedHashSet(); + Set keywords = new LinkedHashSet(); + Set variables = new LinkedHashSet(); + for (RobotLine line : rf.getLines()) { + switch (line.type) { + case TESTCASE_TABLE_TESTCASE_BEGIN: + testCases.add(line.arguments.get(0)); + break; + case KEYWORD_TABLE_KEYWORD_BEGIN: + keywords.add(line.arguments.get(0)); + break; + case VARIABLE_TABLE_LINE: + variables.add(line.arguments.get(0)); + break; + } + } return new Object[] {// - new RootCategoryEntry(inputElement, "Test cases", Collections.singleton(new ParsedString("User should be able to log in", 1))), // - new RootCategoryEntry(inputElement, "Keywords", Collections.singleton(new ParsedString("Go to login page", 1))),// - new RootCategoryEntry(inputElement, "Variables", Collections.singleton(new ParsedString("${FOO}", 1))),// + new RootCategoryEntry(inputElement, "Test cases", testCases), // + new RootCategoryEntry(inputElement, "Keywords", keywords),// + new RootCategoryEntry(inputElement, "Variables", variables),// }; } diff --git a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotContentOutlinePage.java b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotOutlinePage.java similarity index 55% rename from plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotContentOutlinePage.java rename to plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotOutlinePage.java index f85d143..3f4b264 100644 --- a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotContentOutlinePage.java +++ b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotOutlinePage.java @@ -1,23 +1,20 @@ package com.nitorcreations.robotframework.eclipseide.editors.outline; import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.views.contentoutline.ContentOutlinePage; -import com.nitorcreations.robotframework.eclipseide.editors.RobotFrameworkTextfileEditor; +public class RobotOutlinePage extends ContentOutlinePage { -public class RobotContentOutlinePage extends ContentOutlinePage { - - // private final RobotFrameworkTextfileEditor robotFrameworkTextfileEditor; - // private final IDocumentProvider documentProvider; + private final IDocumentProvider documentProvider; private IEditorInput editorInput; - public RobotContentOutlinePage(IDocumentProvider documentProvider, RobotFrameworkTextfileEditor robotFrameworkTextfileEditor) { - // this.documentProvider = documentProvider; - // this.robotFrameworkTextfileEditor = robotFrameworkTextfileEditor; + public RobotOutlinePage(IDocumentProvider documentProvider) { + this.documentProvider = documentProvider; } public void setInput(IEditorInput editorInput) { @@ -28,13 +25,18 @@ public void setInput(IEditorInput editorInput) { public void createControl(Composite parent) { super.createControl(parent); TreeViewer viewer = getTreeViewer(); - viewer.setContentProvider(new RobotOutlineContentProvider()); - viewer.setLabelProvider(new LabelProvider()); - viewer.addSelectionChangedListener(this); + viewer.setContentProvider(new RobotOutlineContentProvider(documentProvider)); + viewer.setLabelProvider(new LabelProvider()); // we could use custom label provider here to get fancy icons if (editorInput != null) { viewer.setInput(editorInput); } } + @Override + public void selectionChanged(SelectionChangedEvent event) { + super.selectionChanged(event); + + // TODO Jump to selection + } } From 3e60f22b2b3c3159e56e50ef616a74b3647afc4a Mon Sep 17 00:00:00 2001 From: Matthias Jacob Date: Wed, 27 Apr 2016 14:27:18 +0200 Subject: [PATCH 3/5] Preserve order of outline entries --- .../eclipseide/editors/outline/RootCategoryEntry.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RootCategoryEntry.java b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RootCategoryEntry.java index 47e5afc..3813d4c 100644 --- a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RootCategoryEntry.java +++ b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RootCategoryEntry.java @@ -1,6 +1,6 @@ package com.nitorcreations.robotframework.eclipseide.editors.outline; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import com.nitorcreations.robotframework.eclipseide.structure.ParsedString; @@ -13,7 +13,7 @@ public class RootCategoryEntry { public RootCategoryEntry(Object input, String category, Set parsedStrings) { this.input = input; this.category = category; - this.entries = new HashSet(parsedStrings.size()); + this.entries = new LinkedHashSet(parsedStrings.size()); for (ParsedString parsedString : parsedStrings) { ParsedStringEntry entry = new ParsedStringEntry(this, parsedString); entries.add(entry); From 3027d82c3b9bd3fd2d36cf6f80c2feb2c5a94796 Mon Sep 17 00:00:00 2001 From: Matthias Jacob Date: Tue, 26 Apr 2016 23:37:40 +0200 Subject: [PATCH 4/5] Allow the selection of a single entry only --- .../eclipseide/editors/outline/RobotOutlinePage.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotOutlinePage.java b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotOutlinePage.java index 3f4b264..0f9406a 100644 --- a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotOutlinePage.java +++ b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/RobotOutlinePage.java @@ -3,6 +3,7 @@ import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.texteditor.IDocumentProvider; @@ -39,4 +40,9 @@ public void selectionChanged(SelectionChangedEvent event) { // TODO Jump to selection } + + @Override + protected int getTreeStyle() { + return SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL; + } } From 40e5c72a0c70abdbfea434fa175cf110576aedfb Mon Sep 17 00:00:00 2001 From: Matthias Jacob Date: Fri, 29 Apr 2016 00:01:24 +0200 Subject: [PATCH 5/5] Clicking an outline entry moves the cursor to the associated spot in the editor --- .../editors/RobotFrameworkTextfileEditor.java | 32 ++++++++++++++++++- .../editors/outline/ParsedStringEntry.java | 8 +++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/RobotFrameworkTextfileEditor.java b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/RobotFrameworkTextfileEditor.java index 4509b27..7f273f7 100644 --- a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/RobotFrameworkTextfileEditor.java +++ b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/RobotFrameworkTextfileEditor.java @@ -21,15 +21,20 @@ import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.editors.text.FileDocumentProvider; import org.eclipse.ui.editors.text.TextEditor; import org.eclipse.ui.texteditor.ChainedPreferenceStore; +import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.views.contentoutline.IContentOutlinePage; import com.nitorcreations.robotframework.eclipseide.Activator; import com.nitorcreations.robotframework.eclipseide.PluginContext; import com.nitorcreations.robotframework.eclipseide.builder.parser.RobotFile; +import com.nitorcreations.robotframework.eclipseide.editors.outline.ParsedStringEntry; import com.nitorcreations.robotframework.eclipseide.editors.outline.RobotOutlinePage; /** @@ -93,7 +98,7 @@ public IDocument getEditedDocument() { } public IFile getEditedFile() { - return (IFile) getEditorInput().getAdapter(IFile.class); + return getEditorInput().getAdapter(IFile.class); } @Override @@ -134,6 +139,7 @@ public Object getAdapter(Class required) { if (IContentOutlinePage.class.equals(required)) { if (outlinePage == null) { outlinePage = new RobotOutlinePage(getDocumentProvider()); + outlinePage.addSelectionChangedListener(new RobotOutlineSelectionChangedListener(this)); if (getEditorInput() != null) outlinePage.setInput(getEditorInput()); } @@ -141,6 +147,30 @@ public Object getAdapter(Class required) { } return super.getAdapter(required); } + + private final class RobotOutlineSelectionChangedListener implements ISelectionChangedListener { + private final ITextEditor textEditor; + + public RobotOutlineSelectionChangedListener(ITextEditor textEditor) { + this.textEditor = textEditor; + } + + @Override + public void selectionChanged(SelectionChangedEvent event) { + if (event.getSelection() instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection) event.getSelection(); + + // so far, we only support the selection of one entry at a time - see RobotOutlinePage#getTreeStyle() + Object domain = selection.getFirstElement(); + if (domain instanceof ParsedStringEntry) { + ParsedStringEntry lineEntry = (ParsedStringEntry) domain; + int startCharPos = lineEntry.getStartCharPos(); + int endCharPos = lineEntry.getEndCharPos(); + textEditor.selectAndReveal(startCharPos, endCharPos - startCharPos); + } + } + } + } } // 190312 1720 xxxx diff --git a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/ParsedStringEntry.java b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/ParsedStringEntry.java index 7892ee3..f6b143b 100644 --- a/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/ParsedStringEntry.java +++ b/plugin/src/main/java/com/nitorcreations/robotframework/eclipseide/editors/outline/ParsedStringEntry.java @@ -16,6 +16,14 @@ public RootCategoryEntry getParent() { return parent; } + public int getStartCharPos() { + return parsedString.getArgCharPos(); + } + + public int getEndCharPos() { + return parsedString.getArgEndCharPos(); + } + @Override public String toString() { return parsedString.getValue();