Changeset 3359 for devel-tools/trunk


Ignore:
Timestamp:
Feb 4, 2008, 10:32:33 PM (13 years ago)
Author:
yura
Message:
Location:
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor/PresentationVisitor.java

    r3358 r3359  
    33import java.util.ArrayList;
    44
     5import org.eclipse.jface.preference.IPreferenceStore;
    56import org.eclipse.jface.text.TextAttribute;
    67import org.eclipse.swt.SWT;
     
    4546import org.refal.plus.rfpdt.comp.ast.ProgramVisitor;
    4647import org.refal.plus.rfpdt.comp.ast.SentenceVisitor;
     48import org.refal.plus.rfpdt.editor.color.ColorScanner;
    4749import org.refal.plus.rfpdt.editor.color.IColorPreferences;
    4850
    4951public class PresentationVisitor implements ProgramVisitor, SentenceVisitor, ExpVisitor {
    50     public static StyleRange[] updateTextPresentation (AstImplem astImplem) {
    51         PresentationVisitor presentationVisitor = new PresentationVisitor();
     52    public static StyleRange[] updateTextPresentation (AstImplem astImplem, IPreferenceStore store) {
     53        PresentationVisitor presentationVisitor = new PresentationVisitor(store);
    5254        astImplem.accept(presentationVisitor);
    5355        return presentationVisitor.styleRangeList.toArray(new StyleRange[presentationVisitor.styleRangeList.size()]);
     
    5557
    5658    private final ArrayList<StyleRange> styleRangeList;
    57 
    58     private void addAstNameStype (AstNode name, TextAttribute textAttribute) {
     59    private final IPreferenceStore store;
     60
     61    private void addAstNameStype (AstNode name, String key) {
    5962        if (name == null)
    6063            return;
     
    6265        if (pos.rfpResource.isInterface) // TODO - must be RfpResource
    6366            return;
     67        TextAttribute textAttribute = ColorScanner.getTextAttribute(store, key);
    6468        int style = textAttribute.getStyle();
    6569        StyleRange range = new StyleRange(pos.charStart, pos.charEnd - pos.charStart, textAttribute.getForeground(),
     
    7175    }
    7276
    73     private PresentationVisitor () {
     77    private PresentationVisitor (IPreferenceStore store) {
    7478        this.styleRangeList = new ArrayList<StyleRange>();
     79        this.store = store;
    7580    }
    7681
    7782    private void visitObjectDefinition (AstName name) {
    78         addAstNameStype(name, RfpSourceViewerConfiguration.getTextAttribute(IColorPreferences.IDENTIFIER_DEFINITION));
     83        addAstNameStype(name, IColorPreferences.IDENTIFIER_DEFINITION);
    7984    }
    8085
    8186    private void visitObjectUse (AstName name) {
    8287        if (name != null && name.identifier.length() < name.pos.charEnd - name.pos.charStart)
    83             addAstNameStype(name, RfpSourceViewerConfiguration.getTextAttribute(IColorPreferences.IDENTIFIER_USE));
     88            addAstNameStype(name, IColorPreferences.IDENTIFIER_USE);
    8489    }
    8590
    8691    private void visitVariableDefinition (AstName name) {
    87         addAstNameStype(name, RfpSourceViewerConfiguration.getTextAttribute(IColorPreferences.VARIABLE_DEFINITION));
     92        addAstNameStype(name, IColorPreferences.VARIABLE_DEFINITION);
    8893    }
    8994
    9095    private void visitVariableUse (AstName name) {
    91     // addAstNameStype(name, RfpSourceViewerConfiguration.getTextAttribute(IColorPreferences.VARIABLE_USE));
     96    // addAstNameStype(name, IColorPreferences.VARIABLE_USE);
    9297    }
    9398
    9499    private void visitSymbol (AstWordSymbol astWordSymbol) {
    95100        if (astWordSymbol.word.length() == astWordSymbol.pos.charEnd - astWordSymbol.pos.charStart)
    96             addAstNameStype(astWordSymbol, RfpSourceViewerConfiguration.getTextAttribute(IColorPreferences.SYMBOL));
     101            addAstNameStype(astWordSymbol, IColorPreferences.SYMBOL);
    97102    }
    98103
  • devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor/RfpEditor.java

    r3355 r3359  
    248248                ISourceViewer sourceViewer = getSourceViewer();
    249249                if (sourceViewer != null) {
    250                     rfpSourceViewerConfiguration.updatePresentationReconsiler(sourceViewer);
    251250                    sourceViewer.invalidateTextPresentation();
    252251                }
     
    261260        getPreferenceStore().removePropertyChangeListener(propertyChangeListener);
    262261        bracketMatcher.dispose();
    263         rfpSourceViewerConfiguration.dispose(sourceViewer);
    264262
    265263        editorCount--;
  • devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor/RfpReconcilingStrategy.java

    r3338 r3359  
    22
    33import org.eclipse.core.resources.IFile;
     4import org.eclipse.jface.preference.IPreferenceStore;
    45import org.eclipse.jface.text.IDocument;
    56import org.eclipse.jface.text.IRegion;
     
    1011
    1112public class RfpReconcilingStrategy implements IReconcilingStrategy {
    12     RfpEditor editor;
    13     IDocument document;
     13    private final RfpEditor editor;
     14    private final IPreferenceStore store;
     15    private IDocument document;
    1416
    15     public RfpReconcilingStrategy (RfpEditor editor) {
     17    public RfpReconcilingStrategy (RfpEditor editor, IPreferenceStore store) {
    1618        this.editor = editor;
     19        this.store = store;
    1720    }
    1821
     
    2427        this.editor.astImplem = astImplem;
    2528        if (astImplem != null)
    26             editor.changeTextPresentation(PresentationVisitor.updateTextPresentation(astImplem));
     29            editor.changeTextPresentation(PresentationVisitor.updateTextPresentation(astImplem, store));
    2730    }
    2831
  • devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor/RfpSourceViewerConfiguration.java

    r3356 r3359  
    11package org.refal.plus.rfpdt.editor;
    22
    3 import java.util.HashMap;
    4 import java.util.Map;
    5 
    63import org.eclipse.jface.preference.IPreferenceStore;
    7 import org.eclipse.jface.preference.PreferenceConverter;
    84import org.eclipse.jface.text.IAutoEditStrategy;
    95import org.eclipse.jface.text.IDocument;
    106import org.eclipse.jface.text.ITextDoubleClickStrategy;
    117import org.eclipse.jface.text.ITextHover;
    12 import org.eclipse.jface.text.TextAttribute;
    138import org.eclipse.jface.text.presentation.IPresentationReconciler;
    14 import org.eclipse.jface.text.presentation.PresentationReconciler;
    159import org.eclipse.jface.text.reconciler.IReconciler;
    1610import org.eclipse.jface.text.reconciler.MonoReconciler;
    17 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
    1811import org.eclipse.jface.text.source.IAnnotationHover;
    1912import org.eclipse.jface.text.source.ISourceViewer;
    20 import org.eclipse.swt.SWT;
    21 import org.eclipse.swt.graphics.Color;
    2213import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
    23 import org.refal.plus.rfpdt.editor.color.ColorScanner;
    24 import org.refal.plus.rfpdt.editor.color.IColorPreferences;
    2514import org.refal.plus.rfpdt.editor.preferences.IPreferenceConstants;
    2615
    2716public class RfpSourceViewerConfiguration extends TextSourceViewerConfiguration {
    28     private static final String[] defaultPrefixes = { "//" };
    29     private RfpDoubleClickStrategy doubleClickStrategy;
    30     private RfpAutoIndentStrategy autoIngentStrategy;
    31     private ColorScanner scanner;
    32     private Map<ISourceViewer, PresentationReconciler> reconcilers = new HashMap<ISourceViewer, PresentationReconciler>();
    33     private RfpEditor editor;
     17    private final RfpDoubleClickStrategy doubleClickStrategy;
     18    private final RfpAutoIndentStrategy autoIngentStrategy;
     19    private final RfpEditor editor;
    3420
    3521    public RfpSourceViewerConfiguration (RfpEditor rfpEditor, IPreferenceStore store) {
    3622        super(store);
     23        doubleClickStrategy = new RfpDoubleClickStrategy();
     24        autoIngentStrategy = new RfpAutoIndentStrategy(store);
    3725        editor = rfpEditor;
     26    }
     27
     28    public IAnnotationHover getAnnotationHover (ISourceViewer sourceViewer) {
     29        return new RfpAnnotationHover();
     30    }
     31
     32    public IAutoEditStrategy[] getAutoEditStrategies (ISourceViewer sourceViewer, String contentType) {
     33        return new IAutoEditStrategy[] { autoIngentStrategy };
    3834    }
    3935
     
    4339    }
    4440
     41    public String getConfiguredDocumentPartitioning (ISourceViewer sourceViewer) {
     42        return IRfpPartitions.PARTITIONING;
     43    }
     44
     45    public String[] getDefaultPrefixes (ISourceViewer sourceViewer, String contentType) {
     46        String[] defaultPrefixes = { "//" };
     47        return defaultPrefixes;
     48    }
     49
    4550    public ITextDoubleClickStrategy getDoubleClickStrategy (ISourceViewer sourceViewer, String contentType) {
    46         if (doubleClickStrategy == null)
    47             doubleClickStrategy = new RfpDoubleClickStrategy();
    4851        return doubleClickStrategy;
    4952    }
    5053
    51     public IAutoEditStrategy[] getAutoEditStrategies (ISourceViewer sourceViewer, String contentType) {
    52         if (autoIngentStrategy == null)
    53             autoIngentStrategy = new RfpAutoIndentStrategy(fPreferenceStore);
    54         return new IAutoEditStrategy[] { autoIngentStrategy };
     54    public IPresentationReconciler getPresentationReconciler (ISourceViewer sourceViewer) {
     55        return new RfpPresentationReconciler(getConfiguredDocumentPartitioning(sourceViewer), fPreferenceStore);
    5556    }
    5657
    57     private ColorScanner getColorScanner () {
    58         if (scanner == null) {
    59             scanner = new ColorScanner();
    60         }
    61         return scanner;
    62     }
    63 
    64     public static TextAttribute getTextAttribute (String key) {
    65         IPreferenceStore store = RfpEditorPlugin.getPluginPreferenceStore();
    66         Color color = RfpEditor.getColorManager().getColor(PreferenceConverter.getColor(store, IPreferenceConstants.PREFIX + key + ".color"));
    67         int style = store.getBoolean(IPreferenceConstants.PREFIX + key + ".bold") ? SWT.BOLD : SWT.NORMAL;
    68         if (store.getBoolean(IPreferenceConstants.PREFIX + key + ".italic"))
    69             style |= SWT.ITALIC;
    70         if (store.getBoolean(IPreferenceConstants.PREFIX + key + ".strikethrough"))
    71             style |= TextAttribute.STRIKETHROUGH;
    72         if (store.getBoolean(IPreferenceConstants.PREFIX + key + ".underlined"))
    73             style |= TextAttribute.UNDERLINE;
    74         return new TextAttribute(color, null, style);
    75     }
    76 
    77     public IPresentationReconciler getPresentationReconciler (ISourceViewer sourceViewer) {
    78         PresentationReconciler reconciler;
    79 
    80         if (reconcilers.containsKey(sourceViewer))
    81             reconciler = reconcilers.get(sourceViewer);
    82         else
    83             reconciler = new PresentationReconciler();
    84 
    85         reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
    86 
    87         DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getColorScanner());
    88         reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
    89         reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
    90 
    91         NonRuleBasedDamagerRepairer ndr = new NonRuleBasedDamagerRepairer(getTextAttribute(IColorPreferences.COMMENT));
    92         reconciler.setDamager(ndr, IRfpPartitions.MULTI_LINE_COMMENT);
    93         reconciler.setRepairer(ndr, IRfpPartitions.MULTI_LINE_COMMENT);
    94 
    95         ndr = new NonRuleBasedDamagerRepairer(getTextAttribute(IColorPreferences.COMMENT));
    96         reconciler.setDamager(ndr, IRfpPartitions.SINGLE_LINE_COMMENT);
    97         reconciler.setRepairer(ndr, IRfpPartitions.SINGLE_LINE_COMMENT);
    98 
    99         ndr = new NonRuleBasedDamagerRepairer(getTextAttribute(IColorPreferences.SYMBOL));
    100         reconciler.setDamager(ndr, IRfpPartitions.WORD);
    101         reconciler.setRepairer(ndr, IRfpPartitions.WORD);
    102 
    103         ndr = new NonRuleBasedDamagerRepairer(getTextAttribute(IColorPreferences.SYMBOL));
    104         reconciler.setDamager(ndr, IRfpPartitions.CHARACTER);
    105         reconciler.setRepairer(ndr, IRfpPartitions.CHARACTER);
    106 
    107         reconcilers.put(sourceViewer, reconciler);
    108         return reconciler;
    109     }
    110 
    111     public void updatePresentationReconsiler (ISourceViewer sourceViewer) {
    112         scanner.setTokens();
    113         IPresentationReconciler reconciler = reconcilers.get(sourceViewer);
    114         ((NonRuleBasedDamagerRepairer) reconciler.getRepairer(IRfpPartitions.MULTI_LINE_COMMENT))
    115                 .setDefaultTextAttribute(getTextAttribute(IColorPreferences.COMMENT));
    116         ((NonRuleBasedDamagerRepairer) reconciler.getRepairer(IRfpPartitions.SINGLE_LINE_COMMENT))
    117                 .setDefaultTextAttribute(getTextAttribute(IColorPreferences.COMMENT));
    118         ((NonRuleBasedDamagerRepairer) reconciler.getRepairer(IRfpPartitions.WORD))
    119                 .setDefaultTextAttribute(getTextAttribute(IColorPreferences.SYMBOL));
    120         ((NonRuleBasedDamagerRepairer) reconciler.getRepairer(IRfpPartitions.CHARACTER))
    121                 .setDefaultTextAttribute(getTextAttribute(IColorPreferences.SYMBOL));
    122     }
    123    
    124     public IReconciler getReconciler(ISourceViewer sourceViewer) {
     58    public IReconciler getReconciler (ISourceViewer sourceViewer) {
    12559        if (editor != null && editor.isEditable())
    126             return new MonoReconciler(new RfpReconcilingStrategy(editor), false);
     60            return new MonoReconciler(new RfpReconcilingStrategy(editor, fPreferenceStore), false);
    12761        return null;
    128     }
    129 
    130 
    131     public void dispose (ISourceViewer sourceViewer) {
    132         reconcilers.remove(sourceViewer);
    133     }
    134 
    135     public ITextHover getTextHover (ISourceViewer sourceViewer, String contentType) {
    136         return new RfpTextHover(sourceViewer);
    137     }
    138 
    139     public IAnnotationHover getAnnotationHover (ISourceViewer sourceViewer) {
    140         return new RfpAnnotationHover();
    141     }
    142 
    143     public String[] getDefaultPrefixes (ISourceViewer sourceViewer, String contentType) {
    144         return defaultPrefixes;
    14562    }
    14663
     
    14966    }
    15067
    151     /*
    152      * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
    153      * @since 3.0
    154      */
    155     public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
    156         return IRfpPartitions.PARTITIONING;
     68    public ITextHover getTextHover (ISourceViewer sourceViewer, String contentType) {
     69        return new RfpTextHover(sourceViewer);
    15770    }
    158 
    15971}
  • devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor/color/ColorScanner.java

    r3355 r3359  
    33import java.util.ArrayList;
    44
     5import org.eclipse.jface.preference.IPreferenceStore;
     6import org.eclipse.jface.preference.PreferenceConverter;
    57import org.eclipse.jface.text.BadLocationException;
    68import org.eclipse.jface.text.IDocument;
     9import org.eclipse.jface.text.TextAttribute;
    710import org.eclipse.jface.text.rules.IRule;
    811import org.eclipse.jface.text.rules.IToken;
     
    1215import org.eclipse.jface.text.rules.WhitespaceRule;
    1316import org.eclipse.jface.text.rules.WordRule;
    14 import org.refal.plus.rfpdt.editor.RfpSourceViewerConfiguration;
     17import org.eclipse.swt.SWT;
     18import org.eclipse.swt.graphics.Color;
     19import org.refal.plus.rfpdt.editor.RfpEditor;
     20import org.refal.plus.rfpdt.editor.preferences.IPreferenceConstants;
    1521
    1622public class ColorScanner implements ITokenScanner {
     
    2733    }
    2834
     35    public static TextAttribute getTextAttribute (IPreferenceStore store, String key) {
     36        Color color = RfpEditor.getColorManager().getColor(
     37                PreferenceConverter.getColor(store, IPreferenceConstants.PREFIX + key + ".color"));
     38        int style = store.getBoolean(IPreferenceConstants.PREFIX + key + ".bold") ? SWT.BOLD : SWT.NORMAL;
     39        if (store.getBoolean(IPreferenceConstants.PREFIX + key + ".italic"))
     40            style |= SWT.ITALIC;
     41        if (store.getBoolean(IPreferenceConstants.PREFIX + key + ".strikethrough"))
     42            style |= TextAttribute.STRIKETHROUGH;
     43        if (store.getBoolean(IPreferenceConstants.PREFIX + key + ".underlined"))
     44            style |= TextAttribute.UNDERLINE;
     45        return new TextAttribute(color, null, style);
     46    }
     47
     48    private final IPreferenceStore store;
    2949    private final RuleBasedScanner scanner;
     50    private final ArrayList<TokenWrapper> tokens;
    3051    private IDocument document = null;
    31     private final ArrayList<TokenWrapper> tokens;
    3252    private IToken symbol = null;
    3353    private IToken keyword = null;
     
    3757    private IToken other = null;
    3858
     59    public ColorScanner (IPreferenceStore store) {
     60        this.store = store;
     61        scanner = new RuleBasedScanner();
     62        tokens = new ArrayList<TokenWrapper>(3);
     63        setTokens();
     64    }
     65
    3966    public void setTokens () {
    40         symbol = new Token(RfpSourceViewerConfiguration.getTextAttribute(IColorPreferences.SYMBOL));
    41         keyword = new Token(RfpSourceViewerConfiguration.getTextAttribute(IColorPreferences.KEYWORD));
    42         identifier = new Token(RfpSourceViewerConfiguration.getTextAttribute(IColorPreferences.IDENTIFIER_USE));
    43         variable_type = new Token(RfpSourceViewerConfiguration.getTextAttribute(IColorPreferences.VARIABLE_TYPE));
    44         variable = new Token(RfpSourceViewerConfiguration.getTextAttribute(IColorPreferences.VARIABLE_USE));
    45         other = new Token(RfpSourceViewerConfiguration.getTextAttribute(IColorPreferences.OTHER_SYMBOLS));
     67        symbol = new Token(getTextAttribute(store, IColorPreferences.SYMBOL));
     68        keyword = new Token(getTextAttribute(store, IColorPreferences.KEYWORD));
     69        identifier = new Token(getTextAttribute(store, IColorPreferences.IDENTIFIER_USE));
     70        variable_type = new Token(getTextAttribute(store, IColorPreferences.VARIABLE_TYPE));
     71        variable = new Token(getTextAttribute(store, IColorPreferences.VARIABLE_USE));
     72        other = new Token(getTextAttribute(store, IColorPreferences.OTHER_SYMBOLS));
    4673        ArrayList<IRule> rules = new ArrayList<IRule>();
    4774        rules.add(new WhitespaceRule(new WhitespaceDetector()));
     
    5784        scanner.setRules(rules.toArray(new IRule[0]));
    5885        scanner.setDefaultReturnToken(other);
    59     }
    60 
    61     public ColorScanner () {
    62         scanner = new RuleBasedScanner();
    63         tokens = new ArrayList<TokenWrapper>(3);
    64         setTokens();
    6586    }
    6687
Note: See TracChangeset for help on using the changeset viewer.