Skip to content

Commit

Permalink
Created a new LuaPerspective
Browse files Browse the repository at this point in the history
Fixed Context Menu Contributions for accessing File and Project Wizards
Preliminary support for an Outline View
  • Loading branch information
jasonsantos committed Jan 30, 2009
1 parent b0f42ec commit 4fe762e
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 3 deletions.
4 changes: 3 additions & 1 deletion org.keplerproject.ldt.ui/META-INF/MANIFEST.MF
Expand Up @@ -13,7 +13,9 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui.workbench.texteditor,
org.eclipse.jface.text,
org.eclipse.ui.ide,
org.keplerproject.ldt.core;bundle-version="1.1.0";visibility:=reexport
org.keplerproject.ldt.core;bundle-version="1.1.0";visibility:=reexport,
org.eclipse.ui.console,
org.eclipse.ui.views
Eclipse-LazyStart: true
Export-Package: org.keplerproject.ldt.ui,
org.keplerproject.ldt.ui.editors,
Expand Down
12 changes: 10 additions & 2 deletions org.keplerproject.ldt.ui/plugin.xml
Expand Up @@ -37,11 +37,10 @@
canFinishEarly="true"
category="org.keplerproject.ldt.ui.luaCategory"
class="org.keplerproject.ldt.ui.wizards.LuaProjectWizard"
finalPerspective="all"
finalPerspective="org.keplerproject.ldt.ui.LuaPerspective"
hasPages="true"
id="org.keplerproject.ldt.ui.luaProject.Wizard"
name="New Lua Project"
preferredPerspectives="all"
project="true"
icon="icons/project.gif">
<description>
Expand Down Expand Up @@ -134,6 +133,15 @@
name="LuaSpecs"
point="org.eclipse.core.runtime.preferences">
</extension>
<extension
point="org.eclipse.ui.perspectives">
<perspective
class="org.keplerproject.ldt.ui.LuaPerspective"
icon="icons/luaeclipse.icon.small.lua.gif"
id="org.keplerproject.ldt.ui.LuaPerspective"
name="Lua">
</perspective>
</extension>



Expand Down
@@ -0,0 +1,96 @@
package org.keplerproject.ldt.ui;

import org.eclipse.ui.IFolderLayout;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;
import org.eclipse.ui.console.IConsoleConstants;
import org.keplerproject.ldt.ui.wizards.LuaFileWizard;
import org.keplerproject.ldt.ui.wizards.LuaProjectWizard;

