[SCM] Lisaac eclipse plugin branch, master, updated. 8459b9d7d5632cbb57d46d46886df728db9b4c79
Damien Bouvarel
dams.bouvarel at wanadoo.fr
Sat Apr 18 11:22:31 UTC 2009
The following commit has been merged in the master branch:
commit 8459b9d7d5632cbb57d46d46886df728db9b4c79
Author: Damien Bouvarel <dams.bouvarel at wanadoo.fr>
Date: Sat Apr 18 12:38:08 2009 +0200
add slot comment in hover text + editor preferences
diff --git a/plugin.xml b/plugin.xml
index 29d8e17..60137f6 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -60,16 +60,25 @@
id="org.eclipse.lisaac.preferences.LisaacPreferencePage">
</page>
<page
- category="org.eclipse.lisaac.preferences.LisaacPreferencePage"
+ category="org.eclipse.lisaac.editorpreferences"
class="org.eclipse.lisaac.preferences.LisaacTemplatePage"
id="org.eclipse.lisaac.templatepreferences"
name="Templates">
</page>
<page
+ category="org.eclipse.lisaac.editorpreferences"
+ class="org.eclipse.lisaac.preferences.LisaacColoringPage"
+ id="org.eclipse.lisaac.editorcolorpreferences"
+ name="Syntax Coloring">
+ </page>
+ <page
category="org.eclipse.lisaac.preferences.LisaacPreferencePage"
class="org.eclipse.lisaac.preferences.LisaacEditorPage"
id="org.eclipse.lisaac.editorpreferences"
- name="Syntax Coloring">
+ name="Editor">
+ <keywordReference
+ id="org.eclipse.ui.editors.general">
+ </keywordReference>
</page>
</extension>
<extension
diff --git a/src/org/eclipse/lisaac/editors/AbstractLisaacEditor.java b/src/org/eclipse/lisaac/editors/AbstractLisaacEditor.java
index 5773014..fb03946 100644
--- a/src/org/eclipse/lisaac/editors/AbstractLisaacEditor.java
+++ b/src/org/eclipse/lisaac/editors/AbstractLisaacEditor.java
@@ -13,9 +13,12 @@ import org.eclipse.jface.action.Action;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewerExtension2;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.lisaac.LisaacPlugin;
import org.eclipse.lisaac.model.LisaacModel;
+import org.eclipse.lisaac.preferences.PreferenceConstants;
import org.eclipse.lisaac.views.LisaacOutlineView;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.editors.text.TextEditor;
@@ -106,6 +109,19 @@ public class AbstractLisaacEditor extends TextEditor {
protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
colorManager.handlePreferenceStoreChanged(event);
super.handlePreferenceStoreChanged(event);
+
+ String prop = event.getProperty();
+ if (prop.equals(PreferenceConstants.P_LISAAC_COMPLETION_DELAY)) {
+ IContentAssistant assistant = getSourceViewerConfiguration().getContentAssistant(getSourceViewer());
+
+ Integer delay;
+ try {
+ delay = Integer.valueOf(((String)event.getNewValue()));
+ } catch (Exception e) {
+ delay = 500;
+ }
+ ((ContentAssistant) assistant).setAutoActivationDelay(delay);
+ }
}
protected boolean affectsTextPresentation(PropertyChangeEvent event) {
diff --git a/src/org/eclipse/lisaac/editors/HoverPresenter.java b/src/org/eclipse/lisaac/editors/HoverPresenter.java
index 3b5c970..6bb33c9 100644
--- a/src/org/eclipse/lisaac/editors/HoverPresenter.java
+++ b/src/org/eclipse/lisaac/editors/HoverPresenter.java
@@ -1,5 +1,7 @@
package org.eclipse.lisaac.editors;
+import java.util.Stack;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.graphics.Color;
@@ -39,6 +41,7 @@ public class HoverPresenter implements DefaultInformationControl.IInformationPre
StringBuffer buffer= new StringBuffer();
int style = NONE;
+ Stack<Integer> styles = new Stack<Integer>();
int startOffset = 0;
int len = hoverInfo.length();
@@ -54,19 +57,30 @@ public class HoverPresenter implements DefaultInformationControl.IInformationPre
c = Character.toLowerCase(hoverInfo.charAt(i+2));
if (hoverInfo.charAt(i+3) == '>') {
+ style = styles.pop();
+ startOffset = styles.pop();
+ int styleDerive = styles.pop();
+
+ int lengthDerive = derive - styleDerive;
+
+ if (lengthDerive > 0) {
+ // FIXME ranges cannot overlap...
+ style = NONE;
+ }
+
switch(style) {
case BOLD:
presentation.addStyleRange(new StyleRange(
- startOffset - derive, i - startOffset, null, null, SWT.BOLD));
+ startOffset - styleDerive, i - startOffset - lengthDerive, null, null, SWT.BOLD));
break;
case ITALIC:
presentation.addStyleRange(new StyleRange(
- startOffset - derive, i - startOffset, null, null, SWT.ITALIC));
+ startOffset - styleDerive, i - startOffset - lengthDerive, null, null, SWT.ITALIC));
break;
case GRAY:
Color gray = colorManager.getColor(ILisaacColor.GRAY);
presentation.addStyleRange(new StyleRange(
- startOffset - derive, i - startOffset, gray, null, SWT.NONE));
+ startOffset - styleDerive, i - startOffset - lengthDerive, gray, null, SWT.NONE));
break;
}
i += 3;
@@ -91,15 +105,21 @@ public class HoverPresenter implements DefaultInformationControl.IInformationPre
if (c != '>') {
buffer.append(c);
style = NONE;
+ } else {
+ i += 2;
+ derive += 3;
+
+ styles.push(derive);
+ styles.push(startOffset);
+ styles.push(style);
}
- i += 2;
- derive += 3;
}
} else {
buffer.append(c);
}
i++;
}
+
return buffer.toString();
}
diff --git a/src/org/eclipse/lisaac/editors/LisaacAutoEditStrategy.java b/src/org/eclipse/lisaac/editors/LisaacAutoEditStrategy.java
index e444a56..8944998 100644
--- a/src/org/eclipse/lisaac/editors/LisaacAutoEditStrategy.java
+++ b/src/org/eclipse/lisaac/editors/LisaacAutoEditStrategy.java
@@ -1,359 +1,366 @@
-package org.eclipse.lisaac.editors;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
-import org.eclipse.jface.text.DocumentCommand;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TextUtilities;
-
-
-public class LisaacAutoEditStrategy extends DefaultIndentLineAutoEditStrategy {
-
- /**
- * @see DefaultIndentLineAutoEditStrategy#customizeDocumentCommand(IDocument, DocumentCommand)
- */
- public void customizeDocumentCommand(IDocument d, DocumentCommand c) {
- editDocumentCommand(d, c);
- }
-
- /**
- * Customizes the given document command to edit the given document.
- * @param document the document
- * @param command the command
- * @see DefaultIndentLineAutoEditStrategy#customizeDocumentCommand(IDocument, DocumentCommand)
- */
- protected void editDocumentCommand(IDocument document, DocumentCommand command) {
- String textCommand = command.text;
-
- if (textCommand != null) {
- String[] lineDelimiters = document.getLegalLineDelimiters();
- int endOfLineIndex = TextUtilities.endsWith(lineDelimiters, textCommand);
-
- if (endOfLineIndex > -1) {
- // this is an end of line
- indentOnNewLine(document, command);
- } else if (textCommand.equals("\t")) {
- // this is a tab
- indentOnTab(document, command);
- } else {
- // this is another character or string
- indentOnSpecificChar(document, command);
- }
- }
- }
-
- /**
- * Indent One line.
- * @param indentLine line to be indented
- * @param document
- * @param command
- * @return last indentation for the next line
- */
- private static void doIndentLine(int indentLine, IDocument document, DocumentCommand command) {
- try {
- //
- // find last line indent
- //
-
- int lastIndent = getIndentWithPreviousLine(indentLine, document);
-
- //
- // current line indent
- //
- IRegion currentLineInfo = document.getLineInformation(indentLine);
-
- int lineStart = currentLineInfo.getOffset();
- int lineEnd = currentLineInfo.getOffset() + currentLineInfo.getLength();
-
- IRegion originalBlankRegion = getBlankAfterOffset(document, lineStart);
- int currentIndent = originalBlankRegion.getLength();
-
- // special case
- if (lineEnd - originalBlankRegion.getOffset()+currentIndent > 8) {
- String instr = document.get(originalBlankRegion.getOffset()+currentIndent,8);
- if (instr.startsWith("Section ")) {
- lastIndent = 2;
-
- // insertion in current line
- if (command != null) {
- command.text = "";
- command.offset = lineStart;
- command.length = currentIndent;
- } else {
- document.replace(lineStart, currentIndent, "");
- }
- return;
- }
- }
- int i = lineEnd-1;
- int indent2 = 0;
- while (i >= lineStart) {
- char c = document.getChar(i);
- switch (c) {
- case '{':
- case '(':
- case '[':
- if (indent2 != 0) {
- indent2 -= 2;
- }
- break;
- case '}':
- case ')':
- case ']':
- indent2 += 2;
- break;
- case '\"':// string " "
- do {
- i--;
- if (i >= lineStart) {
- c = document.getChar(i);
- }
- } while (i >= lineStart && c != '\"');
- break;
- case '\'':// string ' '
- do {
- i--;
- if (i >= lineStart) {
- c = document.getChar(i);
- }
- } while (i >= lineStart && c != '\'');
- break;
- }
- i--;
- }
- //
- // insertion in current line
- //
- lastIndent -= indent2;
-
- if (command != null) {
- command.text = createString(lastIndent);
- command.offset = lineStart;
- command.length = currentIndent;
- } else {
- document.replace(lineStart, currentIndent, createString(lastIndent));
- }
-
- } catch (BadLocationException excp) {
- // stop work
- }
- }
-
- /**
- * Get line indentation using previous line.
- */
- private static int getIndentWithPreviousLine(int line, IDocument document) {
- int result = 0;
- try {
- //
- // find last line indent
- //
- while (line > 0) {
- line--;
- IRegion lineRegion = document.getLineInformation(line);
-
- int lineStart = lineRegion.getOffset();
- int lineEnd = lineRegion.getOffset() + lineRegion.getLength();
-
- IRegion originalBlankRegion = getBlankAfterOffset(document, document.getLineOffset(line));
- result = originalBlankRegion.getLength();
-
- // special case
- if (lineEnd - originalBlankRegion.getOffset()+result > 8) {
- String instr = document.get(originalBlankRegion.getOffset()+result,8);
- if (instr.startsWith("Section ")) {
- result = 2;
- break;
- }
- }
- int i = lineStart;
- int deltaIndent = 0;
- while (i < lineEnd) {
- char c = document.getChar(i);
- switch (c) {
- case '{':
- case '(':
- case '[':
- deltaIndent += 2;
- break;
- case '}':
- case ')':
- case ']':
- if (deltaIndent != 0) {
- deltaIndent -= 2;
- }
- break;
- case '\"':// string " "
- do {
- i++;
- if (i < lineEnd) {
- c = document.getChar(i);
- }
- } while (i < lineEnd && c != '\"');
- break;
- case '\'':// string ' '
- do {
- i++;
- if (i < lineEnd) {
- c = document.getChar(i);
- }
- } while (i < lineEnd && c != '\'');
- break;
- }
- i++;
- }
- result += deltaIndent;
-
- if (getBlankEnd(document,lineStart) != lineEnd) {
- // not empty line
- break;
- }
- }
- } catch (BadLocationException excp) {
- // stop work
- }
- return result;
- }
-
- /**
- * Get the blank region of given line after offset
- */
- private static int getBlankEnd(IDocument document, int offset) throws BadLocationException {
- IRegion lineRegion = document.getLineInformationOfOffset(offset);
- int blankEnd = offset;
- int maxBlankEnd = lineRegion.getOffset() + lineRegion.getLength();
-
- while (blankEnd < maxBlankEnd) {
- char c = document.getChar(blankEnd);
- if (c != ' ' && c != '\t') {
- break;
- }
- blankEnd++;
- }
- return blankEnd;
- }
-
- /**
- * Customizes the given command to edit the given document when a newline is pressed.
- * @param document the document
- * @param command the command
- */
- protected void indentOnNewLine(IDocument document, DocumentCommand command) {
- try {
- int p = (command.offset == document.getLength() ? command.offset - 1 : command.offset);
- int line = document.getLineOfOffset(p);
-
- // indent previous line
- doIndentLine(line, document, command);
-
- // get indent for new line
- int indent = getIndentWithPreviousLine(line+1, document);
-
- //
- // indent new line
- //
- IRegion info = document.getLineInformation(line);
- command.addCommand(info.getOffset() + info.getLength(), 0, "\n"+createString(indent), null);
- command.shiftsCaret = true;
- command.caretOffset = info.getOffset() + info.getLength();
-
- } catch (BadLocationException excp) {
- // stop work
- }
- }
-
- /**
- * Get the blank region of given line after offset
- */
- private static IRegion getBlankAfterOffset(IDocument document, int offset) throws BadLocationException {
- IRegion lineRegion = document.getLineInformationOfOffset(offset);
- int blankEnd = offset;
- int maxBlankEnd = lineRegion.getOffset() + lineRegion.getLength();
-
- while (blankEnd < maxBlankEnd) {
- char c = document.getChar(blankEnd);
- if (c != ' ' && c != '\t') {
- break;
- }
- blankEnd++;
- }
- return new Region(offset, blankEnd - offset);
- }
-
- /**
- * Returns a blank string of the given length.
- * @param length the length of the string to create
- * @return a blank string of the given length
- */
- public static String createString(int length) {
- StringBuffer buffer = new StringBuffer(length);
-
- for (int index = 0 ; index < length ; index++) {
- buffer.append(' ');
- }
- return buffer.toString();
- }
-
- /**
- * Customizes the given command to edit the given document when a tabulation is pressed.
- * @param document the document
- * @param command the command
- */
- protected void indentOnTab(IDocument document, DocumentCommand command) {
-
- //fullIndentDocument(document);
-
- try {
- int p = (command.offset == document.getLength() ? command.offset - 1 : command.offset);
- int line = document.getLineOfOffset(p);
-
- doIndentLine(line, document, command);
-
- } catch (BadLocationException excp) {
- // stop work
- }
- }
-
- /**
- * Customizes the given command to edit the given document when a specific character is pressed.
- * @param document the document
- * @param command the command
- */
- protected void indentOnSpecificChar(IDocument document, DocumentCommand command) {
- // TODO code templates!!!
- }
-
- /**
- * Indent correctly the whole document
- * @param document the document
- */
- public static void fullIndentDocument(IDocument document) {
- int line = 0;
- int maxLine = document.getNumberOfLines();
-
- while (line < maxLine) {
- doIndentLine(line, document, null);
- line++;
- }
- }
-
- /**
- * Indent correctly part of a document
- * @param document the document
- */
- public static void fullIndentDocument(IDocument document, int offset, int length) {
- try {
- int line = document.getLineOfOffset(offset);
- int maxLine = document.getNumberOfLines(offset, length);
-
- while (line < maxLine) { // TODO indent part of document
- // indentLine(line, document);
- line++;
- }
- } catch (BadLocationException excp) {
- // stop work
- }
- }
-}
+package org.eclipse.lisaac.editors;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.TextUtilities;
+import org.eclipse.lisaac.LisaacPlugin;
+import org.eclipse.lisaac.preferences.PreferenceConstants;
+
+
+public class LisaacAutoEditStrategy extends DefaultIndentLineAutoEditStrategy {
+
+ /**
+ * @see DefaultIndentLineAutoEditStrategy#customizeDocumentCommand(IDocument, DocumentCommand)
+ */
+ public void customizeDocumentCommand(IDocument d, DocumentCommand c) {
+ editDocumentCommand(d, c);
+ }
+
+ /**
+ * Customizes the given document command to edit the given document.
+ * @param document the document
+ * @param command the command
+ * @see DefaultIndentLineAutoEditStrategy#customizeDocumentCommand(IDocument, DocumentCommand)
+ */
+ protected void editDocumentCommand(IDocument document, DocumentCommand command) {
+ String textCommand = command.text;
+
+ if (textCommand != null) {
+
+ boolean enableIndent = LisaacPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.P_LISAAC_INDENT);
+ if (! enableIndent) {
+ return;
+ }
+ String[] lineDelimiters = document.getLegalLineDelimiters();
+ int endOfLineIndex = TextUtilities.endsWith(lineDelimiters, textCommand);
+
+ if (endOfLineIndex > -1) {
+ // this is an end of line
+ indentOnNewLine(document, command);
+ } else if (textCommand.equals("\t")) {
+ // this is a tab
+ indentOnTab(document, command);
+ } else {
+ // this is another character or string
+ indentOnSpecificChar(document, command);
+ }
+ }
+ }
+
+ /**
+ * Indent One line.
+ * @param indentLine line to be indented
+ * @param document
+ * @param command
+ * @return last indentation for the next line
+ */
+ private static void doIndentLine(int indentLine, IDocument document, DocumentCommand command) {
+ try {
+ //
+ // find last line indent
+ //
+
+ int lastIndent = getIndentWithPreviousLine(indentLine, document);
+
+ //
+ // current line indent
+ //
+ IRegion currentLineInfo = document.getLineInformation(indentLine);
+
+ int lineStart = currentLineInfo.getOffset();
+ int lineEnd = currentLineInfo.getOffset() + currentLineInfo.getLength();
+
+ IRegion originalBlankRegion = getBlankAfterOffset(document, lineStart);
+ int currentIndent = originalBlankRegion.getLength();
+
+ // special case
+ if (lineEnd - originalBlankRegion.getOffset()+currentIndent > 8) {
+ String instr = document.get(originalBlankRegion.getOffset()+currentIndent,8);
+ if (instr.startsWith("Section ")) {
+ lastIndent = 2;
+
+ // insertion in current line
+ if (command != null) {
+ command.text = "";
+ command.offset = lineStart;
+ command.length = currentIndent;
+ } else {
+ document.replace(lineStart, currentIndent, "");
+ }
+ return;
+ }
+ }
+ int i = lineEnd-1;
+ int indent2 = 0;
+ while (i >= lineStart) {
+ char c = document.getChar(i);
+ switch (c) {
+ case '{':
+ case '(':
+ case '[':
+ if (indent2 != 0) {
+ indent2 -= 2;
+ }
+ break;
+ case '}':
+ case ')':
+ case ']':
+ indent2 += 2;
+ break;
+ case '\"':// string " "
+ do {
+ i--;
+ if (i >= lineStart) {
+ c = document.getChar(i);
+ }
+ } while (i >= lineStart && c != '\"');
+ break;
+ case '\'':// string ' '
+ do {
+ i--;
+ if (i >= lineStart) {
+ c = document.getChar(i);
+ }
+ } while (i >= lineStart && c != '\'');
+ break;
+ }
+ i--;
+ }
+ //
+ // insertion in current line
+ //
+ lastIndent -= indent2;
+
+ if (command != null) {
+ command.text = createString(lastIndent);
+ command.offset = lineStart;
+ command.length = currentIndent;
+ } else {
+ document.replace(lineStart, currentIndent, createString(lastIndent));
+ }
+
+ } catch (BadLocationException excp) {
+ // stop work
+ }
+ }
+
+ /**
+ * Get line indentation using previous line.
+ */
+ private static int getIndentWithPreviousLine(int line, IDocument document) {
+ int result = 0;
+ try {
+ //
+ // find last line indent
+ //
+ while (line > 0) {
+ line--;
+ IRegion lineRegion = document.getLineInformation(line);
+
+ int lineStart = lineRegion.getOffset();
+ int lineEnd = lineRegion.getOffset() + lineRegion.getLength();
+
+ IRegion originalBlankRegion = getBlankAfterOffset(document, document.getLineOffset(line));
+ result = originalBlankRegion.getLength();
+
+ // special case
+ if (lineEnd - originalBlankRegion.getOffset()+result > 8) {
+ String instr = document.get(originalBlankRegion.getOffset()+result,8);
+ if (instr.startsWith("Section ")) {
+ result = 2;
+ break;
+ }
+ }
+ int i = lineStart;
+ int deltaIndent = 0;
+ while (i < lineEnd) {
+ char c = document.getChar(i);
+ switch (c) {
+ case '{':
+ case '(':
+ case '[':
+ deltaIndent += 2;
+ break;
+ case '}':
+ case ')':
+ case ']':
+ if (deltaIndent != 0) {
+ deltaIndent -= 2;
+ }
+ break;
+ case '\"':// string " "
+ do {
+ i++;
+ if (i < lineEnd) {
+ c = document.getChar(i);
+ }
+ } while (i < lineEnd && c != '\"');
+ break;
+ case '\'':// string ' '
+ do {
+ i++;
+ if (i < lineEnd) {
+ c = document.getChar(i);
+ }
+ } while (i < lineEnd && c != '\'');
+ break;
+ }
+ i++;
+ }
+ result += deltaIndent;
+
+ if (getBlankEnd(document,lineStart) != lineEnd) {
+ // not empty line
+ break;
+ }
+ }
+ } catch (BadLocationException excp) {
+ // stop work
+ }
+ return result;
+ }
+
+ /**
+ * Get the blank region of given line after offset
+ */
+ private static int getBlankEnd(IDocument document, int offset) throws BadLocationException {
+ IRegion lineRegion = document.getLineInformationOfOffset(offset);
+ int blankEnd = offset;
+ int maxBlankEnd = lineRegion.getOffset() + lineRegion.getLength();
+
+ while (blankEnd < maxBlankEnd) {
+ char c = document.getChar(blankEnd);
+ if (c != ' ' && c != '\t') {
+ break;
+ }
+ blankEnd++;
+ }
+ return blankEnd;
+ }
+
+ /**
+ * Customizes the given command to edit the given document when a newline is pressed.
+ * @param document the document
+ * @param command the command
+ */
+ protected void indentOnNewLine(IDocument document, DocumentCommand command) {
+ try {
+ int p = (command.offset == document.getLength() ? command.offset - 1 : command.offset);
+ int line = document.getLineOfOffset(p);
+
+ // indent previous line
+ doIndentLine(line, document, command);
+
+ // get indent for new line
+ int indent = getIndentWithPreviousLine(line+1, document);
+
+ //
+ // indent new line
+ //
+ IRegion info = document.getLineInformation(line);
+ command.addCommand(info.getOffset() + info.getLength(), 0, "\n"+createString(indent), null);
+ command.shiftsCaret = true;
+ command.caretOffset = info.getOffset() + info.getLength();
+
+ } catch (BadLocationException excp) {
+ // stop work
+ }
+ }
+
+ /**
+ * Get the blank region of given line after offset
+ */
+ private static IRegion getBlankAfterOffset(IDocument document, int offset) throws BadLocationException {
+ IRegion lineRegion = document.getLineInformationOfOffset(offset);
+ int blankEnd = offset;
+ int maxBlankEnd = lineRegion.getOffset() + lineRegion.getLength();
+
+ while (blankEnd < maxBlankEnd) {
+ char c = document.getChar(blankEnd);
+ if (c != ' ' && c != '\t') {
+ break;
+ }
+ blankEnd++;
+ }
+ return new Region(offset, blankEnd - offset);
+ }
+
+ /**
+ * Returns a blank string of the given length.
+ * @param length the length of the string to create
+ * @return a blank string of the given length
+ */
+ public static String createString(int length) {
+ StringBuffer buffer = new StringBuffer(length);
+
+ for (int index = 0 ; index < length ; index++) {
+ buffer.append(' ');
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * Customizes the given command to edit the given document when a tabulation is pressed.
+ * @param document the document
+ * @param command the command
+ */
+ protected void indentOnTab(IDocument document, DocumentCommand command) {
+
+ //fullIndentDocument(document);
+
+ try {
+ int p = (command.offset == document.getLength() ? command.offset - 1 : command.offset);
+ int line = document.getLineOfOffset(p);
+
+ doIndentLine(line, document, command);
+
+ } catch (BadLocationException excp) {
+ // stop work
+ }
+ }
+
+ /**
+ * Customizes the given command to edit the given document when a specific character is pressed.
+ * @param document the document
+ * @param command the command
+ */
+ protected void indentOnSpecificChar(IDocument document, DocumentCommand command) {
+ // TODO code templates!!!
+ }
+
+ /**
+ * Indent correctly the whole document
+ * @param document the document
+ */
+ public static void fullIndentDocument(IDocument document) {
+ int line = 0;
+ int maxLine = document.getNumberOfLines();
+
+ while (line < maxLine) {
+ doIndentLine(line, document, null);
+ line++;
+ }
+ }
+
+ /**
+ * Indent correctly part of a document
+ * @param document the document
+ */
+ public static void fullIndentDocument(IDocument document, int offset, int length) {
+ try {
+ int line = document.getLineOfOffset(offset);
+ int maxLine = document.getNumberOfLines(offset, length);
+
+ while (line < maxLine) { // TODO indent part of document
+ // indentLine(line, document);
+ line++;
+ }
+ } catch (BadLocationException excp) {
+ // stop work
+ }
+ }
+}
diff --git a/src/org/eclipse/lisaac/editors/LisaacCompletionProcessor.java b/src/org/eclipse/lisaac/editors/LisaacCompletionProcessor.java
index 2f99d6d..b619dc0 100644
--- a/src/org/eclipse/lisaac/editors/LisaacCompletionProcessor.java
+++ b/src/org/eclipse/lisaac/editors/LisaacCompletionProcessor.java
@@ -10,7 +10,9 @@ import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+import org.eclipse.lisaac.LisaacPlugin;
import org.eclipse.lisaac.model.LisaacCompletionParser;
+import org.eclipse.lisaac.preferences.PreferenceConstants;
import org.eclipse.lisaac.templates.LisaacTemplateProcessor;
@@ -25,6 +27,11 @@ public class LisaacCompletionProcessor implements IContentAssistProcessor {
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
try {
+ boolean enableCompletion = LisaacPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.P_LISAAC_COMPLETION);
+ if (! enableCompletion) {
+ return null;
+ }
+
IDocument document = viewer.getDocument();
ArrayList<ICompletionProposal> result = new ArrayList<ICompletionProposal>();
diff --git a/src/org/eclipse/lisaac/editors/LisaacConfiguration.java b/src/org/eclipse/lisaac/editors/LisaacConfiguration.java
index ed0ddff..0aba2e8 100644
--- a/src/org/eclipse/lisaac/editors/LisaacConfiguration.java
+++ b/src/org/eclipse/lisaac/editors/LisaacConfiguration.java
@@ -17,7 +17,9 @@ import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.lisaac.LisaacPlugin;
import org.eclipse.lisaac.model.LisaacModel;
+import org.eclipse.lisaac.preferences.PreferenceConstants;
import org.eclipse.lisaac.templates.LisaacTemplateProcessor;
/**
@@ -69,8 +71,15 @@ public class LisaacConfiguration extends SourceViewerConfiguration {
contentAssistant.setStatusLineVisible(true);
contentAssistant.setStatusMessage("Lisaac Completion");
//
+
+ int delay;
+ try {
+ delay = LisaacPlugin.getDefault().getPreferenceStore().getInt(PreferenceConstants.P_LISAAC_COMPLETION_DELAY);
+ } catch (Exception e) {
+ delay = 500;
+ }
contentAssistant.enableAutoActivation(true);
- contentAssistant.setAutoActivationDelay(500);
+ contentAssistant.setAutoActivationDelay(delay);
contentAssistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY);
}
return contentAssistant;
diff --git a/src/org/eclipse/lisaac/editors/LisaacTextHover.java b/src/org/eclipse/lisaac/editors/LisaacTextHover.java
index 79fc5ac..4a70aaa 100644
--- a/src/org/eclipse/lisaac/editors/LisaacTextHover.java
+++ b/src/org/eclipse/lisaac/editors/LisaacTextHover.java
@@ -12,11 +12,13 @@ import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextHoverExtension;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
+import org.eclipse.lisaac.LisaacPlugin;
import org.eclipse.lisaac.model.LisaacCompletionParser;
import org.eclipse.lisaac.model.LisaacModel;
import org.eclipse.lisaac.model.items.IVariable;
import org.eclipse.lisaac.model.items.Prototype;
import org.eclipse.lisaac.model.items.Slot;
+import org.eclipse.lisaac.preferences.PreferenceConstants;
import org.eclipse.swt.widgets.Shell;
public class LisaacTextHover implements ITextHover, ITextHoverExtension {
@@ -34,6 +36,11 @@ public class LisaacTextHover implements ITextHover, ITextHoverExtension {
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
try {
+ boolean enableHover = LisaacPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.P_LISAAC_HOVER);
+ if (! enableHover) {
+ return null;
+ }
+
String text = textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength());
if (LisaacScanner.isPrototypeIdentifier(text)) {
// get prototype info
@@ -49,7 +56,7 @@ public class LisaacTextHover implements ITextHover, ITextHoverExtension {
if (prototype != null) {
Slot slot = prototype.getSlotFromKeyword(text, prototype.openParser(), hoverRegion.getOffset());
if (slot != null) {
- return "<I>Slot</I> : <b>"+slot.getHoverInformation()+"</b> <g>- "+slot.getPrototype().getName()+"</g>";
+ return "<I>Slot</I> : "+slot.getHoverInformation();
} else {
slot = prototype.getSlot(hoverRegion.getOffset());
IVariable variable = slot.getVariable(text, hoverRegion.getOffset());
diff --git a/src/org/eclipse/lisaac/model/LisaacParser.java b/src/org/eclipse/lisaac/model/LisaacParser.java
index 8bcdd14..42deb3e 100644
--- a/src/org/eclipse/lisaac/model/LisaacParser.java
+++ b/src/org/eclipse/lisaac/model/LisaacParser.java
@@ -306,9 +306,13 @@ public class LisaacParser extends AbstractLisaacParser {
lastSlot.setResultType(t);
lastSlot.setAffect(affect);
+ setCatchComment();
+
if (affect != ' ') {
readSpace();
- //old_pos = position;
+
+ setCatchCommentOff();
+
//
readDefSlot();
//
@@ -317,6 +321,9 @@ public class LisaacParser extends AbstractLisaacParser {
reporter.syntaxError("Added ';'.", getPosition());
return false;
}
+ if (lastComment != null && lastComment.length() > 0) {
+ lastSlot.setComment(lastComment);
+ }
if (lastSection.isInheritOrInsert()) {
// Add parent slot
Slot s = prototype.getParentSlot(lastSlot.getName());
diff --git a/src/org/eclipse/lisaac/model/items/Slot.java b/src/org/eclipse/lisaac/model/items/Slot.java
index 8f76d33..fe38a6a 100644
--- a/src/org/eclipse/lisaac/model/items/Slot.java
+++ b/src/org/eclipse/lisaac/model/items/Slot.java
@@ -28,6 +28,8 @@ public class Slot {
protected ArrayList<ICode> subLists;
+ protected String comment;
+
public Slot(Position position, String name, Section sectionId) {
this.name = name;
@@ -70,6 +72,10 @@ public class Slot {
this.keywordList = keywordList;
}
+ public void setComment(String comment) {
+ this.comment = comment;
+ }
+
public void setAffect(char affect) {
this.affect = affect;
}
@@ -260,7 +266,17 @@ public class Slot {
}
public String getHoverInformation() {
- return getSignature(false);
+ StringBuffer buffer = new StringBuffer("<b>");
+ buffer.append(getSignature(false));
+ buffer.append("</b> <I>- ");
+ buffer.append(getPrototype().getName());
+ buffer.append("</I>");
+ if (comment != null) {
+ buffer.append("\n\n<g>");
+ buffer.append(comment);
+ buffer.append("</g>");
+ }
+ return buffer.toString();
}
}
diff --git a/src/org/eclipse/lisaac/preferences/LisaacEditorPage.java b/src/org/eclipse/lisaac/preferences/LisaacColoringPage.java
similarity index 92%
copy from src/org/eclipse/lisaac/preferences/LisaacEditorPage.java
copy to src/org/eclipse/lisaac/preferences/LisaacColoringPage.java
index 0b087c8..c1ffcb1 100644
--- a/src/org/eclipse/lisaac/preferences/LisaacEditorPage.java
+++ b/src/org/eclipse/lisaac/preferences/LisaacColoringPage.java
@@ -12,10 +12,10 @@ import org.eclipse.ui.*;
/**
* Lisaac Syntax coloring preference page.
*/
-public class LisaacEditorPage extends FieldEditorPreferencePage
+public class LisaacColoringPage extends FieldEditorPreferencePage
implements IWorkbenchPreferencePage {
- public LisaacEditorPage() {
+ public LisaacColoringPage() {
super(GRID);
setPreferenceStore(LisaacPlugin.getDefault().getPreferenceStore());
}
diff --git a/src/org/eclipse/lisaac/preferences/LisaacEditorPage.java b/src/org/eclipse/lisaac/preferences/LisaacEditorPage.java
index 0b087c8..15cdc4e 100644
--- a/src/org/eclipse/lisaac/preferences/LisaacEditorPage.java
+++ b/src/org/eclipse/lisaac/preferences/LisaacEditorPage.java
@@ -1,12 +1,11 @@
package org.eclipse.lisaac.preferences;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.layout.GridData;
import org.eclipse.jface.preference.*;
import org.eclipse.lisaac.LisaacPlugin;
-import org.eclipse.lisaac.editors.ILisaacColor;
import org.eclipse.ui.*;
/**
@@ -20,49 +19,30 @@ implements IWorkbenchPreferencePage {
setPreferenceStore(LisaacPlugin.getDefault().getPreferenceStore());
}
- public void createFieldEditors() {
- Group g = new Group(getFieldEditorParent(),SWT.SHADOW_ETCHED_IN);
+ public void createFieldEditors() {
+ Composite g = getFieldEditorParent();
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan = 3;
g.setLayoutData(gd);
- g.setText("Lisaac Editor Syntax Coloring preferences :");
+
- Label l1= new Label(g, SWT.LEFT);
- l1.setText("");
- gd = new GridData();
+ addField(new BooleanFieldEditor(PreferenceConstants.P_LISAAC_INDENT,
+ "&Enable Auto-Indentation", g));
+ addField(new BooleanFieldEditor(PreferenceConstants.P_LISAAC_HOVER,
+ "&Enable Hovering", g));
+
+ Group completionGroup = new Group(g,SWT.SHADOW_ETCHED_IN);
+ gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan = 3;
- l1.setLayoutData(gd);
+ gd.verticalSpan = 2;
+ completionGroup.setLayoutData(gd);
+ completionGroup.setText("Content Assist preferences");
- addField(new ColorFieldEditor(
- ILisaacColor.PREF_COMMENT,
- " &Comments:", g));
- addField(new ColorFieldEditor(
- ILisaacColor.PREF_PROTOTYPE,
- " &Prototype:", g));
- addField(new ColorFieldEditor(
- ILisaacColor.PREF_PROTOTYPE_STYLE,
- " &Prototype Style:", g));
- addField(new ColorFieldEditor(
- ILisaacColor.PREF_KEYWORD,
- " &Keywords:", g));
- addField(new ColorFieldEditor(
- ILisaacColor.PREF_CHARACTER,
- " &Characters:", g));
- addField(new ColorFieldEditor(
- ILisaacColor.PREF_STRING,
- " &Strings:", g));
- addField(new ColorFieldEditor(
- ILisaacColor.PREF_NUMBER,
- " &Numbers:", g));
- addField(new ColorFieldEditor(
- ILisaacColor.PREF_OPERATOR,
- " &Operators:", g));
- addField(new ColorFieldEditor(
- ILisaacColor.PREF_EXTERNAL,
- " &Externals:", g));
- addField(new ColorFieldEditor(
- ILisaacColor.PREF_DEFAULT_COLOR,
- " O&thers:", g));
+ addField(new BooleanFieldEditor(PreferenceConstants.P_LISAAC_COMPLETION,
+ "&Enable Completion", completionGroup));
+
+ addField(new StringFieldEditor(PreferenceConstants.P_LISAAC_COMPLETION_DELAY,
+ "Auto-Activation Delay", completionGroup));
}
public void init(IWorkbench workbench) {
diff --git a/src/org/eclipse/lisaac/preferences/PreferenceConstants.java b/src/org/eclipse/lisaac/preferences/PreferenceConstants.java
index 3831b2f..a7fafeb 100644
--- a/src/org/eclipse/lisaac/preferences/PreferenceConstants.java
+++ b/src/org/eclipse/lisaac/preferences/PreferenceConstants.java
@@ -5,8 +5,13 @@ package org.eclipse.lisaac.preferences;
*/
public class PreferenceConstants {
- public static final String P_LISAAC_PATH = "";
- public static final String P_LISAAC_USER = "";
+ public static final String P_LISAAC_PATH = "lisaac_path";
+ public static final String P_LISAAC_USER = "lisaac_user";
- public static final String P_LISAAC_013_COMPATIBILITY = "";
+ public static final String P_LISAAC_INDENT = "lisaac_indent";
+ public static final String P_LISAAC_HOVER = "lisaac_hover";
+ public static final String P_LISAAC_COMPLETION = "lisaac_competion";
+ public static final String P_LISAAC_COMPLETION_DELAY = "lisaac_competion_delay";
+
+ public static final String P_LISAAC_013_COMPATIBILITY = "lisaac_013";
}
diff --git a/src/org/eclipse/lisaac/preferences/PreferenceInitializer.java b/src/org/eclipse/lisaac/preferences/PreferenceInitializer.java
index 72a6fe5..c03f3e9 100644
--- a/src/org/eclipse/lisaac/preferences/PreferenceInitializer.java
+++ b/src/org/eclipse/lisaac/preferences/PreferenceInitializer.java
@@ -21,6 +21,11 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer {
IPreferenceStore store = LisaacPlugin.getDefault().getPreferenceStore();
//store.setDefault(PreferenceConstants.P_LISAAC_PATH, "TODO");
+ store.setDefault(PreferenceConstants.P_LISAAC_INDENT, true);
+ store.setDefault(PreferenceConstants.P_LISAAC_HOVER, true);
+ store.setDefault(PreferenceConstants.P_LISAAC_COMPLETION, true);
+ store.setDefault(PreferenceConstants.P_LISAAC_COMPLETION_DELAY, 200);
+
// Colors for syntax highlighting.
store.setDefault(
ILisaacColor.PREF_COMMENT,
--
Lisaac eclipse plugin
More information about the Lisaac-commits
mailing list