Changeset 3359 for devel-tools/trunk
- Timestamp:
- Feb 4, 2008, 10:32:33 PM (13 years ago)
- 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 3 3 import java.util.ArrayList; 4 4 5 import org.eclipse.jface.preference.IPreferenceStore; 5 6 import org.eclipse.jface.text.TextAttribute; 6 7 import org.eclipse.swt.SWT; … … 45 46 import org.refal.plus.rfpdt.comp.ast.ProgramVisitor; 46 47 import org.refal.plus.rfpdt.comp.ast.SentenceVisitor; 48 import org.refal.plus.rfpdt.editor.color.ColorScanner; 47 49 import org.refal.plus.rfpdt.editor.color.IColorPreferences; 48 50 49 51 public 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); 52 54 astImplem.accept(presentationVisitor); 53 55 return presentationVisitor.styleRangeList.toArray(new StyleRange[presentationVisitor.styleRangeList.size()]); … … 55 57 56 58 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) { 59 62 if (name == null) 60 63 return; … … 62 65 if (pos.rfpResource.isInterface) // TODO - must be RfpResource 63 66 return; 67 TextAttribute textAttribute = ColorScanner.getTextAttribute(store, key); 64 68 int style = textAttribute.getStyle(); 65 69 StyleRange range = new StyleRange(pos.charStart, pos.charEnd - pos.charStart, textAttribute.getForeground(), … … 71 75 } 72 76 73 private PresentationVisitor ( ) {77 private PresentationVisitor (IPreferenceStore store) { 74 78 this.styleRangeList = new ArrayList<StyleRange>(); 79 this.store = store; 75 80 } 76 81 77 82 private void visitObjectDefinition (AstName name) { 78 addAstNameStype(name, RfpSourceViewerConfiguration.getTextAttribute(IColorPreferences.IDENTIFIER_DEFINITION));83 addAstNameStype(name, IColorPreferences.IDENTIFIER_DEFINITION); 79 84 } 80 85 81 86 private void visitObjectUse (AstName name) { 82 87 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); 84 89 } 85 90 86 91 private void visitVariableDefinition (AstName name) { 87 addAstNameStype(name, RfpSourceViewerConfiguration.getTextAttribute(IColorPreferences.VARIABLE_DEFINITION));92 addAstNameStype(name, IColorPreferences.VARIABLE_DEFINITION); 88 93 } 89 94 90 95 private void visitVariableUse (AstName name) { 91 // addAstNameStype(name, RfpSourceViewerConfiguration.getTextAttribute(IColorPreferences.VARIABLE_USE));96 // addAstNameStype(name, IColorPreferences.VARIABLE_USE); 92 97 } 93 98 94 99 private void visitSymbol (AstWordSymbol astWordSymbol) { 95 100 if (astWordSymbol.word.length() == astWordSymbol.pos.charEnd - astWordSymbol.pos.charStart) 96 addAstNameStype(astWordSymbol, RfpSourceViewerConfiguration.getTextAttribute(IColorPreferences.SYMBOL));101 addAstNameStype(astWordSymbol, IColorPreferences.SYMBOL); 97 102 } 98 103 -
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor/RfpEditor.java
r3355 r3359 248 248 ISourceViewer sourceViewer = getSourceViewer(); 249 249 if (sourceViewer != null) { 250 rfpSourceViewerConfiguration.updatePresentationReconsiler(sourceViewer);251 250 sourceViewer.invalidateTextPresentation(); 252 251 } … … 261 260 getPreferenceStore().removePropertyChangeListener(propertyChangeListener); 262 261 bracketMatcher.dispose(); 263 rfpSourceViewerConfiguration.dispose(sourceViewer);264 262 265 263 editorCount--; -
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor/RfpReconcilingStrategy.java
r3338 r3359 2 2 3 3 import org.eclipse.core.resources.IFile; 4 import org.eclipse.jface.preference.IPreferenceStore; 4 5 import org.eclipse.jface.text.IDocument; 5 6 import org.eclipse.jface.text.IRegion; … … 10 11 11 12 public class RfpReconcilingStrategy implements IReconcilingStrategy { 12 RfpEditor editor; 13 IDocument document; 13 private final RfpEditor editor; 14 private final IPreferenceStore store; 15 private IDocument document; 14 16 15 public RfpReconcilingStrategy (RfpEditor editor ) {17 public RfpReconcilingStrategy (RfpEditor editor, IPreferenceStore store) { 16 18 this.editor = editor; 19 this.store = store; 17 20 } 18 21 … … 24 27 this.editor.astImplem = astImplem; 25 28 if (astImplem != null) 26 editor.changeTextPresentation(PresentationVisitor.updateTextPresentation(astImplem ));29 editor.changeTextPresentation(PresentationVisitor.updateTextPresentation(astImplem, store)); 27 30 } 28 31 -
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor/RfpSourceViewerConfiguration.java
r3356 r3359 1 1 package org.refal.plus.rfpdt.editor; 2 2 3 import java.util.HashMap;4 import java.util.Map;5 6 3 import org.eclipse.jface.preference.IPreferenceStore; 7 import org.eclipse.jface.preference.PreferenceConverter;8 4 import org.eclipse.jface.text.IAutoEditStrategy; 9 5 import org.eclipse.jface.text.IDocument; 10 6 import org.eclipse.jface.text.ITextDoubleClickStrategy; 11 7 import org.eclipse.jface.text.ITextHover; 12 import org.eclipse.jface.text.TextAttribute;13 8 import org.eclipse.jface.text.presentation.IPresentationReconciler; 14 import org.eclipse.jface.text.presentation.PresentationReconciler;15 9 import org.eclipse.jface.text.reconciler.IReconciler; 16 10 import org.eclipse.jface.text.reconciler.MonoReconciler; 17 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;18 11 import org.eclipse.jface.text.source.IAnnotationHover; 19 12 import org.eclipse.jface.text.source.ISourceViewer; 20 import org.eclipse.swt.SWT;21 import org.eclipse.swt.graphics.Color;22 13 import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; 23 import org.refal.plus.rfpdt.editor.color.ColorScanner;24 import org.refal.plus.rfpdt.editor.color.IColorPreferences;25 14 import org.refal.plus.rfpdt.editor.preferences.IPreferenceConstants; 26 15 27 16 public 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; 34 20 35 21 public RfpSourceViewerConfiguration (RfpEditor rfpEditor, IPreferenceStore store) { 36 22 super(store); 23 doubleClickStrategy = new RfpDoubleClickStrategy(); 24 autoIngentStrategy = new RfpAutoIndentStrategy(store); 37 25 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 }; 38 34 } 39 35 … … 43 39 } 44 40 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 45 50 public ITextDoubleClickStrategy getDoubleClickStrategy (ISourceViewer sourceViewer, String contentType) { 46 if (doubleClickStrategy == null)47 doubleClickStrategy = new RfpDoubleClickStrategy();48 51 return doubleClickStrategy; 49 52 } 50 53 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); 55 56 } 56 57 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) { 125 59 if (editor != null && editor.isEditable()) 126 return new MonoReconciler(new RfpReconcilingStrategy(editor ), false);60 return new MonoReconciler(new RfpReconcilingStrategy(editor, fPreferenceStore), false); 127 61 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;145 62 } 146 63 … … 149 66 } 150 67 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); 157 70 } 158 159 71 } -
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.editor/src/org/refal/plus/rfpdt/editor/color/ColorScanner.java
r3355 r3359 3 3 import java.util.ArrayList; 4 4 5 import org.eclipse.jface.preference.IPreferenceStore; 6 import org.eclipse.jface.preference.PreferenceConverter; 5 7 import org.eclipse.jface.text.BadLocationException; 6 8 import org.eclipse.jface.text.IDocument; 9 import org.eclipse.jface.text.TextAttribute; 7 10 import org.eclipse.jface.text.rules.IRule; 8 11 import org.eclipse.jface.text.rules.IToken; … … 12 15 import org.eclipse.jface.text.rules.WhitespaceRule; 13 16 import org.eclipse.jface.text.rules.WordRule; 14 import org.refal.plus.rfpdt.editor.RfpSourceViewerConfiguration; 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.graphics.Color; 19 import org.refal.plus.rfpdt.editor.RfpEditor; 20 import org.refal.plus.rfpdt.editor.preferences.IPreferenceConstants; 15 21 16 22 public class ColorScanner implements ITokenScanner { … … 27 33 } 28 34 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; 29 49 private final RuleBasedScanner scanner; 50 private final ArrayList<TokenWrapper> tokens; 30 51 private IDocument document = null; 31 private final ArrayList<TokenWrapper> tokens;32 52 private IToken symbol = null; 33 53 private IToken keyword = null; … … 37 57 private IToken other = null; 38 58 59 public ColorScanner (IPreferenceStore store) { 60 this.store = store; 61 scanner = new RuleBasedScanner(); 62 tokens = new ArrayList<TokenWrapper>(3); 63 setTokens(); 64 } 65 39 66 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)); 46 73 ArrayList<IRule> rules = new ArrayList<IRule>(); 47 74 rules.add(new WhitespaceRule(new WhitespaceDetector())); … … 57 84 scanner.setRules(rules.toArray(new IRule[0])); 58 85 scanner.setDefaultReturnToken(other); 59 }60 61 public ColorScanner () {62 scanner = new RuleBasedScanner();63 tokens = new ArrayList<TokenWrapper>(3);64 setTokens();65 86 } 66 87
Note: See TracChangeset
for help on using the changeset viewer.