Changeset 3382 for devel-tools/trunk


Ignore:
Timestamp:
Feb 6, 2008, 6:09:19 PM (13 years ago)
Author:
yura
Message:
  • Update style ranges when preference store is changed.
Location:
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor
Files:
4 edited

Legend:

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

    r3365 r3382  
    88import org.eclipse.swt.SWT;
    99import org.eclipse.swt.custom.StyleRange;
     10import org.refal.plus.rfpdt.comp.RfpResource;
    1011import org.refal.plus.rfpdt.comp.SrcPosition;
    1112import org.refal.plus.rfpdt.comp.ast.AstAlt;
     
    5253public class PresentationVisitor implements ProgramVisitor, SentenceVisitor, ExpVisitor {
    5354    public static class StylePosition extends Position {
    54         private final TextAttribute textAttribute;
    55 
    56         public StylePosition (SrcPosition pos, TextAttribute textAttribute) {
     55        private final String key;
     56        private TextAttribute textAttribute = null;
     57
     58        public StylePosition (SrcPosition pos, String key) {
    5759            super(pos.charStart, pos.charEnd - pos.charStart);
    58             this.textAttribute = textAttribute;
     60            this.key = key;
    5961        }
    6062
     63        public void updateStyleRange (IPreferenceStore store) {
     64            textAttribute = ColorScanner.getTextAttribute(store, key);
     65        }
     66
    6167        public StyleRange getStyleRange () {
    62             StyleRange range = new StyleRange(offset, length, textAttribute.getForeground(), textAttribute
    63                     .getBackground());
     68            StyleRange styleRange = new StyleRange(offset, length, textAttribute.getForeground(), textAttribute.getBackground());
    6469            int style = textAttribute.getStyle();
    65             range.fontStyle = style & (SWT.BOLD | SWT.ITALIC);
    66             range.strikeout = (style & TextAttribute.STRIKETHROUGH) == TextAttribute.STRIKETHROUGH;
    67             range.underline = (style & TextAttribute.UNDERLINE) == TextAttribute.STRIKETHROUGH;
    68             return range;
     70            styleRange.fontStyle = style & (SWT.BOLD | SWT.ITALIC);
     71            styleRange.strikeout = (style & TextAttribute.STRIKETHROUGH) == TextAttribute.STRIKETHROUGH;
     72            styleRange.underline = (style & TextAttribute.UNDERLINE) == TextAttribute.STRIKETHROUGH;
     73            return styleRange;
    6974        }
    7075    }
    7176
    72     public static StylePosition[] updateTextPresentation (AstImplem astImplem, IPreferenceStore store) {
    73         PresentationVisitor presentationVisitor = new PresentationVisitor(store);
     77    public static StylePosition[] updateTextPresentation (AstImplem astImplem) {
     78        PresentationVisitor presentationVisitor = new PresentationVisitor(astImplem.pos.rfpResource);
    7479        astImplem.accept(presentationVisitor);
    7580        return presentationVisitor.styleRangeList.toArray(new StylePosition[presentationVisitor.styleRangeList.size()]);
     
    7782
    7883    private final ArrayList<StylePosition> styleRangeList;
    79     private final IPreferenceStore store;
    80 
    81     private void addAstNameStype (AstNode name, String key) {
    82         if (name == null || name.pos.rfpResource.isInterface) // TODO - must be RfpResource
     84    private final RfpResource rfpResource;
     85
     86    private void addAstNameStyle (AstNode name, String key) {
     87        if (! rfpResource.equals(name.pos.rfpResource))
    8388            return;
    84         styleRangeList.add(new StylePosition(name.pos, ColorScanner.getTextAttribute(store, key)));
    85     }
    86 
    87     private PresentationVisitor (IPreferenceStore store) {
     89        styleRangeList.add(new StylePosition(name.pos, key));
     90    }
     91
     92    private PresentationVisitor (RfpResource rfpResource) {
    8893        this.styleRangeList = new ArrayList<StylePosition>();
    89         this.store = store;
     94        this.rfpResource = rfpResource;
    9095    }
    9196
    9297    private void visitObjectDefinition (AstName name) {
    93         addAstNameStype(name, IColorPreferences.IDENTIFIER_DEFINITION);
     98        if (name != null)
     99            addAstNameStyle(name, IColorPreferences.IDENTIFIER_DEFINITION);
    94100    }
    95101
    96102    private void visitObjectUse (AstName name) {
    97103        if (name != null && name.identifier.length() < name.pos.charEnd - name.pos.charStart)
    98             addAstNameStype(name, IColorPreferences.IDENTIFIER_USE);
     104            addAstNameStyle(name, IColorPreferences.IDENTIFIER_USE);
    99105    }
    100106
    101107    private void visitVariableDefinition (AstName name) {
    102         addAstNameStype(name, IColorPreferences.VARIABLE_DEFINITION);
     108        if (name != null)
     109            addAstNameStyle(name, IColorPreferences.VARIABLE_DEFINITION);
    103110    }
    104111
    105112    private void visitVariableUse (AstName name) {
    106         // addAstNameStype(name, IColorPreferences.VARIABLE_USE);
     113    // addAstNameStype(name, IColorPreferences.VARIABLE_USE);
    107114    }
    108115
    109116    private void visitSymbol (AstWordSymbol astWordSymbol) {
    110117        if (astWordSymbol.word.length() == astWordSymbol.pos.charEnd - astWordSymbol.pos.charStart)
    111             addAstNameStype(astWordSymbol, IColorPreferences.SYMBOL);
     118            addAstNameStyle(astWordSymbol, IColorPreferences.SYMBOL);
    112119    }
    113120
  • devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor/RfpEditor.java

    r3372 r3382  
    145145    private IPropertyChangeListener propertyChangeListener;
    146146    private RfpSourceViewerConfiguration rfpSourceViewerConfiguration;
     147    private  IPreferenceStore store;
    147148
    148149    RfpReconcilingStrategy rfpReconcilingStrategy = null;
     
    167168        stores.add(RfpEditorPlugin.getPluginPreferenceStore());
    168169        stores.add(EditorsUI.getPreferenceStore());
    169         IPreferenceStore store = new ChainedPreferenceStore(stores.toArray(new IPreferenceStore[stores.size()]));
     170        store = new ChainedPreferenceStore(stores.toArray(new IPreferenceStore[stores.size()]));
    170171        setPreferenceStore(store);
    171172
     
    177178        propertyChangeListener = new IPropertyChangeListener() {
    178179            public void propertyChange (PropertyChangeEvent event) {
     180                for (StylePosition position : stylePositionList)
     181                    position.updateStyleRange(store);
    179182                redrawTextAsync();
    180183            }
     
    187190    public void changeTextPresentation (IDocument document, StylePosition[] stylePositionList) {
    188191        if (this.stylePositionList != null)
    189             for (Position position : stylePositionList)
     192            for (Position position : this.stylePositionList)
    190193                document.removePosition(position);
     194        for (StylePosition position : stylePositionList)
     195            position.updateStyleRange(store);
    191196        this.stylePositionList = stylePositionList;
    192197        if (this.stylePositionList != null)
    193             for (Position position : stylePositionList)
     198            for (StylePosition position : this.stylePositionList)
    194199                try {
    195200                    document.addPosition(position);
  • devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor/RfpReconcilingStrategy.java

    r3380 r3382  
    22
    33import org.eclipse.core.resources.IFile;
    4 import org.eclipse.jface.preference.IPreferenceStore;
    54import org.eclipse.jface.text.DocumentEvent;
    65import org.eclipse.jface.text.IDocument;
     
    1413public class RfpReconcilingStrategy implements IReconcilingStrategy, IDocumentListener {
    1514    private final RfpEditor editor;
    16     private final IPreferenceStore store;
    1715    private IDocument document = null;
    1816    private AstImplem astImplem = null;
     
    2927    }
    3028
    31     public RfpReconcilingStrategy (RfpEditor editor, IPreferenceStore store) {
     29    public RfpReconcilingStrategy (RfpEditor editor) {
    3230        this.editor = editor;
    33         this.store = store;
    3431        editor.rfpReconcilingStrategy = this;
    3532    }
     
    4441        updateAstImplem();
    4542        if (astImplem != null)
    46             editor.changeTextPresentation(document, PresentationVisitor.updateTextPresentation(astImplem, store));
     43            editor.changeTextPresentation(document, PresentationVisitor.updateTextPresentation(astImplem));
    4744    }
    4845
  • devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor/RfpSourceViewerConfiguration.java

    r3381 r3382  
    8181    public IReconciler getReconciler (ISourceViewer sourceViewer) {
    8282        if (editor != null && editor.isEditable())
    83             return new MonoReconciler(new RfpReconcilingStrategy(editor, fPreferenceStore), false);
     83            return new MonoReconciler(new RfpReconcilingStrategy(editor), false);
    8484        return null;
    8585    }
Note: See TracChangeset for help on using the changeset viewer.