Changeset 3365 for devel-tools/trunk


Ignore:
Timestamp:
Feb 5, 2008, 12:06:21 AM (13 years ago)
Author:
yura
Message:
  • Annotation is position in document!
Location:
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor
Files:
3 edited

Legend:

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

    r3359 r3365  
    44
    55import org.eclipse.jface.preference.IPreferenceStore;
     6import org.eclipse.jface.text.Position;
    67import org.eclipse.jface.text.TextAttribute;
    78import org.eclipse.swt.SWT;
     
    5051
    5152public class PresentationVisitor implements ProgramVisitor, SentenceVisitor, ExpVisitor {
    52     public static StyleRange[] updateTextPresentation (AstImplem astImplem, IPreferenceStore store) {
     53    public static class StylePosition extends Position {
     54        private final TextAttribute textAttribute;
     55
     56        public StylePosition (SrcPosition pos, TextAttribute textAttribute) {
     57            super(pos.charStart, pos.charEnd - pos.charStart);
     58            this.textAttribute = textAttribute;
     59        }
     60
     61        public StyleRange getStyleRange () {
     62            StyleRange range = new StyleRange(offset, length, textAttribute.getForeground(), textAttribute
     63                    .getBackground());
     64            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;
     69        }
     70    }
     71
     72    public static StylePosition[] updateTextPresentation (AstImplem astImplem, IPreferenceStore store) {
    5373        PresentationVisitor presentationVisitor = new PresentationVisitor(store);
    5474        astImplem.accept(presentationVisitor);
    55         return presentationVisitor.styleRangeList.toArray(new StyleRange[presentationVisitor.styleRangeList.size()]);
    56     }
    57 
    58     private final ArrayList<StyleRange> styleRangeList;
     75        return presentationVisitor.styleRangeList.toArray(new StylePosition[presentationVisitor.styleRangeList.size()]);
     76    }
     77
     78    private final ArrayList<StylePosition> styleRangeList;
    5979    private final IPreferenceStore store;
    6080
    6181    private void addAstNameStype (AstNode name, String key) {
    62         if (name == null)
     82        if (name == null || name.pos.rfpResource.isInterface) // TODO - must be RfpResource
    6383            return;
    64         SrcPosition pos = name.pos;
    65         if (pos.rfpResource.isInterface) // TODO - must be RfpResource
    66             return;
    67         TextAttribute textAttribute = ColorScanner.getTextAttribute(store, key);
    68         int style = textAttribute.getStyle();
    69         StyleRange range = new StyleRange(pos.charStart, pos.charEnd - pos.charStart, textAttribute.getForeground(),
    70                 textAttribute.getBackground());
    71         range.fontStyle = style & (SWT.BOLD | SWT.ITALIC);
    72         range.strikeout = (style & TextAttribute.STRIKETHROUGH) == TextAttribute.STRIKETHROUGH;
    73         range.underline = (style & TextAttribute.UNDERLINE) == TextAttribute.STRIKETHROUGH;
    74         styleRangeList.add(range);
     84        styleRangeList.add(new StylePosition(name.pos, ColorScanner.getTextAttribute(store, key)));
    7585    }
    7686
    7787    private PresentationVisitor (IPreferenceStore store) {
    78         this.styleRangeList = new ArrayList<StyleRange>();
     88        this.styleRangeList = new ArrayList<StylePosition>();
    7989        this.store = store;
    8090    }
     
    94104
    95105    private void visitVariableUse (AstName name) {
    96     // addAstNameStype(name, IColorPreferences.VARIABLE_USE);
     106        // addAstNameStype(name, IColorPreferences.VARIABLE_USE);
    97107    }
    98108
  • devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor/RfpEditor.java

    r3362 r3365  
    77import org.eclipse.jface.action.Action;
    88import org.eclipse.jface.preference.IPreferenceStore;
     9import org.eclipse.jface.text.BadLocationException;
     10import org.eclipse.jface.text.IDocument;
    911import org.eclipse.jface.text.IRegion;
    1012import org.eclipse.jface.text.ISynchronizable;
     
    2426import org.eclipse.jface.viewers.ISelectionChangedListener;
    2527import org.eclipse.jface.viewers.SelectionChangedEvent;
    26 import org.eclipse.swt.custom.StyleRange;
    2728import org.eclipse.swt.custom.StyledText;
    2829import org.eclipse.swt.widgets.Composite;
    2930import org.eclipse.swt.widgets.Display;
    30 import org.eclipse.swt.widgets.Shell;
    3131import org.eclipse.ui.IEditorInput;
    3232import org.eclipse.ui.IFileEditorInput;
    33 import org.eclipse.ui.IWorkbenchPartSite;
    3433import org.eclipse.ui.editors.text.EditorsUI;
    3534import org.eclipse.ui.editors.text.TextEditor;
     
    4645import org.refal.plus.rfpdt.comp.ast.AstRef;
    4746import org.refal.plus.rfpdt.comp.ast.AstVar;
     47import org.refal.plus.rfpdt.editor.PresentationVisitor.StylePosition;
    4848import org.refal.plus.rfpdt.editor.color.ColorManager;
    4949import org.refal.plus.rfpdt.editor.preferences.IPreferenceConstants;
     
    178178    }
    179179
    180     private StyleRange[] styleRangeList = null;
    181 
    182     public void changeTextPresentation (StyleRange[] styleRangeList) {
    183         this.styleRangeList = styleRangeList;
    184         Runnable runnable = new Runnable() {
    185             public void run () {
    186                 getSourceViewer().invalidateTextPresentation();
    187             }
    188         };
    189         if (runnable == null)
    190             return;
    191         IWorkbenchPartSite site = this.getSite();
    192         if (site == null)
    193             return;
    194         Shell shell = site.getShell();
    195         if (shell == null || shell.isDisposed())
    196             return;
    197         Display display = shell.getDisplay();
    198         if (display == null || display.isDisposed())
    199             return;
    200         display.asyncExec(runnable);
     180    private StylePosition[] stylePositionList = null;
     181
     182    public void changeTextPresentation (IDocument document, StylePosition[] stylePositionList) {
     183        if (this.stylePositionList != null)
     184            for (Position position : stylePositionList)
     185                document.removePosition(position);
     186        this.stylePositionList = stylePositionList;
     187        if (this.stylePositionList != null)
     188            for (Position position : stylePositionList)
     189                try {
     190                    document.addPosition(position);
     191                } catch (BadLocationException e) {}
     192        redrawTextAsync();
    201193    }
    202194
     
    205197            public void run () {
    206198                ISourceViewer sourceViewer = getSourceViewer();
    207                 if (sourceViewer != null) {
     199                if (sourceViewer != null)
    208200                    sourceViewer.invalidateTextPresentation();
    209                 }
    210201            }
    211202        });
     203        //Runnable runnable = new Runnable() {
     204        //    public void run () {
     205        //        getSourceViewer().invalidateTextPresentation();
     206        //    }
     207        //};
     208        //if (runnable == null)
     209        //    return;
     210        //IWorkbenchPartSite site = this.getSite();
     211        //if (site == null)
     212        //    return;
     213        //Shell shell = site.getShell();
     214        //if (shell == null || shell.isDisposed())
     215        //    return;
     216        //Display display = shell.getDisplay();
     217        //if (display == null || display.isDisposed())
     218        //    return;
     219        //display.asyncExec(runnable);
    212220    }
    213221
     
    280288            ((ITextViewerExtension4) sourceViewer).addTextPresentationListener(new ITextPresentationListener() {
    281289                public void applyTextPresentation (TextPresentation presentation) {
    282                     if (styleRangeList == null)
     290                    if (stylePositionList == null)
    283291                        return;
    284292                    IRegion reg = presentation.getCoverage();
    285                     for (StyleRange sr : styleRangeList) {
    286                         if (reg.getOffset() <= sr.start && sr.start + sr.length <= reg.getOffset() + reg.getLength())
    287                             presentation.mergeStyleRange((StyleRange) sr.clone());
    288                     }
     293                    for (StylePosition stylePosition : stylePositionList)
     294                        if (reg.getOffset() <= stylePosition.getOffset()
     295                                && stylePosition.getOffset() + stylePosition.getLength() <= reg.getOffset()
     296                                        + reg.getLength())
     297                            presentation.mergeStyleRange(stylePosition.getStyleRange());
    289298                }
    290299            });
  • devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor/RfpReconcilingStrategy.java

    r3359 r3365  
    2727        this.editor.astImplem = astImplem;
    2828        if (astImplem != null)
    29             editor.changeTextPresentation(PresentationVisitor.updateTextPresentation(astImplem, store));
     29            editor.changeTextPresentation(document, PresentationVisitor.updateTextPresentation(astImplem, store));
    3030    }
    3131
    3232    public void reconcile (DirtyRegion dirtyRegion, IRegion subRegion) {
    33         reconcile(subRegion);
     33        reconcile(null);
    3434    }
    3535
Note: See TracChangeset for help on using the changeset viewer.