[SCM] Lisaac compiler branch, master, updated. lisaac-0.12-501-g18c67bd

Damien Bouvarel dams.bouvarel at wanadoo.fr
Thu Sep 24 22:51:43 UTC 2009


The following commit has been merged in the master branch:
commit 18c67bd07dc3800baf6405d2cfa271fd2c5f255c
Author: Damien Bouvarel <dams.bouvarel at wanadoo.fr>
Date:   Fri Sep 25 00:51:06 2009 +0200

    syntax colors for completion and outline

diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/editors/ColorManager.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/editors/ColorManager.java
index cef19a8..517e5cb 100644
--- a/editor/eclipse/eclisaac/src/org/lisaac/ldt/editors/ColorManager.java
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/editors/ColorManager.java
@@ -5,6 +5,7 @@ import java.util.Iterator;
 import java.util.Map;
 
 import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.StyledString.Styler;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.resource.StringConverter;
 import org.eclipse.jface.text.TextAttribute;
@@ -13,20 +14,38 @@ import org.eclipse.jface.text.rules.Token;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.TextStyle;
 import org.eclipse.swt.widgets.Display;
 
 public class ColorManager {
 
+	private static ColorManager instance;
+	
 	protected Map<RGB,Color> fColorTable = new HashMap<RGB,Color>(10);
 	private Map<String,IToken> tokenTable = new HashMap<String,IToken>(10);
 	private Map<String,String> styleTable = new HashMap<String,String>(10);
 
 	private final IPreferenceStore preferenceStore;
 
+	private Styler operatorStyler;
+	private Styler prototypeStyler;
+	private Styler slotStyler;
+	private Styler variableStyler;
+	
 	public ColorManager(IPreferenceStore preferenceStore) {
 		this.preferenceStore = preferenceStore;
+		instance = this;
+		
+		operatorStyler = new DefaultStyler(ILisaacColor.PREF_OPERATOR, ILisaacColor.STYLE_OPERATOR);
+		prototypeStyler = new DefaultStyler(ILisaacColor.PREF_PROTOTYPE, ILisaacColor.STYLE_PROTOTYPE);
+		slotStyler = new DefaultStyler(ILisaacColor.PREF_SLOT, ILisaacColor.STYLE_SLOT);
+		variableStyler = new DefaultStyler(ILisaacColor.PREF_LOCAL_SLOT, ILisaacColor.STYLE_LOCAL_SLOT);
 	}
 
+	public static ColorManager getDefault() {
+		return instance;
+	}
+	
 	public void dispose() {
 		Iterator<Color> e = fColorTable.values().iterator();
 		while (e.hasNext())
@@ -123,4 +142,34 @@ public class ColorManager {
 		}
 		return SWT.NORMAL; 
 	}
+	
+	public Styler getOperatorStyler() {
+		return operatorStyler;
+	}
+	
+	public Styler getPrototypeStyler() {
+		return prototypeStyler;
+	}
+	
+	public Styler getSlotStyler() {
+		return slotStyler;
+	}
+	
+	public Styler getVariableStyler() {
+		return variableStyler;
+	}
+	
+	private class DefaultStyler extends Styler {
+		String prefKey, styleKey;
+		
+		public DefaultStyler(String prefKey, String styleKey) {
+			this.prefKey = prefKey;
+			this.styleKey = styleKey;
+		}
+		public void applyStyles(TextStyle textStyle) {
+			IToken token = getToken(prefKey, styleKey);
+			TextAttribute attrib = (TextAttribute) token.getData();
+			textStyle.foreground = attrib.getForeground();
+		}
+	}
 }
diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/editors/LisaacCompletionProcessor.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/editors/LisaacCompletionProcessor.java
index 935351c..848452d 100644
--- a/editor/eclipse/eclisaac/src/org/lisaac/ldt/editors/LisaacCompletionProcessor.java
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/editors/LisaacCompletionProcessor.java
@@ -1,6 +1,9 @@
 package org.lisaac.ldt.editors;
 
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
 
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jface.text.BadLocationException;
@@ -13,6 +16,7 @@ import org.eclipse.jface.text.contentassist.IContextInformationValidator;
 import org.eclipse.jface.text.templates.TemplateProposal;
 import org.lisaac.ldt.LisaacPlugin;
 import org.lisaac.ldt.model.LisaacCompletionParser;
