Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Distinguish comments/haddock/pragmas in syntax highlighting

  • Loading branch information...
commit 3185e413bd6b80cc8e986df097a6201c774e044d 1 parent a87fa79
@JPMoresmau authored
Showing with 882 additions and 842 deletions.
  1. +2 −1  docs/releasenotes/net.sf.eclipsefp.haskell_2.4.3.txt
  2. +29 −27 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/codeassist/IScionTokens.java
  3. +4 −0 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/HaskellEditor.java
  4. +7 −3 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/text/ColorProvider.java
  5. +295 −291 ....haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/text/PartitionedScionTokenScanner.java
  6. +4 −2 ...f.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/text/ScionTokenScanner.java
  7. +151 −147 ...ell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/partitioned/PartitionSourceViewerConfiguration.java
  8. +6 −0 ...kell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/DefaultEditorPreferenceInitializer.java
  9. +4 −0 ...clipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/IEditorPreferenceNames.java
  10. +363 −357 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/SyntaxPP.java
  11. +12 −12 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/preview.hs
  12. +0 −1  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/preview.json
  13. +1 −1  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/scion/ScionManager.java
  14. +2 −0  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/util/UITexts.java
  15. +2 −0  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/util/uitexts.properties
View
3  docs/releasenotes/net.sf.eclipsefp.haskell_2.4.3.txt
@@ -5,7 +5,7 @@ Release Notes
Necessary Haskell packages:
- - EclipseFP relies on BuildWrapper, a Haskell IDE library, for a lot of its functionality. See https://github.com/JPMoresmau/BuildWrapper for more information. Version 0.6.4 of buildwrapper has been validated with this version of EclipseFP
+ - EclipseFP relies on BuildWrapper, a Haskell IDE library, for a lot of its functionality. See https://github.com/JPMoresmau/BuildWrapper for more information. Version 0.6.5 of buildwrapper has been validated with this version of EclipseFP
- EclipseFP also uses scion-browser. Version 0.2.13 has been validated with this version of EclipseFP
@@ -14,6 +14,7 @@ Fixes:
Features:
- Cabal Packages view shows a green tick on installed packages and versions when you display the list of all hackage packages.
+ - Distinguish comments/haddock/pragmas in syntax highlighting (https://github.com/JPMoresmau/eclipsefp/issues/44)
Internal:
View
56 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/codeassist/IScionTokens.java
@@ -1,27 +1,29 @@
-package net.sf.eclipsefp.haskell.core.codeassist;
-
-/**
- * Scion tokens: These are the token strings returned by scion to annotate various parts of the
- * input source, i.e., identify keywords, etc.
- *
- * @author B. Scott Michel (bscottm@ieee.org)
- */
-public interface IScionTokens {
- // !!These strings need to be synchronized with changes to the scion source!! (See lib/Scion/Inspect.hs)
- public final static String LITERAL_STRING = "LS"; //$NON-NLS-1$
- public final static String LITERAL_CHAR = "LC"; //$NON-NLS-1$
- public final static String DOCUMENTATION_ANNOTATION = "D"; //$NON-NLS-1$
- public final static String LITERATE_COMMENT = "DL"; //$NON-NLS-1$
- public final static String KEYWORD = "K"; //$NON-NLS-1$
- public final static String GHC_EXTENSION_KEYWORD = "EK"; //$NON-NLS-1$
- public final static String LITERAL_INTEGER = "LI"; //$NON-NLS-1$
- public final static String LITERAL_RATIONAL = "LR"; //$NON-NLS-1$
- public final static String LITERAL_WORD = "LW"; //$NON-NLS-1$
- public final static String LITERAL_FLOAT = "LF"; //$NON-NLS-1$
- public final static String IDENTIFIER_CONSTRUCTOR = "IC"; // aka "conid" //$NON-NLS-1$
- public final static String IDENTIFIER_VARIABLE = "IV"; // aka "varid" //$NON-NLS-1$
- public final static String SYMBOL_RESERVED = "S"; //$NON-NLS-1$
- public final static String SYMBOL_SPECIAL = "SS"; //$NON-NLS-1$
- public final static String PREPROCESSOR_TEXT = "PP"; //$NON-NLS-1$
- public final static String TEMPLATE_HASKELL = "TH"; //$NON-NLS-1$
-}
+package net.sf.eclipsefp.haskell.core.codeassist;
+
+/**
+ * Scion tokens: These are the token strings returned by scion to annotate various parts of the
+ * input source, i.e., identify keywords, etc.
+ *
+ * @author B. Scott Michel (bscottm@ieee.org)
+ */
+public interface IScionTokens {
+ // !!These strings need to be synchronized with changes to the scion source!! (See lib/Scion/Inspect.hs)
+ public final static String LITERAL_STRING = "LS"; //$NON-NLS-1$
+ public final static String LITERAL_CHAR = "LC"; //$NON-NLS-1$
+ public final static String PRAGMA = "P"; //$NON-NLS-1$
+ public final static String DOCUMENTATION_ANNOTATION = "D"; //$NON-NLS-1$
+ public final static String COMMENT = "C"; //$NON-NLS-1$
+ public final static String LITERATE_COMMENT = "DL"; //$NON-NLS-1$
+ public final static String KEYWORD = "K"; //$NON-NLS-1$
+ public final static String GHC_EXTENSION_KEYWORD = "EK"; //$NON-NLS-1$
+ public final static String LITERAL_INTEGER = "LI"; //$NON-NLS-1$
+ public final static String LITERAL_RATIONAL = "LR"; //$NON-NLS-1$
+ public final static String LITERAL_WORD = "LW"; //$NON-NLS-1$
+ public final static String LITERAL_FLOAT = "LF"; //$NON-NLS-1$
+ public final static String IDENTIFIER_CONSTRUCTOR = "IC"; // aka "conid" //$NON-NLS-1$
+ public final static String IDENTIFIER_VARIABLE = "IV"; // aka "varid" //$NON-NLS-1$
+ public final static String SYMBOL_RESERVED = "S"; //$NON-NLS-1$
+ public final static String SYMBOL_SPECIAL = "SS"; //$NON-NLS-1$
+ public final static String PREPROCESSOR_TEXT = "PP"; //$NON-NLS-1$
+ public final static String TEMPLATE_HASKELL = "TH"; //$NON-NLS-1$
+}
View
4 ...fp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/HaskellEditor.java
@@ -587,6 +587,10 @@ protected void handleElementContentReplaced() {
private boolean isAffectingProperty( final String property ) {
return property.equals( EDITOR_COMMENT_COLOR )
|| property.equals( EDITOR_COMMENT_BOLD )
+ || property.equals( EDITOR_DOC_COLOR )
+ || property.equals( EDITOR_DOC_BOLD )
+ || property.equals( EDITOR_PRAGMA_COLOR )
+ || property.equals( EDITOR_PRAGMA_BOLD )
|| property.equals( EDITOR_LITERATE_COMMENT_COLOR )
|| property.equals( EDITOR_LITERATE_COMMENT_BOLD )
|| property.equals( EDITOR_DEFAULT_COLOR )
View
10 ...skell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/text/ColorProvider.java
@@ -26,8 +26,10 @@
*/
public class ColorProvider implements IEditorPreferenceNames {
- public static final RGB DEFAULT_COMMENT = new RGB( 128, 128, 192 );
- public static final RGB DEFAULT_LITERATE_COMMENT = new RGB( 128, 128, 192 );
+ public static final RGB DEFAULT_COMMENT = new RGB( 63, 127, 95 );
+ public static final RGB DEFAULT_LITERATE_COMMENT = new RGB( 63, 95, 191 );
+ public static final RGB DEFAULT_DOC = new RGB( 63, 95, 191 );
+ public static final RGB DEFAULT_PRAGMA = new RGB( 63, 95, 191 );
public static final RGB DEFAULT_KEYWORD = new RGB( 0, 0, 196 );
public static final RGB DEFAULT_FUNCTION = new RGB( 64, 192, 192 );
public static final RGB DEFAULT_STRING = new RGB( 128, 64, 64 );
@@ -35,7 +37,7 @@
public static final RGB DEFAULT_NUMBER = new RGB( 0, 0, 0 );
public static final RGB DEFAULT_VAR = new RGB( 0, 0, 0 );
public static final RGB DEFAULT_CON = new RGB( 200, 0, 0 );
- public static final RGB DEFAULT_CPP = new RGB( 128, 128, 192 );
+ public static final RGB DEFAULT_CPP = new RGB( 63, 95, 191 );
public static final RGB DEFAULT_TH = new RGB( 0, 0, 0 );
public static final RGB DEFAULT_SYMBOL = new RGB( 128, 128, 0 );
public static final RGB DEFAULT_OTHER = new RGB( 0, 0, 0 );
@@ -119,6 +121,8 @@ private Color getColor( final RGB rgb ) {
private void initializeRgbs() {
putRgb( EDITOR_COMMENT_COLOR, DEFAULT_COMMENT );
+ putRgb( EDITOR_DOC_COLOR, DEFAULT_DOC);
+ putRgb( EDITOR_PRAGMA_COLOR, DEFAULT_PRAGMA );
putRgb( EDITOR_LITERATE_COMMENT_COLOR, DEFAULT_LITERATE_COMMENT );
putRgb( EDITOR_FUNCTION_COLOR, DEFAULT_FUNCTION );
putRgb( EDITOR_KEYWORD_COLOR, DEFAULT_KEYWORD );
View
586 ...t/sf/eclipsefp/haskell/ui/internal/editors/haskell/text/PartitionedScionTokenScanner.java
@@ -1,291 +1,295 @@
-package net.sf.eclipsefp.haskell.ui.internal.editors.haskell.text;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import net.sf.eclipsefp.haskell.buildwrapper.BWFacade;
-import net.sf.eclipsefp.haskell.buildwrapper.BuildWrapperPlugin;
-import net.sf.eclipsefp.haskell.buildwrapper.types.Location;
-import net.sf.eclipsefp.haskell.buildwrapper.types.TokenDef;
-import net.sf.eclipsefp.haskell.core.codeassist.IScionTokens;
-import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
-import net.sf.eclipsefp.haskell.ui.internal.preferences.editor.IEditorPreferenceNames;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.rules.IPartitionTokenScanner;
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.Token;
-
-/**
- * Uses Scion tokenTypesArbitrary function to get tokens for a haskell source
- *
- * @author Alejandro Serrano
- * @deprecated i don't see the use of that, use ScionTokenScanner instead
- */
-@Deprecated
-public class PartitionedScionTokenScanner implements IPartitionTokenScanner,
- IEditorPreferenceNames {
-
- private final ScannerManager man;
- //private final ScionInstance instance;
- private final IFile file;
-
- private IDocument doc;
- private String contents;
-
- private TokenDef currentTokenDef;
- private List<TokenDef> lTokenDefs;
- private ListIterator<TokenDef> tokenDefs;
- private IToken currentToken;
- private int currentOffset;
- private int currentLength;
-
- private int offset;
- private int length;
-
- private final Map<String, IToken> tokenByTypes;
-
- private final String[] initialElements;
- private final String[] endElements;
- private final String[] initialComments;
- private final String[] endComments;
-
- public PartitionedScionTokenScanner( final ScannerManager man, final IFile file ) {
- this( man, file, new String[] { "{" }, new String[] { "}" },
- new String[ 0 ], new String[ 0 ] );
- }
-
- public PartitionedScionTokenScanner( final ScannerManager man,final IFile file,
- final String[] initialElements, final String[] endElements,
- final String[] initialComments, final String[] endComments ) {
- this.man = man;
- //this.instance = instance;
- this.file = file;
-
- this.initialElements = initialElements;
- this.endElements = endElements;
- this.initialComments = initialComments;
- this.endComments = endComments;
-
- this.tokenByTypes = new HashMap<String, IToken>() {
-
- // Eclipse insists on a serial version identifier, not that this hash map
- // will ever
- // get serialized...
- private static final long serialVersionUID = 3579246300065591883L;
- {
- put( IScionTokens.LITERAL_STRING,
- man.createToken( EDITOR_STRING_COLOR, EDITOR_STRING_BOLD ) );
- put( IScionTokens.LITERAL_CHAR,
- man.createToken( EDITOR_CHAR_COLOR, EDITOR_CHAR_BOLD ) );
- put( IScionTokens.DOCUMENTATION_ANNOTATION,
- man.createToken( EDITOR_COMMENT_COLOR, EDITOR_COMMENT_BOLD ) );
- put( IScionTokens.LITERATE_COMMENT, man.createToken(
- EDITOR_LITERATE_COMMENT_COLOR, EDITOR_LITERATE_COMMENT_BOLD ) );
- put( IScionTokens.KEYWORD,
- man.createToken( EDITOR_KEYWORD_COLOR, EDITOR_KEYWORD_BOLD ) );
- put( IScionTokens.GHC_EXTENSION_KEYWORD,
- man.createToken( EDITOR_KEYWORD_COLOR, EDITOR_KEYWORD_BOLD ) );
- put( IScionTokens.LITERAL_INTEGER,
- man.createToken( EDITOR_NUMBER_COLOR, EDITOR_NUMBER_BOLD ) );
- put( IScionTokens.LITERAL_RATIONAL,
- man.createToken( EDITOR_NUMBER_COLOR, EDITOR_NUMBER_BOLD ) );
- put( IScionTokens.LITERAL_WORD,
- man.createToken( EDITOR_NUMBER_COLOR, EDITOR_NUMBER_BOLD ) );
- put( IScionTokens.LITERAL_FLOAT,
- man.createToken( EDITOR_NUMBER_COLOR, EDITOR_NUMBER_BOLD ) );
- put( IScionTokens.IDENTIFIER_CONSTRUCTOR,
- man.createToken( EDITOR_CON_COLOR, EDITOR_CON_BOLD ) );
- put( IScionTokens.IDENTIFIER_VARIABLE,
- man.createToken( EDITOR_VAR_COLOR, EDITOR_VAR_BOLD ) );
- put( IScionTokens.SYMBOL_RESERVED,
- man.createToken( EDITOR_SYMBOL_COLOR, EDITOR_SYMBOL_BOLD ) );
- put( IScionTokens.SYMBOL_SPECIAL,
- man.createToken( EDITOR_SYMBOL_COLOR, EDITOR_SYMBOL_BOLD ) );
- put( IScionTokens.PREPROCESSOR_TEXT,
- man.createToken( EDITOR_CPP_COLOR, EDITOR_CPP_BOLD ) );
- put( IScionTokens.TEMPLATE_HASKELL,
- man.createToken( EDITOR_TH_COLOR, EDITOR_TH_BOLD ) );
- }
- };
- }
-
- @Override
- public int getTokenLength() {
- if( currentTokenDef != null ) {
- return currentLength;
-
- }
- return 0;
- }
-
- @Override
- public int getTokenOffset() {
- if( currentTokenDef != null ) {
- return currentOffset;
- }
- return 0;
- }
-
- @Override
- public IToken nextToken() {
-
- do {
- if( tokenDefs != null && tokenDefs.hasNext() ) {
- TokenDef nextTokenDef = tokenDefs.next();
- try {
- int nextOffset = nextTokenDef.getLocation().getStartOffset( doc );
- int nextEnd = nextTokenDef.getLocation().getEndOffset( doc );
- int end = Math.min( offset + length, nextEnd );
-
- IToken nextToken = getTokenFromTokenDef( nextTokenDef );
- if( currentToken != null
- && currentToken.getData().equals( nextToken.getData() )
- && currentOffset + currentLength < nextOffset ) {
- nextOffset = currentOffset + currentLength;
- }
- int nextLength = end - nextOffset;
- currentLength = nextLength;
- currentOffset = nextOffset;
- currentTokenDef = nextTokenDef;
- currentToken = nextToken;
-
- if( currentOffset > offset + length ) {
- return Token.EOF;
- }
-
-
- } catch( BadLocationException ble ) {
- HaskellUIPlugin.log( ble );
- }
- } else {
- return Token.EOF;
- }
- } while( currentOffset < offset );
- return currentToken;
-
- }
-
- @Override
- public void setRange( final IDocument document, final int offset,
- final int length ) {
- currentTokenDef = null;
- // currentToken=null;
- tokenDefs = null;
-
- int realOffset = offset, realLength = length;
-
- try {
- String prevContents = document.get( realOffset, realLength );
-
- // Check whether this is a comment
- boolean isInitialComment = false, isEndComment = false;
- for( String initialC: initialComments ) {
- if( prevContents.startsWith( initialC ) ) {
- isInitialComment = true;
- break;
- }
- }
- for( String endC: endComments ) {
- if( prevContents.endsWith( endC ) ) {
- isEndComment = true;
- break;
- }
- }
- if( isInitialComment && isEndComment ) {
- // We found a comment
- doc = document;
- contents = prevContents;
-
- TokenDef def = new TokenDef( IScionTokens.LITERATE_COMMENT,
- new Location( "", document, new Region( realOffset, realLength ) ) );
- lTokenDefs = new ArrayList<TokenDef>();
- lTokenDefs.add( def );
- } else {
- // We are not in a comment
- for( String initialE: initialElements ) {
- if( prevContents.startsWith( initialE ) ) {
- int initialLength = initialE.length();
- realOffset += initialLength;
- realLength -= initialLength;
- for( int i = initialLength; i < prevContents.length(); i++ ) {
- char c = prevContents.charAt( i );
- if( Character.isWhitespace( c ) ) {
- realOffset++;
- realLength--;
- } else {
- break;
- }
- }
- break;
- }
- }
- for( String endE: endElements ) {
- if( prevContents.endsWith( endE ) ) {
- realLength -= endE.length();
- break;
- }
- }
-
- String newContents = document.get( realOffset, realLength );
-
- if( !document.equals( doc ) || !newContents.equals( contents )
- || lTokenDefs == null ) {
- doc = document;
- contents = newContents;
- BWFacade f=BuildWrapperPlugin.getFacade( file.getProject() );
- if (f!=null){
- f.write( file, contents );
- lTokenDefs = f.tokenTypes( file );
- }
- }
-
- try {
- // Move the offset to the correct place
- // First get line and character
- int line = document.getLineOfOffset( realOffset );
- int lineOffset = document.getLineOffset( line );
- int column = realOffset - lineOffset;
- if( lTokenDefs != null ) {
- for( TokenDef def: lTokenDefs ) {
- def.move( line, column );
- }
- }
- } catch( BadLocationException ble ) {
- HaskellUIPlugin.log( ble );
- }
- }
- } catch( BadLocationException ble ) {
- HaskellUIPlugin.log( ble );
- }
-
- this.doc = document;
- if( lTokenDefs != null && lTokenDefs.size() > 0 ) {
- tokenDefs = lTokenDefs.listIterator();
- }
-
- this.offset = realOffset;
- this.length = realLength;
- this.currentTokenDef = null;
- this.currentOffset = this.offset;
- this.currentLength = this.length;
- }
-
- private IToken getTokenFromTokenDef( final TokenDef td ) {
- IToken tok = tokenByTypes.get( td.getName() );
- if( tok != null ) {
- return tok;
- }
- return man.createToken( EDITOR_DEFAULT_COLOR, EDITOR_DEFAULT_BOLD );
- }
-
- @Override
- public void setPartialRange( final IDocument document, final int offset,
- final int length, final String contentType, final int partitionOffset ) {
- setRange( document, offset, length );
- }
-}
+package net.sf.eclipsefp.haskell.ui.internal.editors.haskell.text;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import net.sf.eclipsefp.haskell.buildwrapper.BWFacade;
+import net.sf.eclipsefp.haskell.buildwrapper.BuildWrapperPlugin;
+import net.sf.eclipsefp.haskell.buildwrapper.types.Location;
+import net.sf.eclipsefp.haskell.buildwrapper.types.TokenDef;
+import net.sf.eclipsefp.haskell.core.codeassist.IScionTokens;
+import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
+import net.sf.eclipsefp.haskell.ui.internal.preferences.editor.IEditorPreferenceNames;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.rules.IPartitionTokenScanner;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.Token;
+
+/**
+ * Uses Scion tokenTypesArbitrary function to get tokens for a haskell source
+ *
+ * @author Alejandro Serrano
+ * @deprecated i don't see the use of that, use ScionTokenScanner instead
+ */
+@Deprecated
+public class PartitionedScionTokenScanner implements IPartitionTokenScanner,
+ IEditorPreferenceNames {
+
+ private final ScannerManager man;
+ //private final ScionInstance instance;
+ private final IFile file;
+
+ private IDocument doc;
+ private String contents;
+
+ private TokenDef currentTokenDef;
+ private List<TokenDef> lTokenDefs;
+ private ListIterator<TokenDef> tokenDefs;
+ private IToken currentToken;
+ private int currentOffset;
+ private int currentLength;
+
+ private int offset;
+ private int length;
+
+ private final Map<String, IToken> tokenByTypes;
+
+ private final String[] initialElements;
+ private final String[] endElements;
+ private final String[] initialComments;
+ private final String[] endComments;
+
+ public PartitionedScionTokenScanner( final ScannerManager man, final IFile file ) {
+ this( man, file, new String[] { "{" }, new String[] { "}" },
+ new String[ 0 ], new String[ 0 ] );
+ }
+
+ public PartitionedScionTokenScanner( final ScannerManager man,final IFile file,
+ final String[] initialElements, final String[] endElements,
+ final String[] initialComments, final String[] endComments ) {
+ this.man = man;
+ //this.instance = instance;
+ this.file = file;
+
+ this.initialElements = initialElements;
+ this.endElements = endElements;
+ this.initialComments = initialComments;
+ this.endComments = endComments;
+
+ this.tokenByTypes = new HashMap<String, IToken>() {
+
+ // Eclipse insists on a serial version identifier, not that this hash map
+ // will ever
+ // get serialized...
+ private static final long serialVersionUID = 3579246300065591883L;
+ {
+ put( IScionTokens.LITERAL_STRING,
+ man.createToken( EDITOR_STRING_COLOR, EDITOR_STRING_BOLD ) );
+ put( IScionTokens.LITERAL_CHAR,
+ man.createToken( EDITOR_CHAR_COLOR, EDITOR_CHAR_BOLD ) );
+ put( IScionTokens.DOCUMENTATION_ANNOTATION,
+ man.createToken( EDITOR_DOC_COLOR, EDITOR_DOC_BOLD ) );
+ put( IScionTokens.COMMENT,
+ man.createToken( EDITOR_COMMENT_COLOR, EDITOR_COMMENT_BOLD ) );
+ put( IScionTokens.LITERATE_COMMENT, man.createToken(
+ EDITOR_LITERATE_COMMENT_COLOR, EDITOR_LITERATE_COMMENT_BOLD ) );
+ put( IScionTokens.PRAGMA,
+ man.createToken( EDITOR_PRAGMA_COLOR, EDITOR_PRAGMA_BOLD ) );
+ put( IScionTokens.KEYWORD,
+ man.createToken( EDITOR_KEYWORD_COLOR, EDITOR_KEYWORD_BOLD ) );
+ put( IScionTokens.GHC_EXTENSION_KEYWORD,
+ man.createToken( EDITOR_KEYWORD_COLOR, EDITOR_KEYWORD_BOLD ) );
+ put( IScionTokens.LITERAL_INTEGER,
+ man.createToken( EDITOR_NUMBER_COLOR, EDITOR_NUMBER_BOLD ) );
+ put( IScionTokens.LITERAL_RATIONAL,
+ man.createToken( EDITOR_NUMBER_COLOR, EDITOR_NUMBER_BOLD ) );
+ put( IScionTokens.LITERAL_WORD,
+ man.createToken( EDITOR_NUMBER_COLOR, EDITOR_NUMBER_BOLD ) );
+ put( IScionTokens.LITERAL_FLOAT,
+ man.createToken( EDITOR_NUMBER_COLOR, EDITOR_NUMBER_BOLD ) );
+ put( IScionTokens.IDENTIFIER_CONSTRUCTOR,
+ man.createToken( EDITOR_CON_COLOR, EDITOR_CON_BOLD ) );
+ put( IScionTokens.IDENTIFIER_VARIABLE,
+ man.createToken( EDITOR_VAR_COLOR, EDITOR_VAR_BOLD ) );
+ put( IScionTokens.SYMBOL_RESERVED,
+ man.createToken( EDITOR_SYMBOL_COLOR, EDITOR_SYMBOL_BOLD ) );
+ put( IScionTokens.SYMBOL_SPECIAL,
+ man.createToken( EDITOR_SYMBOL_COLOR, EDITOR_SYMBOL_BOLD ) );
+ put( IScionTokens.PREPROCESSOR_TEXT,
+ man.createToken( EDITOR_CPP_COLOR, EDITOR_CPP_BOLD ) );
+ put( IScionTokens.TEMPLATE_HASKELL,
+ man.createToken( EDITOR_TH_COLOR, EDITOR_TH_BOLD ) );
+ }
+ };
+ }
+
+ @Override
+ public int getTokenLength() {
+ if( currentTokenDef != null ) {
+ return currentLength;
+
+ }
+ return 0;
+ }
+
+ @Override
+ public int getTokenOffset() {
+ if( currentTokenDef != null ) {
+ return currentOffset;
+ }
+ return 0;
+ }
+
+ @Override
+ public IToken nextToken() {
+
+ do {
+ if( tokenDefs != null && tokenDefs.hasNext() ) {
+ TokenDef nextTokenDef = tokenDefs.next();
+ try {
+ int nextOffset = nextTokenDef.getLocation().getStartOffset( doc );
+ int nextEnd = nextTokenDef.getLocation().getEndOffset( doc );
+ int end = Math.min( offset + length, nextEnd );
+
+ IToken nextToken = getTokenFromTokenDef( nextTokenDef );
+ if( currentToken != null
+ && currentToken.getData().equals( nextToken.getData() )
+ && currentOffset + currentLength < nextOffset ) {
+ nextOffset = currentOffset + currentLength;
+ }
+ int nextLength = end - nextOffset;
+ currentLength = nextLength;
+ currentOffset = nextOffset;
+ currentTokenDef = nextTokenDef;
+ currentToken = nextToken;
+
+ if( currentOffset > offset + length ) {
+ return Token.EOF;
+ }
+
+
+ } catch( BadLocationException ble ) {
+ HaskellUIPlugin.log( ble );
+ }
+ } else {
+ return Token.EOF;
+ }
+ } while( currentOffset < offset );
+ return currentToken;
+
+ }
+
+ @Override
+ public void setRange( final IDocument document, final int offset,
+ final int length ) {
+ currentTokenDef = null;
+ // currentToken=null;
+ tokenDefs = null;
+
+ int realOffset = offset, realLength = length;
+
+ try {
+ String prevContents = document.get( realOffset, realLength );
+
+ // Check whether this is a comment
+ boolean isInitialComment = false, isEndComment = false;
+ for( String initialC: initialComments ) {
+ if( prevContents.startsWith( initialC ) ) {
+ isInitialComment = true;
+ break;
+ }
+ }
+ for( String endC: endComments ) {
+ if( prevContents.endsWith( endC ) ) {
+ isEndComment = true;
+ break;
+ }
+ }
+ if( isInitialComment && isEndComment ) {
+ // We found a comment
+ doc = document;
+ contents = prevContents;
+
+ TokenDef def = new TokenDef( IScionTokens.LITERATE_COMMENT,
+ new Location( "", document, new Region( realOffset, realLength ) ) );
+ lTokenDefs = new ArrayList<TokenDef>();
+ lTokenDefs.add( def );
+ } else {
+ // We are not in a comment
+ for( String initialE: initialElements ) {
+ if( prevContents.startsWith( initialE ) ) {
+ int initialLength = initialE.length();
+ realOffset += initialLength;
+ realLength -= initialLength;
+ for( int i = initialLength; i < prevContents.length(); i++ ) {
+ char c = prevContents.charAt( i );
+ if( Character.isWhitespace( c ) ) {
+ realOffset++;
+ realLength--;
+ } else {
+ break;
+ }
+ }
+ break;
+ }
+ }
+ for( String endE: endElements ) {
+ if( prevContents.endsWith( endE ) ) {
+ realLength -= endE.length();
+ break;
+ }
+ }
+
+ String newContents = document.get( realOffset, realLength );
+
+ if( !document.equals( doc ) || !newContents.equals( contents )
+ || lTokenDefs == null ) {
+ doc = document;
+ contents = newContents;
+ BWFacade f=BuildWrapperPlugin.getFacade( file.getProject() );
+ if (f!=null){
+ f.write( file, contents );
+ lTokenDefs = f.tokenTypes( file );
+ }
+ }
+
+ try {
+ // Move the offset to the correct place
+ // First get line and character
+ int line = document.getLineOfOffset( realOffset );
+ int lineOffset = document.getLineOffset( line );
+ int column = realOffset - lineOffset;
+ if( lTokenDefs != null ) {
+ for( TokenDef def: lTokenDefs ) {
+ def.move( line, column );
+ }
+ }
+ } catch( BadLocationException ble ) {
+ HaskellUIPlugin.log( ble );
+ }
+ }
+ } catch( BadLocationException ble ) {
+ HaskellUIPlugin.log( ble );
+ }
+
+ this.doc = document;
+ if( lTokenDefs != null && lTokenDefs.size() > 0 ) {
+ tokenDefs = lTokenDefs.listIterator();
+ }
+
+ this.offset = realOffset;
+ this.length = realLength;
+ this.currentTokenDef = null;
+ this.currentOffset = this.offset;
+ this.currentLength = this.length;
+ }
+
+ private IToken getTokenFromTokenDef( final TokenDef td ) {
+ IToken tok = tokenByTypes.get( td.getName() );
+ if( tok != null ) {
+ return tok;
+ }
+ return man.createToken( EDITOR_DEFAULT_COLOR, EDITOR_DEFAULT_BOLD );
+ }
+
+ @Override
+ public void setPartialRange( final IDocument document, final int offset,
+ final int length, final String contentType, final int partitionOffset ) {
+ setRange( document, offset, length );
+ }
+}
View
6 ...l.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/text/ScionTokenScanner.java
@@ -87,7 +87,9 @@ public ScionTokenScanner(final ScannerManager man,final IFile file,final Display
{
put( IScionTokens.LITERAL_STRING, man.createToken( EDITOR_STRING_COLOR, EDITOR_STRING_BOLD ) );
put( IScionTokens.LITERAL_CHAR, man.createToken( EDITOR_CHAR_COLOR, EDITOR_CHAR_BOLD ) );
- put( IScionTokens.DOCUMENTATION_ANNOTATION, man.createToken( EDITOR_COMMENT_COLOR,EDITOR_COMMENT_BOLD ) );
+ put( IScionTokens.DOCUMENTATION_ANNOTATION, man.createToken( EDITOR_DOC_COLOR,EDITOR_DOC_BOLD ) );
+ put( IScionTokens.COMMENT, man.createToken( EDITOR_COMMENT_COLOR,EDITOR_COMMENT_BOLD ) );
+ put( IScionTokens.PRAGMA, man.createToken( EDITOR_PRAGMA_COLOR,EDITOR_PRAGMA_BOLD ) );
put( IScionTokens.LITERATE_COMMENT, man.createToken( EDITOR_LITERATE_COMMENT_COLOR, EDITOR_LITERATE_COMMENT_BOLD ) );
put( IScionTokens.KEYWORD, man.createToken( EDITOR_KEYWORD_COLOR, EDITOR_KEYWORD_BOLD ) );
put( IScionTokens.GHC_EXTENSION_KEYWORD, man.createToken( EDITOR_KEYWORD_COLOR, EDITOR_KEYWORD_BOLD ) );
@@ -364,7 +366,7 @@ public void markTaskTags(){
try {
file.deleteMarkers( IMarker.TASK , true, IResource.DEPTH_ZERO );
for (TokenDef nextTokenDef:lTokenDefs){
- if (nextTokenDef.getName().equals(IScionTokens.DOCUMENTATION_ANNOTATION) || nextTokenDef.getName().equals(IScionTokens.LITERATE_COMMENT)){
+ if (nextTokenDef.getName().equals(IScionTokens.DOCUMENTATION_ANNOTATION) || nextTokenDef.getName().equals(IScionTokens.COMMENT) || nextTokenDef.getName().equals(IScionTokens.LITERATE_COMMENT)){
String s=nextTokenDef.getLocation().getContents( doc );
outer:for (int a=0;a<s.length();a++){
if (Character.isLetter( s.charAt( a ) )){
View
298 ...eclipsefp/haskell/ui/internal/editors/partitioned/PartitionSourceViewerConfiguration.java
@@ -1,148 +1,152 @@
-/**
- * (c) 2011, Alejandro Serrano
- * Released under the terms of the EPL.
- */
-package net.sf.eclipsefp.haskell.ui.internal.editors.partitioned;
-
-
-import java.util.HashMap;
-import java.util.Map;
-import net.sf.eclipsefp.haskell.core.codeassist.IScionTokens;
-import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
-import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.text.AnnotationHover;
-import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.text.ScannerManager;
-import net.sf.eclipsefp.haskell.ui.internal.preferences.editor.IEditorPreferenceNames;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.WordRule;
-import org.eclipse.jface.text.source.IAnnotationHover;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.SourceViewerConfiguration;
-
-/**
- * Base class for source configuration of Alex, Happy and UUAGC editors.
- * @author Alejandro Serrano
- *
- */
-public class PartitionSourceViewerConfiguration extends
- SourceViewerConfiguration implements IEditorPreferenceNames {
-
- /** The associated editor */
- protected final PartitionEditor editor;
- /** The plugin's preference store */
- protected IPreferenceStore prefStore;
- /** The syntax highlighting and other content management container */
- protected ScannerManager scannerManager;
-
- protected final Map<String, IToken> tokenByTypes;
-
- public PartitionSourceViewerConfiguration( final PartitionEditor editor ) {
- super();
- this.editor = editor;
-
- this.tokenByTypes = new HashMap<String, IToken>() {
-
- // Eclipse insists on a serial version identifier, not that this hash map
- // will ever
- // get serialized...
- private static final long serialVersionUID = 3579246300065591883L;
- {
- put(
- IScionTokens.LITERAL_STRING,
- getScannerManager().createToken( EDITOR_STRING_COLOR,
- EDITOR_STRING_BOLD ) );
- put(
- IScionTokens.LITERAL_CHAR,
- getScannerManager().createToken( EDITOR_CHAR_COLOR,
- EDITOR_CHAR_BOLD ) );
- put( IScionTokens.DOCUMENTATION_ANNOTATION, getScannerManager()
- .createToken( EDITOR_COMMENT_COLOR, EDITOR_COMMENT_BOLD ) );
- put(
- IScionTokens.LITERATE_COMMENT,
- getScannerManager().createToken( EDITOR_LITERATE_COMMENT_COLOR,
- EDITOR_LITERATE_COMMENT_BOLD ) );
- put(
- IScionTokens.KEYWORD,
- getScannerManager().createToken( EDITOR_KEYWORD_COLOR,
- EDITOR_KEYWORD_BOLD ) );
- put( IScionTokens.GHC_EXTENSION_KEYWORD, getScannerManager()
- .createToken( EDITOR_KEYWORD_COLOR, EDITOR_KEYWORD_BOLD ) );
- put(
- IScionTokens.LITERAL_INTEGER,
- getScannerManager().createToken( EDITOR_NUMBER_COLOR,
- EDITOR_NUMBER_BOLD ) );
- put(
- IScionTokens.LITERAL_RATIONAL,
- getScannerManager().createToken( EDITOR_NUMBER_COLOR,
- EDITOR_NUMBER_BOLD ) );
- put(
- IScionTokens.LITERAL_WORD,
- getScannerManager().createToken( EDITOR_NUMBER_COLOR,
- EDITOR_NUMBER_BOLD ) );
- put(
- IScionTokens.LITERAL_FLOAT,
- getScannerManager().createToken( EDITOR_NUMBER_COLOR,
- EDITOR_NUMBER_BOLD ) );
- put( IScionTokens.IDENTIFIER_CONSTRUCTOR, getScannerManager()
- .createToken( EDITOR_CON_COLOR, EDITOR_CON_BOLD ) );
- put( IScionTokens.IDENTIFIER_VARIABLE,
- getScannerManager().createToken( EDITOR_VAR_COLOR, EDITOR_VAR_BOLD ) );
- put(
- IScionTokens.SYMBOL_RESERVED,
- getScannerManager().createToken( EDITOR_SYMBOL_COLOR,
- EDITOR_SYMBOL_BOLD ) );
- put(
- IScionTokens.SYMBOL_SPECIAL,
- getScannerManager().createToken( EDITOR_SYMBOL_COLOR,
- EDITOR_SYMBOL_BOLD ) );
- put( IScionTokens.PREPROCESSOR_TEXT,
- getScannerManager().createToken( EDITOR_CPP_COLOR, EDITOR_CPP_BOLD ) );
- put( IScionTokens.TEMPLATE_HASKELL,
- getScannerManager().createToken( EDITOR_TH_COLOR, EDITOR_TH_BOLD ) );
- }
- };
- }
-
- protected WordRule createRuleForToken( final String string, final String token ) {
- WordRule rule = new WordRule( new SingleWordDetector( string ) );
- rule.addWord( string, tokenByTypes.get( token ) );
- return rule;
- }
-
- @Override
- public int getTabWidth( final ISourceViewer sourceViewer ) {
- return getPreferenceStore().getInt( EDITOR_TAB_WIDTH );
- }
-
- protected IPreferenceStore getPreferenceStore() {
- if( prefStore != null ) {
- return prefStore;
- }
- return HaskellUIPlugin.getDefault().getPreferenceStore();
- }
-
- public void setPreferenceStore( final IPreferenceStore prefStore ) {
- this.prefStore = prefStore;
- }
-
- /**
- * Get the scanner manager. If the preference store (prefStore) is set, then
- * return a new {@link ScannerManager} that uses the preference store;
- * otherwise, return the ScannerManager singleton instance.
- * */
- public ScannerManager getScannerManager() {
- if( prefStore != null ) {
- if( scannerManager == null ) {
- scannerManager = new ScannerManager( prefStore );
- }
- return scannerManager;
- }
- return ScannerManager.getInstance();
- }
-
- @Override
- public IAnnotationHover getAnnotationHover( final ISourceViewer sourceViewer ) {
- return new AnnotationHover();
- }
-
+/**
+ * (c) 2011, Alejandro Serrano
+ * Released under the terms of the EPL.
+ */
+package net.sf.eclipsefp.haskell.ui.internal.editors.partitioned;
+
+
+import java.util.HashMap;
+import java.util.Map;
+import net.sf.eclipsefp.haskell.core.codeassist.IScionTokens;
+import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
+import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.text.AnnotationHover;
+import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.text.ScannerManager;
+import net.sf.eclipsefp.haskell.ui.internal.preferences.editor.IEditorPreferenceNames;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.WordRule;
+import org.eclipse.jface.text.source.IAnnotationHover;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+
+/**
+ * Base class for source configuration of Alex, Happy and UUAGC editors.
+ * @author Alejandro Serrano
+ *
+ */
+public class PartitionSourceViewerConfiguration extends
+ SourceViewerConfiguration implements IEditorPreferenceNames {
+
+ /** The associated editor */
+ protected final PartitionEditor editor;
+ /** The plugin's preference store */
+ protected IPreferenceStore prefStore;
+ /** The syntax highlighting and other content management container */
+ protected ScannerManager scannerManager;
+
+ protected final Map<String, IToken> tokenByTypes;
+
+ public PartitionSourceViewerConfiguration( final PartitionEditor editor ) {
+ super();
+ this.editor = editor;
+
+ this.tokenByTypes = new HashMap<String, IToken>() {
+
+ // Eclipse insists on a serial version identifier, not that this hash map
+ // will ever
+ // get serialized...
+ private static final long serialVersionUID = 3579246300065591883L;
+ {
+ put(
+ IScionTokens.LITERAL_STRING,
+ getScannerManager().createToken( EDITOR_STRING_COLOR,
+ EDITOR_STRING_BOLD ) );
+ put(
+ IScionTokens.LITERAL_CHAR,
+ getScannerManager().createToken( EDITOR_CHAR_COLOR,
+ EDITOR_CHAR_BOLD ) );
+ put( IScionTokens.DOCUMENTATION_ANNOTATION, getScannerManager()
+ .createToken( EDITOR_DOC_COLOR, EDITOR_DOC_BOLD ) );
+ put( IScionTokens.COMMENT, getScannerManager()
+ .createToken( EDITOR_COMMENT_COLOR, EDITOR_COMMENT_BOLD ) );
+ put( IScionTokens.PRAGMA, getScannerManager()
+ .createToken( EDITOR_PRAGMA_COLOR, EDITOR_PRAGMA_BOLD ) );
+ put(
+ IScionTokens.LITERATE_COMMENT,
+ getScannerManager().createToken( EDITOR_LITERATE_COMMENT_COLOR,
+ EDITOR_LITERATE_COMMENT_BOLD ) );
+ put(
+ IScionTokens.KEYWORD,
+ getScannerManager().createToken( EDITOR_KEYWORD_COLOR,
+ EDITOR_KEYWORD_BOLD ) );
+ put( IScionTokens.GHC_EXTENSION_KEYWORD, getScannerManager()
+ .createToken( EDITOR_KEYWORD_COLOR, EDITOR_KEYWORD_BOLD ) );
+ put(
+ IScionTokens.LITERAL_INTEGER,
+ getScannerManager().createToken( EDITOR_NUMBER_COLOR,
+ EDITOR_NUMBER_BOLD ) );
+ put(
+ IScionTokens.LITERAL_RATIONAL,
+ getScannerManager().createToken( EDITOR_NUMBER_COLOR,
+ EDITOR_NUMBER_BOLD ) );
+ put(
+ IScionTokens.LITERAL_WORD,
+ getScannerManager().createToken( EDITOR_NUMBER_COLOR,
+ EDITOR_NUMBER_BOLD ) );
+ put(
+ IScionTokens.LITERAL_FLOAT,
+ getScannerManager().createToken( EDITOR_NUMBER_COLOR,
+ EDITOR_NUMBER_BOLD ) );
+ put( IScionTokens.IDENTIFIER_CONSTRUCTOR, getScannerManager()
+ .createToken( EDITOR_CON_COLOR, EDITOR_CON_BOLD ) );
+ put( IScionTokens.IDENTIFIER_VARIABLE,
+ getScannerManager().createToken( EDITOR_VAR_COLOR, EDITOR_VAR_BOLD ) );
+ put(
+ IScionTokens.SYMBOL_RESERVED,
+ getScannerManager().createToken( EDITOR_SYMBOL_COLOR,
+ EDITOR_SYMBOL_BOLD ) );
+ put(
+ IScionTokens.SYMBOL_SPECIAL,
+ getScannerManager().createToken( EDITOR_SYMBOL_COLOR,
+ EDITOR_SYMBOL_BOLD ) );
+ put( IScionTokens.PREPROCESSOR_TEXT,
+ getScannerManager().createToken( EDITOR_CPP_COLOR, EDITOR_CPP_BOLD ) );
+ put( IScionTokens.TEMPLATE_HASKELL,
+ getScannerManager().createToken( EDITOR_TH_COLOR, EDITOR_TH_BOLD ) );
+ }
+ };
+ }
+
+ protected WordRule createRuleForToken( final String string, final String token ) {
+ WordRule rule = new WordRule( new SingleWordDetector( string ) );
+ rule.addWord( string, tokenByTypes.get( token ) );
+ return rule;
+ }
+
+ @Override
+ public int getTabWidth( final ISourceViewer sourceViewer ) {
+ return getPreferenceStore().getInt( EDITOR_TAB_WIDTH );
+ }
+
+ protected IPreferenceStore getPreferenceStore() {
+ if( prefStore != null ) {
+ return prefStore;
+ }
+ return HaskellUIPlugin.getDefault().getPreferenceStore();
+ }
+
+ public void setPreferenceStore( final IPreferenceStore prefStore ) {
+ this.prefStore = prefStore;
+ }
+
+ /**
+ * Get the scanner manager. If the preference store (prefStore) is set, then
+ * return a new {@link ScannerManager} that uses the preference store;
+ * otherwise, return the ScannerManager singleton instance.
+ * */
+ public ScannerManager getScannerManager() {
+ if( prefStore != null ) {
+ if( scannerManager == null ) {
+ scannerManager = new ScannerManager( prefStore );
+ }
+ return scannerManager;
+ }
+ return ScannerManager.getInstance();
+ }
+
+ @Override
+ public IAnnotationHover getAnnotationHover( final ISourceViewer sourceViewer ) {
+ return new AnnotationHover();
+ }
+
}
View
6 .../eclipsefp/haskell/ui/internal/preferences/editor/DefaultEditorPreferenceInitializer.java
@@ -65,6 +65,12 @@ private static void initColors( final IPreferenceStore store ) {
ColorProvider.DEFAULT_LITERATE_COMMENT );
store.setDefault( EDITOR_LITERATE_COMMENT_BOLD, false );
+ conv( store, EDITOR_DOC_COLOR, ColorProvider.DEFAULT_DOC );
+ store.setDefault( EDITOR_DOC_BOLD, false );
+ conv( store, EDITOR_PRAGMA_COLOR, ColorProvider.DEFAULT_PRAGMA );
+ store.setDefault( EDITOR_PRAGMA_BOLD, true );
+
+
conv( store, EDITOR_FUNCTION_COLOR, ColorProvider.DEFAULT_FUNCTION );
store.setDefault( EDITOR_FUNCTION_BOLD, true );
conv( store, EDITOR_KEYWORD_COLOR, ColorProvider.DEFAULT_KEYWORD );
View
4 ...i/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/IEditorPreferenceNames.java
@@ -43,6 +43,10 @@
String EDITOR_MATCHING_BRACKETS_COLOR = "matchingBracketsColor"; //$NON-NLS-1$
String EDITOR_COMMENT_COLOR = "commentColor"; //$NON-NLS-1$
String EDITOR_COMMENT_BOLD = "commentBold"; //$NON-NLS-1$
+ String EDITOR_DOC_COLOR = "docColor"; //$NON-NLS-1$
+ String EDITOR_DOC_BOLD = "docBold"; //$NON-NLS-1$
+ String EDITOR_PRAGMA_COLOR = "pragmaColor"; //$NON-NLS-1$
+ String EDITOR_PRAGMA_BOLD = "pragmaBold"; //$NON-NLS-1$
String EDITOR_LITERATE_COMMENT_COLOR = "literateCommentColor"; //$NON-NLS-1$
String EDITOR_LITERATE_COMMENT_BOLD = "literateCommentBold"; //$NON-NLS-1$
String EDITOR_FUNCTION_COLOR = "functionColor"; //$NON-NLS-1$
View
720 ...sefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/SyntaxPP.java
@@ -1,357 +1,363 @@
-package net.sf.eclipsefp.haskell.ui.internal.preferences.editor;
-
-import java.text.NumberFormat;
-import java.text.ParseException;
-import java.util.Arrays;
-import java.util.Locale;
-import net.sf.eclipsefp.common.ui.preferences.overlay.OverlayPreferenceStore;
-import net.sf.eclipsefp.common.ui.util.DialogUtil;
-import net.sf.eclipsefp.haskell.ui.internal.util.UITexts;
-import org.eclipse.jface.preference.ColorSelector;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferenceConverter;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.layout.RowLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.List;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IWorkbench;
-
-
-public class SyntaxPP extends AbstractEditorPP {
- private Button rbBackgroundDefault;
- private Button rbBackgroundCustom;
- private ColorSelector backgroundColorSelector;
- private ColorSelector colorSelector;
- private Button cbBold;
- private List colorList;
-
- private Text coloringThreadT;
-
- public static final ColorListEntry[] colorListModel = new ColorListEntry[] {
- new ColorListEntry( UITexts.preferences_editor_syntax_comments, EDITOR_COMMENT_COLOR, EDITOR_COMMENT_BOLD ),
- new ColorListEntry( UITexts.preferences_editor_syntax_literatecomments,
- EDITOR_LITERATE_COMMENT_COLOR,
- EDITOR_LITERATE_COMMENT_BOLD ),
- new ColorListEntry( UITexts.preferences_editor_syntax_strings, EDITOR_STRING_COLOR, EDITOR_STRING_BOLD ),
- new ColorListEntry( UITexts.preferences_editor_syntax_characters, EDITOR_CHAR_COLOR, EDITOR_CHAR_BOLD ),
- new ColorListEntry( UITexts.preferences_editor_syntax_numbers,
- EDITOR_NUMBER_COLOR,
- EDITOR_NUMBER_BOLD ),
-// new ColorListEntry( ScionText.preferences_editor_syntax_functions,
-// EDITOR_FUNCTION_COLOR,
-// EDITOR_FUNCTION_BOLD ),
- new ColorListEntry( UITexts.preferences_editor_syntax_keywords, EDITOR_KEYWORD_COLOR, EDITOR_KEYWORD_BOLD ),
- new ColorListEntry( UITexts.preferences_editor_syntax_vars, EDITOR_VAR_COLOR, EDITOR_VAR_BOLD ),
- new ColorListEntry( UITexts.preferences_editor_syntax_cons, EDITOR_CON_COLOR, EDITOR_CON_BOLD ),
- new ColorListEntry( UITexts.preferences_editor_syntax_symbols, EDITOR_SYMBOL_COLOR, EDITOR_SYMBOL_BOLD ),
- new ColorListEntry( UITexts.preferences_editor_syntax_others, EDITOR_DEFAULT_COLOR, EDITOR_DEFAULT_BOLD ),
- new ColorListEntry( UITexts.preferences_editor_syntax_cpp, EDITOR_CPP_COLOR, EDITOR_CPP_BOLD ),
- new ColorListEntry( UITexts.preferences_editor_syntax_th, EDITOR_TH_COLOR, EDITOR_TH_BOLD ) };
- {
- // order by label (see compareTo in ColorListEntry)
- Arrays.sort( colorListModel );
- }
-
-
- @Override
- protected void addPreferences( final OverlayPreferenceStore store ) {
- store.addStringKey( EDITOR_FOREGROUND_COLOR );
- store.addBooleanKey( EDITOR_FOREGROUND_DEFAULT_COLOR );
- store.addStringKey( EDITOR_BACKGROUND_COLOR );
- store.addBooleanKey( EDITOR_BACKGROUND_DEFAULT_COLOR );
- store.addStringKey( EDITOR_COMMENT_COLOR );
- store.addBooleanKey( EDITOR_COMMENT_BOLD );
- store.addStringKey( EDITOR_LITERATE_COMMENT_COLOR );
- store.addBooleanKey( EDITOR_LITERATE_COMMENT_BOLD );
- store.addStringKey( EDITOR_STRING_COLOR );
- store.addBooleanKey( EDITOR_STRING_BOLD );
- store.addStringKey( EDITOR_CHAR_COLOR );
- store.addBooleanKey( EDITOR_CHAR_BOLD );
- store.addStringKey( EDITOR_FUNCTION_COLOR );
- store.addBooleanKey( EDITOR_FUNCTION_BOLD );
- store.addStringKey( EDITOR_NUMBER_COLOR );
- store.addBooleanKey( EDITOR_NUMBER_BOLD );
- store.addStringKey( EDITOR_VAR_COLOR );
- store.addBooleanKey( EDITOR_VAR_BOLD );
- store.addStringKey( EDITOR_CON_COLOR );
- store.addBooleanKey( EDITOR_CON_BOLD );
- store.addStringKey( EDITOR_KEYWORD_COLOR );
- store.addBooleanKey( EDITOR_KEYWORD_BOLD );
- store.addStringKey( EDITOR_SYMBOL_COLOR );
- store.addBooleanKey( EDITOR_SYMBOL_BOLD );
- store.addStringKey( EDITOR_CPP_COLOR );
- store.addBooleanKey( EDITOR_CPP_BOLD );
- store.addStringKey( EDITOR_TH_COLOR );
- store.addBooleanKey( EDITOR_TH_BOLD );
- store.addStringKey( EDITOR_DEFAULT_COLOR );
- store.addBooleanKey( EDITOR_DEFAULT_BOLD );
-
- store.addIntKey( EDITOR_COLORING_THREAD_THRESHOLD );
- }
-
- @Override
- protected Control createContents( final Composite parent ) {
- Composite composite = new Composite( parent, SWT.NONE );
- composite.setLayout( new GridLayout() );
-
- Group backgroundComposite = initializeBackgroundGroup( composite );
- initializeBackgroundColorSelector( backgroundComposite );
- initializeForeGroundLabel( composite );
- Composite editorComposite = initializeEditorComposite( composite );
- initializeColorList( composite, editorComposite );
- Composite stylesComposite = initializeStylesComposite( editorComposite );
- tab.createLabel( stylesComposite, UITexts.preferences_editor_color );
- initializeColorSelector( stylesComposite );
- initializeBoldCheckBox( stylesComposite );
-
- createPreviewer( composite );
-
- createColoringThreadThreshold(composite);
-
- initialize();
-
- return composite;
- }
-
- @Override
- public void init( final IWorkbench workbench ) {
- setDescription( UITexts.preferences_editor_syntax_title);
- super.init( workbench );
- }
-
- public void initializeFields() {
- tab.initializeFields();
- IPreferenceStore ps = getPreferenceStore();
- RGB rgb = PreferenceConverter.getColor( ps, EDITOR_BACKGROUND_COLOR );
- backgroundColorSelector.setColorValue( rgb );
- boolean defaultBackgroud = ps.getBoolean( EDITOR_BACKGROUND_DEFAULT_COLOR );
- rbBackgroundDefault.setSelection( defaultBackgroud );
- rbBackgroundCustom.setSelection( !defaultBackgroud );
- backgroundColorSelector.setEnabled( !defaultBackgroud );
- }
-
-
- // ui initialization methods
- ////////////////////////////
- private void initializeColorList( final Composite composite,
- final Composite editorComposite ) {
- colorList = new List( editorComposite,
- SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER );
- GridData gridData = new GridData( GridData.FILL_BOTH );
- gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( composite,
- 5 );
- colorList.setLayoutData( gridData );
- colorList.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- handleSyntaxColorListSelection();
- }
- } );
- }
-
- private Composite initializeStylesComposite( final Composite parent ) {
- Composite stylesComposite = new Composite( parent, SWT.NONE );
- GridLayout layout = new GridLayout();
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- layout.numColumns = 2;
- stylesComposite.setLayout( layout );
- stylesComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
- return stylesComposite;
- }
-
- private void initializeBoldCheckBox( final Composite parent ) {
- cbBold = new Button( parent, SWT.CHECK );
- cbBold.setText( UITexts.preferences_editor_syntax_bold );
- GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
- gridData.horizontalAlignment = GridData.BEGINNING;
- gridData.horizontalSpan = 2;
- cbBold.setLayoutData( gridData );
- cbBold.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- int i = colorList.getSelectionIndex();
- String key = colorListModel[ i ].getBoldKey();
- getPreferenceStore().setValue( key, cbBold.getSelection() );
- }
- } );
- }
-
- private Composite initializeEditorComposite( final Composite parent ) {
- Composite editorComposite = new Composite( parent, SWT.NONE );
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- editorComposite.setLayout( layout );
- GridData gridData = new GridData( GridData.FILL_BOTH );
- editorComposite.setLayoutData( gridData );
- return editorComposite;
- }
-
- private void initializeForeGroundLabel( final Composite parent ) {
- Label label = new Label( parent, SWT.LEFT );
- label.setText( UITexts.preferences_editor_syntax_foreground );
- label.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
- }
-
- private Group initializeBackgroundGroup( final Composite parent ) {
- Group backgroundComposite = new Group( parent, SWT.SHADOW_ETCHED_IN );
- backgroundComposite.setLayout( new RowLayout() );
- backgroundComposite.setText( UITexts.preferences_editor_syntax_background );
- SelectionListener bgSelectionListener = new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- boolean custom = rbBackgroundCustom.getSelection();
- backgroundColorSelector.setEnabled( custom );
- getPreferenceStore().setValue(
- IEditorPreferenceNames.EDITOR_BACKGROUND_DEFAULT_COLOR, !custom );
- }
- };
- int style = SWT.RADIO | SWT.LEFT;
- rbBackgroundDefault = new Button( backgroundComposite, style );
- rbBackgroundDefault.setText( UITexts.preferences_editor_syntax_systemdefault);
- rbBackgroundDefault.addSelectionListener( bgSelectionListener );
- rbBackgroundCustom = new Button( backgroundComposite, style );
- rbBackgroundCustom.setText( UITexts.preferences_editor_syntax_custom );
- rbBackgroundCustom.addSelectionListener( bgSelectionListener );
- return backgroundComposite;
- }
-
- private void initializeBackgroundColorSelector( final Group parent ) {
- backgroundColorSelector = new ColorSelector( parent );
- Button backgroundColorButton = backgroundColorSelector.getButton();
- backgroundColorButton.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- String name = IEditorPreferenceNames.EDITOR_BACKGROUND_COLOR;
- RGB colorValue = backgroundColorSelector.getColorValue();
- PreferenceConverter.setValue( getPreferenceStore(), name, colorValue );
- }
- } );
- }
-
- private void initializeColorSelector( final Composite parent ) {
- colorSelector = new ColorSelector( parent );
- Button foregroundColorButton = colorSelector.getButton();
- GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
- gridData.horizontalAlignment = GridData.BEGINNING;
- foregroundColorButton.setLayoutData( gridData );
- foregroundColorButton.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- int i = colorList.getSelectionIndex();
- String key = colorListModel[ i ].getColorKey();
- RGB colorValue = colorSelector.getColorValue();
- PreferenceConverter.setValue( getPreferenceStore(), key, colorValue );
- }
- } );
- }
-
- private void createPreviewer( final Composite parent ) {
- IPreferenceStore preferenceStore = getPreferenceStore();
- SyntaxPreviewer previewer = new SyntaxPreviewer( parent, preferenceStore );
- GridData gridData = new GridData( GridData.FILL_BOTH );
- gridData.widthHint = DialogUtil.convertWidthInCharsToPixels( parent, 20 );
- gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( parent, 5 );
- previewer.getControl().setLayoutData( gridData );
- }
-
- private void createColoringThreadThreshold(final Composite parent){
-
- Composite cColoring=new Composite(parent,SWT.NONE);
- GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
- cColoring.setLayoutData( gridData );
-
- cColoring.setLayout( new GridLayout(2,false) );
-
- Label lColoring=new Label(cColoring,SWT.NONE);
- lColoring.setText( UITexts.preferences_editor_syntax_thread_threshold );
- GridData gd=new GridData( GridData.FILL_HORIZONTAL);
- gd.horizontalSpan=2;
- lColoring.setLayoutData(gd);
-
- coloringThreadT=new Text(cColoring,SWT.BORDER | SWT.RIGHT);
- coloringThreadT.setLayoutData( new GridData( GridData.FILL_HORIZONTAL) );
-
- final NumberFormat nf=NumberFormat.getIntegerInstance( Locale.getDefault() );
-
- int t=getPreferenceStore().getInt( EDITOR_COLORING_THREAD_THRESHOLD );
- coloringThreadT.setText( nf.format( t ));
- coloringThreadT.addModifyListener( new ModifyListener() {
-
- @Override
- public void modifyText( final ModifyEvent paramModifyEvent ) {
- String s=coloringThreadT.getText();
- try {
- int t=nf.parse( s ).intValue();
- setErrorMessage( null );
- getPreferenceStore().setValue( EDITOR_COLORING_THREAD_THRESHOLD, t );
- } catch (ParseException pe){
- setErrorMessage( pe.getLocalizedMessage() );
- }
-
- }
- } );
- Label lNote=new Label(cColoring,SWT.NONE);
- lNote.setText( UITexts.preferences_editor_syntax_thread_threshold_note );
- lNote.setLayoutData( new GridData( GridData.FILL_HORIZONTAL) );
-
- }
-
- public void propertyChange( final PropertyChangeEvent event ) {
- colorList.getDisplay().asyncExec( new Runnable() {
- @Override
- public void run() {
- if( ( colorList != null ) && !colorList.isDisposed() ) {
- handleSyntaxColorListSelection();
- }
- }
- } );
-
- }
-
-
-
- // helping methods
- //////////////////
-
- private void handleSyntaxColorListSelection() {
- int index = colorList.getSelectionIndex();
- String key = colorListModel[ index ].getColorKey();
- RGB rgb = PreferenceConverter.getColor( getPreferenceStore(), key );
- colorSelector.setColorValue( rgb );
- key = colorListModel[ index ].getBoldKey();
- cbBold.setSelection( getPreferenceStore().getBoolean( key ) );
- }
-
- private void initialize() {
- for( int i = 0; i < colorListModel.length; i++ ) {
- colorList.add( colorListModel[ i ].getLabel() );
- }
- colorList.getDisplay().asyncExec( new Runnable() {
- @Override
- public void run() {
- if( ( colorList != null ) && !colorList.isDisposed() ) {
- colorList.select( 0 );
- handleSyntaxColorListSelection();
- }
- }
- } );
- initializeFields();
- }
-}
+package net.sf.eclipsefp.haskell.ui.internal.preferences.editor;
+
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.Arrays;
+import java.util.Locale;
+import net.sf.eclipsefp.common.ui.preferences.overlay.OverlayPreferenceStore;
+import net.sf.eclipsefp.common.ui.util.DialogUtil;
+import net.sf.eclipsefp.haskell.ui.internal.util.UITexts;
+import org.eclipse.jface.preference.ColorSelector;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+
+
+public class SyntaxPP extends AbstractEditorPP {
+ private Button rbBackgroundDefault;
+ private Button rbBackgroundCustom;
+ private ColorSelector backgroundColorSelector;
+ private ColorSelector colorSelector;
+ private Button cbBold;
+ private List colorList;
+
+ private Text coloringThreadT;
+
+ public static final ColorListEntry[] colorListModel = new ColorListEntry[] {
+ new ColorListEntry( UITexts.preferences_editor_syntax_comments, EDITOR_COMMENT_COLOR, EDITOR_COMMENT_BOLD ),
+ new ColorListEntry( UITexts.preferences_editor_syntax_literatecomments,
+ EDITOR_LITERATE_COMMENT_COLOR,
+ EDITOR_LITERATE_COMMENT_BOLD ),
+ new ColorListEntry( UITexts.preferences_editor_syntax_doc, EDITOR_DOC_COLOR, EDITOR_DOC_BOLD ),
+ new ColorListEntry( UITexts.preferences_editor_syntax_pragmas, EDITOR_PRAGMA_COLOR, EDITOR_PRAGMA_BOLD ),
+ new ColorListEntry( UITexts.preferences_editor_syntax_strings, EDITOR_STRING_COLOR, EDITOR_STRING_BOLD ),
+ new ColorListEntry( UITexts.preferences_editor_syntax_characters, EDITOR_CHAR_COLOR, EDITOR_CHAR_BOLD ),
+ new ColorListEntry( UITexts.preferences_editor_syntax_numbers,
+ EDITOR_NUMBER_COLOR,
+ EDITOR_NUMBER_BOLD ),
+// new ColorListEntry( ScionText.preferences_editor_syntax_functions,
+// EDITOR_FUNCTION_COLOR,
+// EDITOR_FUNCTION_BOLD ),
+ new ColorListEntry( UITexts.preferences_editor_syntax_keywords, EDITOR_KEYWORD_COLOR, EDITOR_KEYWORD_BOLD ),
+ new ColorListEntry( UITexts.preferences_editor_syntax_vars, EDITOR_VAR_COLOR, EDITOR_VAR_BOLD ),
+ new ColorListEntry( UITexts.preferences_editor_syntax_cons, EDITOR_CON_COLOR, EDITOR_CON_BOLD ),
+ new ColorListEntry( UITexts.preferences_editor_syntax_symbols, EDITOR_SYMBOL_COLOR, EDITOR_SYMBOL_BOLD ),
+ new ColorListEntry( UITexts.preferences_editor_syntax_others, EDITOR_DEFAULT_COLOR, EDITOR_DEFAULT_BOLD ),
+ new ColorListEntry( UITexts.preferences_editor_syntax_cpp, EDITOR_CPP_COLOR, EDITOR_CPP_BOLD ),
+ new ColorListEntry( UITexts.preferences_editor_syntax_th, EDITOR_TH_COLOR, EDITOR_TH_BOLD ) };
+ {
+ // order by label (see compareTo in ColorListEntry)
+ Arrays.sort( colorListModel );
+ }
+
+
+ @Override
+ protected void addPreferences( final OverlayPreferenceStore store ) {
+ store.addStringKey( EDITOR_FOREGROUND_COLOR );
+ store.addBooleanKey( EDITOR_FOREGROUND_DEFAULT_COLOR );
+ store.addStringKey( EDITOR_BACKGROUND_COLOR );
+ store.addBooleanKey( EDITOR_BACKGROUND_DEFAULT_COLOR );
+ store.addStringKey( EDITOR_COMMENT_COLOR );
+ store.addBooleanKey( EDITOR_COMMENT_BOLD );
+ store.addStringKey( EDITOR_LITERATE_COMMENT_COLOR );
+ store.addBooleanKey( EDITOR_LITERATE_COMMENT_BOLD );
+ store.addStringKey( EDITOR_DOC_COLOR );
+ store.addBooleanKey( EDITOR_DOC_BOLD );
+ store.addStringKey( EDITOR_PRAGMA_COLOR );
+ store.addBooleanKey( EDITOR_PRAGMA_BOLD );
+ store.addStringKey( EDITOR_STRING_COLOR );
+ store.addBooleanKey( EDITOR_STRING_BOLD );
+ store.addStringKey( EDITOR_CHAR_COLOR );
+ store.addBooleanKey( EDITOR_CHAR_BOLD );
+ store.addStringKey( EDITOR_FUNCTION_COLOR );
+ store.addBooleanKey( EDITOR_FUNCTION_BOLD );
+ store.addStringKey( EDITOR_NUMBER_COLOR );
+ store.addBooleanKey( EDITOR_NUMBER_BOLD );
+ store.addStringKey( EDITOR_VAR_COLOR );
+ store.addBooleanKey( EDITOR_VAR_BOLD );
+ store.addStringKey( EDITOR_CON_COLOR );
+ store.addBooleanKey( EDITOR_CON_BOLD );
+ store.addStringKey( EDITOR_KEYWORD_COLOR );
+ store.addBooleanKey( EDITOR_KEYWORD_BOLD );
+ store.addStringKey( EDITOR_SYMBOL_COLOR );
+ store.addBooleanKey( EDITOR_SYMBOL_BOLD );
+ store.addStringKey( EDITOR_CPP_COLOR );
+ store.addBooleanKey( EDITOR_CPP_BOLD );
+ store.addStringKey( EDITOR_TH_COLOR );
+ store.addBooleanKey( EDITOR_TH_BOLD );
+ store.addStringKey( EDITOR_DEFAULT_COLOR );
+ store.addBooleanKey( EDITOR_DEFAULT_BOLD );
+
+ store.addIntKey( EDITOR_COLORING_THREAD_THRESHOLD );
+ }
+
+ @Override
+ protected Control createContents( final Composite parent ) {
+ Composite composite = new Composite( parent, SWT.NONE );
+ composite.setLayout( new GridLayout() );
+
+ Group backgroundComposite = initializeBackgroundGroup( composite );
+ initializeBackgroundColorSelector( backgroundComposite );
+ initializeForeGroundLabel( composite );
+ Composite editorComposite = initializeEditorComposite( composite );
+ initializeColorList( composite, editorComposite );
+ Composite stylesComposite = initializeStylesComposite( editorComposite );
+ tab.createLabel( stylesComposite, UITexts.preferences_editor_color );
+ initializeColorSelector( stylesComposite );
+ initializeBoldCheckBox( stylesComposite );
+
+ createPreviewer( composite );
+
+ createColoringThreadThreshold(composite);
+
+ initialize();
+
+ return composite;
+ }
+
+ @Override
+ public void init( final IWorkbench workbench ) {
+ setDescription( UITexts.preferences_editor_syntax_title);
+ super.init( workbench );
+ }
+
+ public void initializeFields() {
+ tab.initializeFields();
+ IPreferenceStore ps = getPreferenceStore();
+ RGB rgb = PreferenceConverter.getColor( ps, EDITOR_BACKGROUND_COLOR );
+ backgroundColorSelector.setColorValue( rgb );
+ boolean defaultBackgroud = ps.getBoolean( EDITOR_BACKGROUND_DEFAULT_COLOR );
+ rbBackgroundDefault.setSelection( defaultBackgroud );
+ rbBackgroundCustom.setSelection( !defaultBackgroud );
+ backgroundColorSelector.setEnabled( !defaultBackgroud );
+ }
+
+
+ // ui initialization methods
+ ////////////////////////////
+ private void initializeColorList( final Composite composite,
+ final Composite editorComposite ) {
+ colorList = new List( editorComposite,
+ SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER );
+ GridData gridData = new GridData( GridData.FILL_BOTH );
+ gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( composite,
+ 5 );
+ colorList.setLayoutData( gridData );
+ colorList.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ handleSyntaxColorListSelection();
+ }
+ } );
+ }
+
+ private Composite initializeStylesComposite( final Composite parent ) {
+ Composite stylesComposite = new Composite( parent, SWT.NONE );
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ layout.numColumns = 2;
+ stylesComposite.setLayout( layout );
+ stylesComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+ return stylesComposite;
+ }
+
+ private void initializeBoldCheckBox( final Composite parent ) {
+ cbBold = new Button( parent, SWT.CHECK );
+ cbBold.setText( UITexts.preferences_editor_syntax_bold );
+ GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
+ gridData.horizontalAlignment = GridData.BEGINNING;
+ gridData.horizontalSpan = 2;
+ cbBold.setLayoutData( gridData );
+ cbBold.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ int i = colorList.getSelectionIndex();
+ String key = colorListModel[ i ].getBoldKey();
+ getPreferenceStore().setValue( key, cbBold.getSelection() );
+ }
+ } );
+ }
+
+ private Composite initializeEditorComposite( final Composite parent ) {
+ Composite editorComposite = new Composite( parent, SWT.NONE );
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ editorComposite.setLayout( layout );
+ GridData gridData = new GridData( GridData.FILL_BOTH );
+ editorComposite.setLayoutData( gridData );
+ return editorComposite;
+ }
+
+ private void initializeForeGroundLabel( final Composite parent ) {
+ Label label = new Label( parent, SWT.LEFT );
+ label.setText( UITexts.preferences_editor_syntax_foreground );
+ label.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+ }
+
+ private Group initializeBackgroundGroup( final Composite parent ) {
+ Group backgroundComposite = new Group( parent, SWT.SHADOW_ETCHED_IN );
+ backgroundComposite.setLayout( new RowLayout() );
+ backgroundComposite.setText( UITexts.preferences_editor_syntax_background );
+ SelectionListener bgSelectionListener = new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ boolean custom = rbBackgroundCustom.getSelection();
+ backgroundColorSelector.setEnabled( custom );
+ getPreferenceStore().setValue(
+ IEditorPreferenceNames.EDITOR_BACKGROUND_DEFAULT_COLOR, !custom );
+ }
+ };
+ int style = SWT.RADIO | SWT.LEFT;
+ rbBackgroundDefault = new Button( backgroundComposite, style );
+ rbBackgroundDefault.setText( UITexts.preferences_editor_syntax_systemdefault);
+ rbBackgroundDefault.addSelectionListener( bgSelectionListener );
+ rbBackgroundCustom = new Button( backgroundComposite, style );
+ rbBackgroundCustom.setText( UITexts.preferences_editor_syntax_custom );
+ rbBackgroundCustom.addSelectionListener( bgSelectionListener );
+ return backgroundComposite;
+ }
+
+ private void initializeBackgroundColorSelector( final Group parent ) {
+ backgroundColorSelector = new ColorSelector( parent );
+ Button backgroundColorButton = backgroundColorSelector.getButton();
+ backgroundColorButton.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ String name = IEditorPreferenceNames.EDITOR_BACKGROUND_COLOR;
+ RGB colorValue = backgroundColorSelector.getColorValue();
+ PreferenceConverter.setValue( getPreferenceStore(), name, colorValue );
+ }
+ } );
+ }
+
+ private void initializeColorSelector( final Composite parent ) {
+ colorSelector = new ColorSelector( parent );
+ Button foregroundColorButton = colorSelector.getButton();
+ GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
+ gridData.horizontalAlignment = GridData.BEGINNING;
+ foregroundColorButton.setLayoutData( gridData );
+ foregroundColorButton.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ int i = colorList.getSelectionIndex();
+ String key = colorListModel[ i ].getColorKey();
+ RGB colorValue = colorSelector.getColorValue();
+ PreferenceConverter.setValue( getPreferenceStore(), key, colorValue );
+ }
+ } );
+ }
+
+ private void createPreviewer( final Composite parent ) {
+ IPreferenceStore preferenceStore = getPreferenceStore();
+ SyntaxPreviewer previewer = new SyntaxPreviewer( parent, preferenceStore );
+ GridData gridData = new GridData( GridData.FILL_BOTH );
+ gridData.widthHint = DialogUtil.convertWidthInCharsToPixels( parent, 20 );
+ gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( parent, 5 );
+ previewer.getControl().setLayoutData( gridData );
+ }
+
+ private void createColoringThreadThreshold(final Composite parent){
+
+ Composite cColoring=new Composite(parent,SWT.NONE);
+ GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
+ cColoring.setLayoutData( gridData );
+
+ cColoring.setLayout( new GridLayout(2,false) );
+
+ Label lColoring=new Label(cColoring,SWT.NONE);
+ lColoring.setText( UITexts.preferences_editor_syntax_thread_threshold );
+ GridData gd=new GridData( GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan=2;
+ lColoring.setLayoutData(gd);
+
+ coloringThreadT=new Text(cColoring,SWT.BORDER | SWT.RIGHT);
+ coloringThreadT.setLayoutData( new GridData( GridData.FILL_HORIZONTAL) );
+
+ final NumberFormat nf=NumberFormat.getIntegerInstance( Locale.getDefault() );
+
+ int t=getPreferenceStore().getInt( EDITOR_COLORING_THREAD_THRESHOLD );
+ coloringThreadT.setText( nf.format( t ));
+ coloringThreadT.addModifyListener( new ModifyListener() {
+
+ @Override
+ public void modifyText( final ModifyEvent paramModifyEvent ) {
+ String s=coloringThreadT.getText();
+ try {
+ int t=nf.parse( s ).intValue();
+ setErrorMessage( null );
+ getPreferenceStore().setValue( EDITOR_COLORING_THREAD_THRESHOLD, t );
+ } catch (ParseException pe){
+ setErrorMessage( pe.getLocalizedMessage() );
+ }
+
+ }
+ } );
+ Label lNote=new Label(cColoring,SWT.NONE);
+ lNote.setText( UITexts.preferences_editor_syntax_thread_threshold_note );
+ lNote.setLayoutData( new GridData( GridData.FILL_HORIZONTAL) );
+
+ }
+
+ public void propertyChange( final PropertyChangeEvent event ) {
+ colorList.getDisplay().asyncExec( new Runnable() {
+ @Override
+ public void run() {
+ if( ( colorList != null ) && !colorList.isDisposed() ) {
+ handleSyntaxColorListSelection();
+ }
+ }
+ } );
+
+ }
+
+
+
+ // helping methods
+ //////////////////
+
+ private void handleSyntaxColorListSelection() {
+ int index = colorList.getSelectionIndex();
+ String key = colorListModel[ index ].getColorKey();
+ RGB rgb = PreferenceConverter.getColor( getPreferenceStore(), key );
+ colorSelector.setColorValue( rgb );
+ key = colorListModel[ index ].getBoldKey();
+ cbBold.setSelection( getPreferenceStore().getBoolean( key ) );
+ }
+
+ private void initialize() {
+ for( int i = 0; i < colorListModel.length; i++ ) {
+ colorList.add( colorListModel[ i ].getLabel() );
+ }
+ colorList.getDisplay().asyncExec( new Runnable() {
+ @Override
+ public void run() {
+ if( ( colorList != null ) && !colorList.isDisposed() ) {
+ colorList.select( 0 );
+ handleSyntaxColorListSelection();
+ }
+ }
+ } );
+ initializeFields();
+ }
+}
View
24 ...lipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/preview.hs
@@ -1,12 +1,12 @@
-{-# LANGUAGE TemplateHaskell,CPP #-}
--- a comment
-module Main where
-
-main :: IO (Int)
-main = do
- putStr ('h':"ello Prefs!")
- return (2 + 2)
-
-#if USE_TH
-$( derive makeTypeable ''Extension )
-#endif
+{-# LANGUAGE TemplateHaskell,CPP #-}
+-- a comment
+module Main where
+
+main :: IO (Int) -- ^ haddock
+main = do
+ putStr ('h':"ello Prefs!")
+ return (2 + 2)
+
+#if USE_TH
+$( derive makeTypeable ''Extension )
+#endif
View
1  ...psefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/preview.json
@@ -1 +0,0 @@
-[["D",1,0,1,36],["D",2,0,2,13],["K",3,0,3,6],["IC",3,7,3,11],["K",3,12,3,17],["IV",5,0,5,4],["S",5,5,5,7],["IC",5,8,5,10],["SS",5,11,5,12],["IC",5,12,5,15],["SS",5,15,5,16],["IV",6,0,6,4],["S",6,5,6,6],["K",6,7,6,9],["IV",7,8,7,14],["SS",7,15,7,16],["LC",7,16,7,19],["S",7,19,7,20],["LS",7,20,7,33],["SS",7,33,7,34],["IV",8,8,8,14],["SS",8,15,8,16],["LI",8,16,8,17],["IV",8,18,8,19],["LI",8,20,8,21],["SS",8,21,8,22],["PP",10,0,10,11],["TH",11,0,11,2],["IV",11,3,11,9],["IV",11,10,11,22],["TH",11,23,11,25],["IC",11,25,11,34],["SS",11,35,11,36],["PP",12,0,12,7]]
View
2  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/scion/ScionManager.java
@@ -83,7 +83,7 @@
/** Haskell console high water mark */
private int hConHighWater;
- private final static String MINIMUM_BUILDWRAPPER="0.6.4";
+ private final static String MINIMUM_BUILDWRAPPER="0.6.5";
private final static String MINIMUM_SCIONBROWSER="0.2.12";
public ScionManager() {
View
2  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/util/UITexts.java
@@ -390,6 +390,8 @@
public static String preferences_editor_syntax_title;
public static String preferences_editor_syntax_comments;
public static String preferences_editor_syntax_literatecomments;
+ public static String preferences_editor_syntax_doc;
+ public static String preferences_editor_syntax_pragmas;
public static String preferences_editor_syntax_strings;
public static String preferences_editor_syntax_characters;
public static String preferences_editor_syntax_functions;
View
2  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/util/uitexts.properties
@@ -410,6 +410,8 @@ proposal_category_mode=Press {0} to show {1}
preferences_editor_syntax_title=Synta&x coloring options:
preferences_editor_syntax_comments=Comments
preferences_editor_syntax_literatecomments=Literate Comments
+preferences_editor_syntax_doc=Documentation
+preferences_editor_syntax_pragmas=Pragmas
preferences_editor_syntax_strings=Strings
preferences_editor_syntax_characters=Characters
preferences_editor_syntax_functions=Functions
Please sign in to comment.
Something went wrong with that request. Please try again.