public class LuaPerspective implements IPerspectiveFactory {


private IPageLayout factory;

public LuaPerspective() {
super();
}

public void createInitialLayout(IPageLayout factory) {
this.factory = factory;
addViews();
addActionSets();
addNewWizardShortcuts();
addPerspectiveShortcuts();
addViewShortcuts();
}

private void addViews() {
// Creates the overall folder layout.
// Note that each new Folder uses a percentage of the remaining
// EditorArea.

IFolderLayout bottom = factory.createFolder("bottomRight", // NON-NLS-1
IPageLayout.BOTTOM, 0.75f, factory.getEditorArea());

bottom.addView(IPageLayout.ID_PROBLEM_VIEW);
bottom.addView("org.eclipse.team.ui.GenericHistoryView"); // NON-NLS-1
bottom.addPlaceholder(IConsoleConstants.ID_CONSOLE_VIEW);

IFolderLayout topLeft = factory.createFolder("topLeft", // NON-NLS-1
IPageLayout.LEFT, 0.25f, factory.getEditorArea());

topLeft.addView(IPageLayout.ID_RES_NAV);

IFolderLayout topRight = factory.createFolder("topRight", // NON-NLS-1
IPageLayout.RIGHT, 0.75f, factory.getEditorArea());

topRight.addView(IPageLayout.ID_OUTLINE);

factory.addFastView("org.eclipse.team.ccvs.ui.RepositoriesView", 0.50f); // NON-NLS-1
factory.addFastView("org.eclipse.team.sync.views.SynchronizeView",
0.50f); // NON-NLS-1
}

private void addActionSets() {
factory.addActionSet("org.eclipse.debug.ui.launchActionSet"); // NON-NLS-1
factory.addActionSet("org.eclipse.debug.ui.debugActionSet"); // NON-NLS-1
factory.addActionSet("org.eclipse.debug.ui.profileActionSet"); // NON-NLS-1
factory.addActionSet("org.eclipse.team.ui.actionSet"); // NON-NLS-1
factory.addActionSet("org.eclipse.team.cvs.ui.CVSActionSet"); // NON-NLS-1
factory.addActionSet("org.eclipse.ant.ui.actionSet.presentation"); // NON-NLS-1
factory.addActionSet(IPageLayout.ID_NAVIGATE_ACTION_SET); // NON-NLS-1
}

private void addPerspectiveShortcuts() {
factory
.addPerspectiveShortcut("org.eclipse.team.ui.TeamSynchronizingPerspective"); // NON-NLS-1
factory
.addPerspectiveShortcut("org.eclipse.team.cvs.ui.cvsPerspective"); // NON-NLS-1
factory.addPerspectiveShortcut("org.eclipse.ui.resourcePerspective"); // NON-NLS-1
}

private void addNewWizardShortcuts() {

factory.addNewWizardShortcut(LuaProjectWizard.WIZARD_ID);
factory.addNewWizardShortcut(LuaFileWizard.WIZARD_ID);
// factory.addNewWizardShortcut(RubyNewModuleWizard.WIZARD_ID);
// factory.addNewWizardShortcut(RubyNewFileWizard.WIZARD_ID);

factory
.addNewWizardShortcut("org.eclipse.team.cvs.ui.newProjectCheckout");// NON-NLS-1
factory.addNewWizardShortcut("org.eclipse.ui.wizards.new.folder");// NON-NLS-1
factory.addNewWizardShortcut("org.eclipse.ui.wizards.new.file");// NON-NLS-1
}

private void addViewShortcuts() {
factory.addShowViewShortcut("org.eclipse.team.ccvs.ui.AnnotateView"); // NON-NLS-1
factory.addShowViewShortcut("org.eclipse.team.ui.GenericHistoryView"); // NON-NLS-1
factory.addShowViewShortcut(IConsoleConstants.ID_CONSOLE_VIEW);
factory.addShowViewShortcut(IPageLayout.ID_RES_NAV);
factory.addShowViewShortcut(IPageLayout.ID_PROBLEM_VIEW);
factory.addShowViewShortcut(IPageLayout.ID_OUTLINE);
}


}
Expand Up @@ -22,6 +22,7 @@

import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.IVerticalRuler;
Expand All @@ -35,6 +36,7 @@
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
import org.eclipse.ui.texteditor.DefaultRangeIndicator;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.keplerproject.ldt.ui.LDTUIPlugin;

