Commit ad6ae805 authored by Sebastian Pretscher's avatar Sebastian Pretscher

Merge branch 'master' of git@github.com:jroith/cup-eclipse.git

parents 79b1889e 01daf031
package de.tum.in.www2.cupplugin.editors;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
......@@ -29,18 +24,13 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
import org.eclipse.ui.part.FileEditorInput;
import de.in.tum.www2.cup.CupParser;
import de.in.tum.www2.cup.DefaultErrorReporter;
import de.in.tum.www2.cup.IErrorReporter;
import de.in.tum.www2.cup.Position;
import de.in.tum.www2.cup.Range;
import de.in.tum.www2.cup.Utility;
import de.in.tum.www2.cup.analysis.*;
import de.in.tum.www2.cup.ast.*;
import de.in.tum.www2.cup.ast.Package;
import de.in.tum.www2.cup.MultiErrorReporter;
import de.tum.in.www2.cupplugin.model.*;
public class CupContentOutlinePage extends ContentOutlinePage implements
......@@ -49,13 +39,13 @@ public class CupContentOutlinePage extends ContentOutlinePage implements
private CupTextEditor editor;
private IDocument doc;
private TreeViewer viewer;
public CupContentOutlinePage(CupTextEditor editor) {
this.editor = editor;
doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
Model.getInstanceForDocument(doc).registerModelObserver(this);
}
@Override
public void dispose() {
System.out.println("DISPOSING OUTLINE OBSERVER!");
......@@ -63,6 +53,18 @@ public class CupContentOutlinePage extends ContentOutlinePage implements
super.dispose();
};
public void jumpToPosition(Position pos) {
if (viewer == null)
return;
OutlineEntry root = (OutlineEntry) viewer.getInput();
if (root != null) {
// viewer.setSelection(selection);
}
}
@Override
public void modelChanged(Model model) {
ParserResult result = model.getAstModel();
......
......@@ -4,23 +4,29 @@ import org.eclipse.debug.ui.actions.ToggleBreakpointAction;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.IVerticalRulerInfo;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import de.in.tum.www2.cup.Position;
import de.tum.in.www2.cupplugin.controller.Controller;
import de.tum.in.www2.cupplugin.model.Model;
public class CupTextEditor extends TextEditor {
IVerticalRulerInfo ruler = null;
private CupContentOutlinePage outlinePage;
private Position lastPosition;
static Color gray;
static Color blue;
......@@ -59,6 +65,44 @@ public class CupTextEditor extends TextEditor {
// ComplexSymbolFactory f = new ComplexSymbolFactory();
// java_cup.Lexer = new java_cup.Lexer(arg0, f);
}
// adapted from http://javadude.googlecode.com/svn/trunk/com.javadude.antxr.eclipse.ui/src/com/javadude/antxr/eclipse/ui/editor/AntxrEditor.java
public Position getCursorPos() {
int caret = -1;
int line = -1;
int column = -1;
ISourceViewer sourceViewer = getSourceViewer();
if (sourceViewer != null) {
StyledText styledText = sourceViewer.getTextWidget();
caret = AbstractTextEditor.widgetOffset2ModelOffset(sourceViewer,
styledText.getCaretOffset());
IDocument document = sourceViewer.getDocument();
if (document != null) {
try {
line = document.getLineOfOffset(caret) + 1;
column = caret - document.getLineOfOffset(caret); // TODO: off by one?
} catch (BadLocationException e) {
// ignore
}
}
}
return new Position(line, column, caret);
}
@Override
protected void handleCursorPositionChanged() {
Position position = getCursorPos();
if (position != lastPosition) {
lastPosition = position;
handlePositionChanged(position);
}
super.handleCursorPositionChanged();
}
protected void handlePositionChanged (Position position) {
if (outlinePage != null)
outlinePage.jumpToPosition(position);
}
@Override
public void dispose() {
......
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