Permalink
Browse files

Patches contributed by Thomas Fletcher:

* new Outline doing partial updates if possible
* It provides both alphabetical and file ordered based sorting
* Added support for background document synchronizing so that as we expand beyond functions we can better handle incremental changes (or use the AST for 2.0)
* Added new icons for the Outline
* Added a static logging method to the plugin.  
* Added in several fixes to NPE
  • Loading branch information...
1 parent 09b6010 commit dbcfd96f6ca3269ff645fa897d25d668f9d0ba67 jasonsantos committed Dec 2, 2009
@@ -33,7 +33,9 @@
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
import org.keplerproject.ldt.core.project.LuaProjectNature;
import org.osgi.framework.BundleContext;
@@ -30,12 +30,12 @@
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.keplerproject.ldt.core.ILuaEntry;
import org.keplerproject.ldt.core.LuaProject;
import org.keplerproject.ldt.core.LuaScriptsSpecs;
import org.keplerproject.ldt.core.luadoc.LuadocGenerator;
import org.keplerproject.luajava.LuaState;
-import org.keplerproject.luajava.LuaStateFactory;
/**
* The Lua Code DeltaVisitor remade to fit Lua 5.1 API
@@ -21,6 +21,7 @@
import java.io.IOException;
import java.net.URL;
+import org.keplerproject.ldt.core.LuaCorePlugin;
import org.keplerproject.ldt.core.utils.ResourceUtils;
import org.keplerproject.luajava.JavaFunction;
import org.keplerproject.luajava.LuaException;
@@ -53,6 +54,13 @@ private static String dumpTable(LuaState L) {
return sb.toString();
}
+ /**
+ * Attempt to load the file specified by the URL
+ * @param L The lua state to use for the loader
+ * @param u The URL to load
+ * @return 0 if there are no errors loading the string
+ * @throws IOException If there is a problem acessing the URL content
+ */
private static int LoadFile(LuaState L, URL u) throws IOException {
int res = -1;
@@ -61,6 +69,7 @@ private static int LoadFile(LuaState L, URL u) throws IOException {
res = L.LloadString(body);
}
+
return res;
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -238,7 +238,7 @@ public String getInstanceId() {
public LuaOutlinePage getContentOutline() {
if (luaOutlinePage == null ) {
luaOutlinePage = new LuaOutlinePage(getDocumentProvider(), this);
- luaOutlinePage.setInput((IEditorInput) this);
+ luaOutlinePage.setInput(this);
}
return luaOutlinePage;
@@ -1,42 +1,138 @@
package org.keplerproject.ldt.ui.editors;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
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 org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+import org.keplerproject.ldt.ui.LDTUIPlugin;
import org.keplerproject.ldt.ui.editors.outline.LuaOutlineContentProvider;
import org.keplerproject.ldt.ui.editors.outline.LuaOutlineLabelProvider;
+import org.keplerproject.ldt.ui.editors.outline.LuaOutlineContentProvider.FunctionDefinition;
-public class LuaOutlinePage extends ContentOutlinePage implements
- IContentOutlinePage {
+public class LuaOutlinePage extends ContentOutlinePage implements IContentOutlinePage {
- IEditorInput in;
+ LuaEditor fTargetEditor;
+
+ IAction fSortByName;
+
+ /**
+ * Provide a viewer comparator that sorts items based on their offset
+ * locations in the document. This allows items to be listed in their
+ * order of appearance in the file.
+ */
+ class DocumentOffsetComparator extends ViewerComparator {
+ public int compare(Viewer viewer, Object arg0, Object arg1) {
+ if(!(arg0 instanceof FunctionDefinition) || !(arg1 instanceof FunctionDefinition)) {
+ return super.compare(viewer, arg0, arg1);
+ }
+ FunctionDefinition fd0 = (FunctionDefinition)arg0;
+ FunctionDefinition fd1 = (FunctionDefinition)arg1;
+ return fd0.getCharacterOffset() - fd1.getCharacterOffset();
+ }
+
+ public boolean isSorterProperty(Object element, String property) {
+ if(LuaOutlineContentProvider.OFFSET_PROPERTY.equals(property)) {
+ return true;
+ }
+ return false;
+ }
+ }
- public LuaOutlinePage(IDocumentProvider documentProvider,
- LuaEditor luaEditor) {
+ public LuaOutlinePage(IDocumentProvider documentProvider, LuaEditor luaEditor) {
super();
+ setInput(luaEditor);
}
- public void setInput(IEditorInput editorInput) {
- in = editorInput;
- System.out.println("setInput");
+ public void setInput(LuaEditor luaEditor) {
+ fTargetEditor = (LuaEditor)luaEditor;
+
+ TreeViewer viewer = getTreeViewer();
+ if(viewer != null) {
+ viewer.setInput(fTargetEditor);
+ }
+ }
+
+ public void createControl(Composite parent) {
+ createActions();
+
+ super.createControl(parent);
+
+ TreeViewer viewer = getTreeViewer();
+
+ viewer.setLabelProvider(new LuaOutlineLabelProvider());
+ viewer.setContentProvider(new LuaOutlineContentProvider());
+ viewer.setInput(fTargetEditor);
+
+ viewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ setEditorPosition();
+ }
+ });
+
+ addActions();
+ updateSortingStyle();
}
- private void sysout(String name) {
- // TODO Auto-generated method stub
+ protected void createActions() {
+ String SORT_ICON_PATH = "icons/sort.gif";
+ fSortByName = new Action("Sort") {
+ public void run() {
+ updateSortingStyle();
+ }
+ };
+ fSortByName.setChecked(false);
+ fSortByName.setImageDescriptor(LDTUIPlugin.getImageDescriptor(SORT_ICON_PATH));
+ }
+
+ protected void addActions() {
+ IToolBarManager manager = getSite().getActionBars().getToolBarManager();
+ manager.add(fSortByName);
}
- public void createControl(Composite parent) {
- super.createControl(parent);
- TreeViewer viewer= getTreeViewer();
- viewer.setContentProvider(new LuaOutlineContentProvider());
- viewer.setLabelProvider(new LuaOutlineLabelProvider());
- viewer.addSelectionChangedListener(this);
- viewer.setInput(in);
- }
+ protected void updateSortingStyle() {
+ TreeViewer viewer = getTreeViewer();
+ if(viewer == null) {
+ return;
+ }
+ if(fSortByName.isChecked()) {
+ viewer.setComparator(new ViewerComparator());
+ } else {
+ viewer.setComparator(new DocumentOffsetComparator());
+ }
+ }
-}
+ protected void setEditorPosition() {
+ IStructuredSelection ss = (IStructuredSelection)getSelection();
+ if(ss == null || ss.isEmpty()) {
+ return;
+ }
+
+ Object item = ss.getFirstElement();
+ if(!(item instanceof FunctionDefinition)) {
+ return;
+ }
+
+ FunctionDefinition fd = (FunctionDefinition)item;
+ TextSelection ts = new TextSelection(fd.getCharacterOffset(),
+ fd.getCharacterEndOffset() - fd.getCharacterOffset());
+
+ ISelectionProvider provider = fTargetEditor.getSelectionProvider();
+ if(provider != null) {
+ provider.setSelection(ts);
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit dbcfd96

Please sign in to comment.