/**
Expand All @@ -56,6 +58,8 @@ public class LuaEditor extends AbstractDecoratedTextEditor {

private String finstanceId;

private LuaOutlinePage luaOutlinePage;

public LuaEditor() {
super();
// initialize the color manager
Expand Down Expand Up @@ -139,6 +143,8 @@ protected LuaSourceViewerConfiguration createSourceConfiguration(
protected LuaColorManager createColorManager() {
return new LuaColorManager();
}



@Override
public void dispose() {
Expand Down Expand Up @@ -229,5 +235,31 @@ public LuaSourceViewerConfiguration getLuaSourceViewer() {
public String getInstanceId() {
return finstanceId;
}

public LuaOutlinePage getContentOutline() {
if (luaOutlinePage == null ) {
luaOutlinePage = new LuaOutlinePage(getDocumentProvider(), this);

luaOutlinePage.setInput(getEditorInput());
}

return luaOutlinePage;
}


@Override
public Object getAdapter(Class adapter) {

if (IContentOutlinePage.class.equals(adapter)) {

return getContentOutline();
}


return super.getAdapter(adapter);
}

}



Expand Up @@ -28,6 +28,8 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.BadLocationException;
Expand All @@ -44,6 +46,7 @@
import org.keplerproject.ldt.ui.editors.lex.Symbol;
import org.keplerproject.ldt.ui.editors.lex.sym;


/**
* A embeded Folding Reconcilier. One day a put it out of here. for now fold
* just functions and multiline comments.
Expand Down Expand Up @@ -99,6 +102,28 @@ public void initialReconcile() {
private Map deleteAnnotations;
private Map newAnnotations;


protected void registerFunction(String line) {
Pattern p1 = Pattern.compile("function\\s+(\\w+)\\s*?[(]([^)]*?)[)]");
Pattern p2 = Pattern.compile("(\\w+)\\s*?[=]\\s*?function\\s*?[(]([^)]*?)[)]");
Matcher m = p1.matcher(line);
Matcher n = p2.matcher(line);

boolean foundStraight=false;
boolean foundLambda=false;
foundLambda = n.find() || (foundStraight = m.find());

while(foundStraight || foundLambda) {
String functionName = foundStraight ? m.group(1) : n.group(1);
String parameters = foundStraight ? m.group(2) : n.group(2);

System.out.println("Function:"+functionName);
System.out.println("Parameters:"+parameters);

foundLambda = n.find() || (foundStraight = m.find());
}
}

protected void calculatePositions() {
// if (reditor.isDirty())
// return;
Expand Down Expand Up @@ -176,6 +201,13 @@ else if (lineb1 == '\r' || lineb1 == '\n')
while (symbol.sym != sym.EOF) {
//symbol.left -1 (because jflex return line starting at 1 instead of 0)
IRegion lineRegion = doc.getLineInformation(symbol.left -1);

if (symbol.sym == sym.FUNCTION) {
String functionName = doc.get(lineRegion.getOffset(), lineRegion.getLength());
registerFunction(functionName);
}


if (onMultStr == 0) {
if (symbol.sym == sym.DO || symbol.sym == sym.FUNCTION) {
stk.push(new Object[] { lineRegion, symbol });
Expand Down
@@ -0,0 +1,42 @@
package org.keplerproject.ldt.ui.editors;

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 org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.keplerproject.ldt.ui.editors.outline.LuaOutlineContentProvider;
import org.keplerproject.ldt.ui.editors.outline.LuaOutlineLabelProvider;

public class LuaOutlinePage extends ContentOutlinePage implements
IContentOutlinePage {

IEditorInput in;

public LuaOutlinePage(IDocumentProvider documentProvider,
LuaEditor luaEditor) {
super();
}

public void setInput(IEditorInput editorInput) {
in = editorInput;
System.out.println("setInput");
}

private void sysout(String name) {
// TODO Auto-generated method stub

}

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);
}


}
@@ -0,0 +1,37 @@
package org.keplerproject.ldt.ui.editors.outline;

import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

public class LuaOutlineContentProvider implements ITreeContentProvider {

public void dispose() {
}

public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// TODO Auto-generated method stub
System.out.println(oldInput.toString() + '>'+ newInput.toString());
}

public Object[] getChildren(Object parentElement) {
// TODO Auto-generated method stub
return null;
}

public Object getParent(Object element) {
// TODO Auto-generated method stub
return null;
}

public boolean hasChildren(Object element) {
// TODO Auto-generated method stub
return false;
}

public Object[] getElements(Object inputElement) {
// TODO Auto-generated method stub
return null;
}

}
@@ -0,0 +1,28 @@
package org.keplerproject.ldt.ui.editors.outline;

import org.eclipse.jface.viewers.IBaseLabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;

public class LuaOutlineLabelProvider implements IBaseLabelProvider {

public void addListener(ILabelProviderListener listener) {
// TODO Auto-generated method stub

}

public void dispose() {
// TODO Auto-generated method stub

}

public boolean isLabelProperty(Object element, String property) {
// TODO Auto-generated method stub
return false;
}

public void removeListener(ILabelProviderListener listener) {
// TODO Auto-generated method stub

}

}
Expand Up @@ -58,6 +58,9 @@
* @version $Id$
*/
public class LuaFileWizard extends Wizard implements INewWizard {

public static final String WIZARD_ID = "org.keplerproject.ldt.ui.luaFile.Wizard"; //$NON-NLS-1$

private WizardNewFileCreationPage page;
private IStructuredSelection selection;

Expand Down
Expand Up @@ -47,6 +47,9 @@
* @version $Id$
*/
public class LuaProjectWizard extends Wizard implements INewWizard {

public static final String WIZARD_ID = "org.keplerproject.ldt.ui.luaProject.Wizard"; //$NON-NLS-1$

protected WizardNewProjectCreationPage prjCreationPage;
protected IProject newProject;
protected IWorkbench workbench;
Expand Down

0 comments on commit 4fe762e

Please sign in to comment.