+import org.lisaac.ldt.model.LisaacParser;
 import org.lisaac.ldt.preferences.PreferenceConstants;
 import org.lisaac.ldt.templates.LisaacTemplateProcessor;
 
@@ -38,6 +42,13 @@ public class LisaacCompletionProcessor implements IContentAssistProcessor {
 
 			//
 			computeLisaacCompletion(document, offset, result);
+			if (result.size() > 1) {
+				Collections.sort(result, new Comparator<ICompletionProposal>() {
+					public int compare(ICompletionProposal o1, ICompletionProposal o2) {
+						return o1.getDisplayString().compareTo(o2.getDisplayString());
+					}
+				});
+			}
 			//
 
 			String prefix= extractPrefix(document, offset);
@@ -77,6 +88,9 @@ public class LisaacCompletionProcessor implements IContentAssistProcessor {
 				if (c == '-' && pos-1 > 0 && document.getChar(pos-1) == '<') {
 					break;
 				}
+				if (LisaacParser.isOperatorSymbol(c)) {
+					break;
+				}
 				if (c == '(' || c == '{' || c == '[') {
 					if (bracketLevel == 0) {
 						break;
diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/editors/LisaacCompletionProposal.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/editors/LisaacCompletionProposal.java
new file mode 100644
index 0000000..aa09f36
--- /dev/null
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/editors/LisaacCompletionProposal.java
@@ -0,0 +1,121 @@
+package org.lisaac.ldt.editors;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposalExtension6;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+
+
+public class LisaacCompletionProposal implements ICompletionProposal, ICompletionProposalExtension6 {
+
+
+	/** The string to be displayed in the completion proposal popup. */
+	private StyledString fStyledString;
+	
+	/** The replacement string. */
+	private String fReplacementString;
+	/** The replacement offset. */
+	private int fReplacementOffset;
+	/** The replacement length. */
+	private int fReplacementLength;
+	/** The cursor position after this proposal has been applied. */
+	private int fCursorPosition;
+	/** The image to be displayed in the completion proposal popup. */
+	private Image fImage;
+
+
+	/**
+	 * Creates a new completion proposal. All fields are initialized based on the provided information.
+	 *
+	 * @param replacementString the actual string to be inserted into the document
+	 * @param replacementOffset the offset of the text to be replaced
+	 * @param replacementLength the length of the text to be replaced
+	 * @param cursorPosition the position of the cursor following the insert relative to replacementOffset
+	 * @param image the image to display for this proposal
+	 * @param displayString the string to be displayed for the proposal
+	 */
+	public LisaacCompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, String displayString) {
+		this(replacementString, replacementOffset, replacementLength, cursorPosition, image, new StyledString(displayString));
+	}
+
+	/**
+	 * Creates a new completion proposal. All fields are initialized based on the provided information.
+	 *
+	 * @param replacementString the actual string to be inserted into the document
+	 * @param replacementOffset the offset of the text to be replaced
+	 * @param replacementLength the length of the text to be replaced
+	 * @param cursorPosition the position of the cursor following the insert relative to replacementOffset
+	 * @param image the image to display for this proposal
+	 * @param displayString the string to be displayed for the proposal
+	 */
+	public LisaacCompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, StyledString displayString) {
+		Assert.isNotNull(replacementString);
+		Assert.isTrue(replacementOffset >= 0);
+		Assert.isTrue(replacementLength >= 0);
+		Assert.isTrue(cursorPosition >= 0);
+ 
+		fReplacementString= replacementString;
+		fReplacementOffset= replacementOffset;
+		fReplacementLength= replacementLength;
+		fCursorPosition= cursorPosition;
+		fImage= image;
+		fStyledString = displayString;
+	} 
+	
+	/*
+	 * @see ICompletionProposal#apply(IDocument)
+	 */
+	public void apply(IDocument document) {
+		try {
+			document.replace(fReplacementOffset, fReplacementLength, fReplacementString);
+		} catch (BadLocationException x) {
+			// ignore
+		}
+	}
+
+	/*
+	 * @see ICompletionProposal#getSelection(IDocument)
+	 */
+	public Point getSelection(IDocument document) {
+		return new Point(fReplacementOffset + fCursorPosition, 0);
+	}
+
+	/*
+	 * @see ICompletionProposal#getContextInformation()
+	 */
+	public IContextInformation getContextInformation() {
+		return null;
+	}
+
+	/*
+	 * @see ICompletionProposal#getImage()
+	 */
+	public Image getImage() {
+		return fImage;
+	}
+
+	/*
+	 * @see ICompletionProposal#getDisplayString()
+	 */
+	public String getDisplayString() {
+		if (fStyledString != null)
+			return fStyledString.getString();
+		return fReplacementString;
+	}
+
+	/*
+	 * @see ICompletionProposal#getAdditionalProposalInfo()
+	 */
+	public String getAdditionalProposalInfo() {
+		return null;
+	}
+
+	public StyledString getStyledDisplayString() {
+		return fStyledString;
+	}
+}
diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/editors/LisaacConfiguration.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/editors/LisaacConfiguration.java
index 437a03e..1e802e6 100644
--- a/editor/eclipse/eclisaac/src/org/lisaac/ldt/editors/LisaacConfiguration.java
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/editors/LisaacConfiguration.java
@@ -71,6 +71,7 @@ public class LisaacConfiguration extends SourceViewerConfiguration {
 			//
 			contentAssistant.setRepeatedInvocationMode(true);
 			contentAssistant.setStatusLineVisible(true);
+			contentAssistant.enableColoredLabels(true);
 			contentAssistant.setStatusMessage(LisaacMessages.getString("LisaacConfiguration_0")); //$NON-NLS-1$
 			//
 			
diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/AbstractLisaacParser.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/AbstractLisaacParser.java
index 76d7d80..2be8297 100644
--- a/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/AbstractLisaacParser.java
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/AbstractLisaacParser.java
@@ -802,9 +802,9 @@ public class AbstractLisaacParser {
 		return result;
 	}
 
-	private final String operators = "!@#$%^&<|*-+=~/?\\>";
+	private static final String operators = "!@#$%^&<|*-+=~/?\\>";
 
-	public boolean isOperatorSymbol(char c) {
+	public static boolean isOperatorSymbol(char c) {
 		return operators.indexOf(c) != -1;
 	}
 	
diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/LisaacCompletionParser.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/LisaacCompletionParser.java
index 14cd386..77871c5 100644
--- a/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/LisaacCompletionParser.java
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/LisaacCompletionParser.java
@@ -79,7 +79,7 @@ public class LisaacCompletionParser extends LisaacParser {
 		ICode code = readExpr();
 		if (code != null && currentPrototype != null) {
 			type = code.getType(currentSlot, currentPrototype);
-			if (type != null) {
+			if (type != null && source.charAt(position-1) == '.') {
 				if (type instanceof TypeSelf) {
 					currentPrototype = findPrototype(((TypeSelf) type).getStaticType());
 
@@ -96,7 +96,6 @@ public class LisaacCompletionParser extends LisaacParser {
 				if (currentPrototype != null) {
 					// compute completion result
 					currentPrototype.getSlotProposals(proposals, baseOffset, 0);
-					proposals.add(new CompletionProposal(""+type,baseOffset,0,0));
 				} else {
 					// partial prototype name
 					String prefix = type.toString();
diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/IArgument.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/IArgument.java
index 1b05e87..cf8a283 100644
--- a/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/IArgument.java
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/IArgument.java
@@ -3,6 +3,7 @@ package org.lisaac.ldt.model.items;
 import java.util.ArrayList;
 
 import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.viewers.StyledString;
 import org.lisaac.ldt.model.types.IType;
 
 public interface IArgument extends IVariable {
@@ -14,7 +15,8 @@ public interface IArgument extends IVariable {
 	boolean hasName(String word);
 	
 	void printIn(StringBuffer buffer);
-
+	void styledPrintIn(StyledString buffer);
+	
 	void getMatchProposals(String n, ArrayList<ICompletionProposal> matchList,
 			int offset, int length);
 }
diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/ITMArgs.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/ITMArgs.java
index 8097273..d03bada 100644
--- a/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/ITMArgs.java
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/ITMArgs.java
@@ -4,7 +4,9 @@ import java.util.ArrayList;
 
 import org.eclipse.jface.text.contentassist.CompletionProposal;
 import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.viewers.StyledString;
 import org.eclipse.swt.graphics.Image;
+import org.lisaac.ldt.editors.ColorManager;
 import org.lisaac.ldt.model.Position;
 import org.lisaac.ldt.model.types.IType;
 import org.lisaac.ldt.model.types.TypeMulti;
@@ -76,6 +78,22 @@ public class ITMArgs implements IArgument {
 		buffer.append(")");
 	}
 
+	public void styledPrintIn(StyledString buffer) {
+		ColorManager colors = ColorManager.getDefault();
+		buffer.append("(");
+		for (int i=0; i<name.length; i++) {
+			IType subType = type.getSubType(i);
+			buffer.append(name[i], colors.getVariableStyler());
+			buffer.append(" : ");
+			buffer.append(subType.toString(), colors.getPrototypeStyler());
+			
+			if (i != name.length-1) {
+				buffer.append(", ");
+			}
+		}
+		buffer.append(")");
+	}
+	
 	public String getHoverInformation() {
 		StringBuffer buffer = new StringBuffer();
 		buffer.append("<I>Arguments</I> : ");
diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/ITMArgument.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/ITMArgument.java
index fa2a0ea..4731811 100644
--- a/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/ITMArgument.java
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/ITMArgument.java
@@ -4,7 +4,9 @@ import java.util.ArrayList;
 
 import org.eclipse.jface.text.contentassist.CompletionProposal;
 import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.viewers.StyledString;
 import org.eclipse.swt.graphics.Image;
+import org.lisaac.ldt.editors.ColorManager;
 import org.lisaac.ldt.model.Position;
 import org.lisaac.ldt.model.types.IType;
 import org.lisaac.ldt.model.types.ITypeMono;
@@ -41,6 +43,13 @@ public class ITMArgument implements IArgument {
 		buffer.append(type);
 	}
 	
+	public void styledPrintIn(StyledString buffer) {
+		ColorManager colors = ColorManager.getDefault();
+		buffer.append(name, colors.getVariableStyler());
+		buffer.append(':');
+		buffer.append(type.toString(), colors.getPrototypeStyler());
+	}
+	
 	public String getHoverInformation() {
 		StringBuffer buffer = new StringBuffer();
 		buffer.append("<I>Argument</I> : <b>");
diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/Prototype.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/Prototype.java
index 1773ad4..adac394 100644
--- a/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/Prototype.java
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/Prototype.java
@@ -378,7 +378,7 @@ public class Prototype {
 						break;
 					}
 				}
-				if (parser.isOperatorSymbol(c)) {
+				if (LisaacParser.isOperatorSymbol(c)) {
 					if (c == '+' || c == '-') {
 						// slot definition
 						if (offset - 3 > 0 && source.charAt(offset - 1) == ' ' &&
@@ -473,7 +473,7 @@ public class Prototype {
 								break;
 							}
 						}
-						if (parser.isOperatorSymbol(c)) {
+						if (LisaacParser.isOperatorSymbol(c)) {
 							break;
 						}
 						// strings 
diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/Slot.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/Slot.java
index de2ad20..2fc0c29 100644
--- a/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/Slot.java
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/model/items/Slot.java
@@ -1,12 +1,14 @@
 	package org.lisaac.ldt.model.items;
 
 	import java.util.ArrayList;
-	import org.eclipse.jface.text.contentassist.CompletionProposal;
 	import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.viewers.StyledString;
 	import org.eclipse.swt.graphics.Image;
 import org.eclipse.text.edits.DeleteEdit;
 import org.eclipse.text.edits.InsertEdit;
 import org.eclipse.text.edits.TextEdit;
+import org.lisaac.ldt.editors.ColorManager;
+import org.lisaac.ldt.editors.LisaacCompletionProposal;
 	import org.lisaac.ldt.model.ILisaacModel;
 import org.lisaac.ldt.model.LisaacParser;
 	import org.lisaac.ldt.model.Position;
@@ -277,11 +279,9 @@ import org.lisaac.ldt.outline.OutlineSlot;
 		}
 
 		public String getSignature(boolean isCall) {
-
 			if (name.startsWith("__")) {
 				return getOperatorName();
 			}
-
 			if (keywordList == null || keywordList.length < 1) {
 				return name;
 			}
@@ -307,9 +307,51 @@ import org.lisaac.ldt.outline.OutlineSlot;
 			if (!isCall && resultType.toString() != null) {
 				buffer.append(" : " + resultType);
 			}
+			
 			return buffer.toString();
 		}
+		
+		public StyledString getStyledSignature(boolean isCall, boolean showProto) {
+			ColorManager colors = ColorManager.getDefault();
+			StyledString result = new StyledString();
+			
+			if (name.startsWith("__")) {
+				result.append(getOperatorName(), colors.getOperatorStyler());
+				return result;
+			}
+			if (keywordList == null || keywordList.length < 1) {
+				result.append(name, colors.getSlotStyler());
+				return result;
+			}
+			result.append(keywordList[0], colors.getSlotStyler());
+			result.append(" ");
 
+			int keywordIndex = 1;
+			for (int argIndex = 0; argIndex < argumentList.length; argIndex++) {
+				if (isCall) { 
+					result.append(argumentList[argIndex].getName(), colors.getVariableStyler());
+				} else {
+					argumentList[argIndex].styledPrintIn(result);
+				}
+				result.append(" ");
+
+				if (keywordIndex < keywordList.length) {
+					result.append(keywordList[keywordIndex], colors.getSlotStyler());
+					result.append(" ");
+					keywordIndex++;
+				}
+			}
+			if (!isCall && resultType.toString() != null) {
+				result.append(" : ");
+				result.append(resultType.toString(), colors.getPrototypeStyler());
+			}
+			if (showProto) {
+				result.append("  - ", StyledString.QUALIFIER_STYLER);
+				result.append(getPrototype().getName(), StyledString.QUALIFIER_STYLER);
+			}
+			return result;
+		}
+		
 		public void getSlotProposals(ArrayList<ICompletionProposal> proposals,
 				int offset, int length) {
 
@@ -317,11 +359,10 @@ import org.lisaac.ldt.outline.OutlineSlot;
 			String displayString = getSignature(true);
 			
 			if (checkUnicity(proposals,displayString)) {
-				proposals.add(new CompletionProposal(displayString, offset, length,
-					displayString.length() - 1, image, getSignature(false),
-					null, null));
+				proposals.add(new LisaacCompletionProposal(displayString, offset, length,
+					displayString.length() - 1, image, getStyledSignature(false, true)));
 			}
-		}
+		} 
 
 		public void getSlotMatchProposals(
 				ArrayList<ICompletionProposal> proposals, int offset,
@@ -332,9 +373,8 @@ import org.lisaac.ldt.outline.OutlineSlot;
 
 			if (checkUnicity(proposals,displayString)) {
 				displayString = displayString.substring(matchLength);
-				proposals.add(new CompletionProposal(displayString, offset, length,
-					displayString.length(), image, getSignature(false), null,
-					null));
+				proposals.add(new LisaacCompletionProposal(displayString, offset, length,
+					displayString.length(), image, getStyledSignature(false, true)));
 			}
 		}
 		
@@ -376,6 +416,7 @@ import org.lisaac.ldt.outline.OutlineSlot;
 			}
 		}
 
+		// FIXME cannot compare display string now... they're already unique, ex: "slot - SON" and "slot - FATHER"
 		public static boolean checkUnicity(ArrayList<ICompletionProposal> proposals, String str) {
 			for (int i=0; i<proposals.size(); i++) {
 				if (proposals.get(i).getDisplayString().compareTo(str) == 0) {
diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlineItem.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlineItem.java
index bb520c2..7b4d9f2 100644
--- a/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlineItem.java
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlineItem.java
@@ -1,6 +1,8 @@
 package org.lisaac.ldt.outline;
 
 import java.util.List;
+
+import org.eclipse.jface.viewers.StyledString;
 import org.eclipse.swt.graphics.Image;
 
 public abstract class OutlineItem implements Comparable<Object> {
@@ -23,6 +25,8 @@ public abstract class OutlineItem implements Comparable<Object> {
      */
     public abstract String getText();
 	
+    public abstract StyledString getStyledText();
+    
 	/**
      * Returns the children of this element.
      */
@@ -35,5 +39,5 @@ public abstract class OutlineItem implements Comparable<Object> {
 
 	public int length() {
 		return fLength;
-	}
+	}	
 }
diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlineLabelProvider.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlineLabelProvider.java
index 51c96eb..b217a2e 100644
--- a/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlineLabelProvider.java
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlineLabelProvider.java
@@ -1,41 +1,66 @@
 package org.lisaac.ldt.outline;
 
 import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.ViewerCell;
 import org.eclipse.swt.graphics.Image;
 
-public class OutlineLabelProvider extends LabelProvider  {
-	
+public class OutlineLabelProvider extends StyledCellLabelProvider  {
+
+	/**
+	 * @see WorkbenchLabelProvider#getImage(Object)
+	 * @param element the element for which an image is created
+	 * @return the image associated to the element
+	 */
+	public Image getImage(Object element) {
+		if (element instanceof OutlineItem) {
+			OutlineItem item = (OutlineItem) element;
+			Image image = item.getImage();
+
+			if (image != null) {
+				return image;
+			}
+		}
+		return OutlineImages.BLANK;
+	}
+
 	/**
-     * @see WorkbenchLabelProvider#getImage(Object)
-     * @param element the element for which an image is created
-     * @return the image associated to the element
-     */
-    public Image getImage(Object element) {
-        if (element instanceof OutlineItem) {
-            OutlineItem item = (OutlineItem) element;
-            Image image = item.getImage();
-            
-            if (image != null) {
-                return image;
-            }
-        }
-        return OutlineImages.BLANK;
-    }
-
-    /**
-     * @see WorkbenchLabelProvider#getText(Object)
-     * @param element the element for which a label is created
-     * @return the label associated to the element
-     */
-    public String getText(Object element) {
-        if (element instanceof OutlineItem) {
-            OutlineItem item = (OutlineItem) element;
-            return item.getText();
-        }
-        if (element != null) {
-            return element.toString();
-        } else {
-            return new String();
-        }
-    }
+	 * @see WorkbenchLabelProvider#getText(Object)
+	 * @param element the element for which a label is created
+	 * @return the label associated to the element
+	 */
+	public String getText(Object element) {
+		if (element instanceof OutlineItem) {
+			OutlineItem item = (OutlineItem) element;
+			return item.getText();
+		}
+		if (element != null) {
+			return element.toString();
+		} else {
+			return new String();
+		}
+	}
+
+	public StyledString getStyledText(Object element) {
+		if (element instanceof OutlineItem) {
+			OutlineItem item = (OutlineItem) element;
+			return item.getStyledText();
+		}
+		if (element != null) {
+			return new StyledString(element.toString());
+		} else {
+			return new StyledString();
+		}
+	}
+
+	public void update(ViewerCell cell) {
+		Object obj = cell.getElement();
+		StyledString styledString = getStyledText(obj);
+
+		cell.setText(styledString.toString());
+		cell.setStyleRanges(styledString.getStyleRanges());
+		cell.setImage(getImage(obj));
+		super.update(cell);
+	}
 }
diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlinePrototype.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlinePrototype.java
index d55daff..d2e8bd0 100644
--- a/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlinePrototype.java
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlinePrototype.java
@@ -3,7 +3,9 @@ package org.lisaac.ldt.outline;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.eclipse.jface.viewers.StyledString;
 import org.eclipse.swt.graphics.Image;
+import org.lisaac.ldt.editors.ColorManager;
 import org.lisaac.ldt.model.items.Prototype;
 
 public class OutlinePrototype extends OutlineItem {
@@ -25,6 +27,11 @@ public class OutlinePrototype extends OutlineItem {
     	return name;
     }
     
+    public StyledString getStyledText() {
+		ColorManager colors = ColorManager.getDefault();
+		return new StyledString(name, colors.getPrototypeStyler());
+	}
+    
     public String toString() {
     	return name;
     }
diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlineSection.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlineSection.java
index d45a4e1..84ea3a6 100644
--- a/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlineSection.java
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlineSection.java
@@ -2,7 +2,9 @@ package org.lisaac.ldt.outline;
 
 import java.util.List;
 
+import org.eclipse.jface.viewers.StyledString;
 import org.eclipse.swt.graphics.Image;
+import org.lisaac.ldt.editors.ColorManager;
 import org.lisaac.ldt.model.Position;
 import org.lisaac.ldt.model.items.Section;
 import org.lisaac.ldt.model.types.ITypeMono;
@@ -12,13 +14,13 @@ public class OutlineSection extends OutlineItem {
 	protected Section section;
 
 	protected List<OutlineItem> slots;
-	
+
 	public OutlineSection(Section section) {
 		this.section = section;
 		this.slots = section.getOutlineItems();
-		
+
 		Position position = section.getPosition();
-		
+
 		fstartOffset = position.getStartOffset() - 7;
 		fLength = 7;
 		//fstartOffset = position.getStartOffset();
@@ -47,6 +49,26 @@ public class OutlineSection extends OutlineItem {
 		return result;
 	}
 
+	public StyledString getStyledText() {
+		StyledString result = new StyledString();
+		ColorManager colors = ColorManager.getDefault();
+		
+		if (section != null) {
+			if (section.getName() != null) {
+				result.append(section.getName());
+			} else {
+				ITypeMono[] types = section.getTypeList();
+				for (int i=0; i<types.length; i++) {
+					result.append(types[i].toString(), colors.getPrototypeStyler());
+					if (i != types.length-1) {
+						result.append(", ");
+					}
+				}
+			}
+		}
+		return result;
+	}
+
 	public String toString() {
 		return getText();
 	}
diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlineSlot.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlineSlot.java
index 62de449..69eb440 100644
--- a/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlineSlot.java
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/outline/OutlineSlot.java
@@ -2,10 +2,10 @@ package org.lisaac.ldt.outline;
 
 import java.util.List;
 
+import org.eclipse.jface.viewers.StyledString;
 import org.eclipse.swt.graphics.Image;
 import org.lisaac.ldt.model.Position;
 import org.lisaac.ldt.model.items.Slot;
-import org.lisaac.ldt.model.types.IType;
 
 public class OutlineSlot extends OutlineItem {
 
@@ -31,6 +31,13 @@ public class OutlineSlot extends OutlineItem {
 		}
 		return result;
 	}
+	
+	public StyledString getStyledText() {
+		if (slot != null) {
+			return slot.getStyledSignature(false, false);
+		}
+		return null;
+	}
 
 	public String toString() {
 		return getText();
diff --git a/editor/eclipse/eclisaac/src/org/lisaac/ldt/views/LisaacOutlineView.java b/editor/eclipse/eclisaac/src/org/lisaac/ldt/views/LisaacOutlineView.java
index 8169ca8..4b84f2d 100644
--- a/editor/eclipse/eclisaac/src/org/lisaac/ldt/views/LisaacOutlineView.java
+++ b/editor/eclipse/eclisaac/src/org/lisaac/ldt/views/LisaacOutlineView.java
@@ -124,15 +124,6 @@ public class LisaacOutlineView extends ContentOutlinePage implements IDocumentLi
 		IToolBarManager toolbarManager = actionBars.getToolBarManager();
 		toolbarManager.add(sortByName);
 		toolbarManager.add(sortBySection);
-		
-		/* IMenuManager menuManager = actionBars.getMenuManager();
-        menuManager.add(new OutlineHideCommentsAction(this, imageCache));
-        menuManager.add(new OutlineHideImportsAction(this, imageCache));
-        menuManager.add(new OutlineHideMagicObjectsAction(this, imageCache));
-        menuManager.add(new OutlineHideFieldsAction(this, imageCache));
-        menuManager.add(new OutlineHideNonPublicMembersAction(this, imageCache));
-        menuManager.add(new OutlineHideStaticMethodsAction(this, imageCache));
-		 */
 	}
 
 	/**

-- 
Lisaac compiler



More information about the Lisaac-commits mailing list