]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/winterwell.markdown/src/winterwell/markdown/editors/MDConfiguration.java
migrated to svn revision 33108
[simantics/platform.git] / bundles / winterwell.markdown / src / winterwell / markdown / editors / MDConfiguration.java
1 package winterwell.markdown.editors;
2
3 import org.eclipse.core.runtime.NullProgressMonitor;
4 import org.eclipse.jface.preference.IPreferenceStore;
5 import org.eclipse.jface.text.IDocument;
6 import org.eclipse.jface.text.IRegion;
7 import org.eclipse.jface.text.ITextHover;
8 import org.eclipse.jface.text.presentation.IPresentationReconciler;
9 import org.eclipse.jface.text.presentation.PresentationReconciler;
10 import org.eclipse.jface.text.reconciler.DirtyRegion;
11 import org.eclipse.jface.text.reconciler.IReconciler;
12 import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
13 import org.eclipse.jface.text.reconciler.MonoReconciler;
14 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
15 import org.eclipse.jface.text.source.ISourceViewer;
16 import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
17
18 public class MDConfiguration extends TextSourceViewerConfiguration {
19         private ColorManager colorManager;
20
21         public MDConfiguration(ColorManager colorManager, IPreferenceStore prefStore) {
22                 super(prefStore);
23                 this.colorManager = colorManager;
24         }
25
26         @Override
27         public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
28                 MDScanner scanner = new MDScanner(colorManager);
29                 PresentationReconciler pr = (PresentationReconciler) super.getPresentationReconciler(sourceViewer); // FIXME
30                 DefaultDamagerRepairer ddr = new DefaultDamagerRepairer(scanner);
31                 pr.setRepairer(ddr, IDocument.DEFAULT_CONTENT_TYPE);
32                 pr.setDamager(ddr, IDocument.DEFAULT_CONTENT_TYPE);
33                 return pr;
34         }
35
36         
37         @Override
38         public IReconciler getReconciler(ISourceViewer sourceViewer) {
39                 // This awful mess adds in update support
40                 // Get super strategy
41                 IReconciler rs = super.getReconciler(sourceViewer);
42                 if (true) return rs;    // Seems to work fine?!
43                 final IReconcilingStrategy fsuperStrategy = rs==null? null : rs.getReconcilingStrategy("text");
44                 // Add our own
45                 IReconcilingStrategy strategy = new IReconcilingStrategy() {
46                         private IDocument doc;
47                         public void reconcile(IRegion partition) {
48                                 MarkdownEditor ed = MarkdownEditor.getEditor(doc);
49                                 if (ed != null) ed.updatePage(partition);
50                                 if (fsuperStrategy!=null) fsuperStrategy.reconcile(partition);
51                         }
52                         public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
53                                 MarkdownEditor ed = MarkdownEditor.getEditor(doc);
54                                 if (ed != null) ed.updatePage(subRegion);
55                                 if (fsuperStrategy!=null) fsuperStrategy.reconcile(dirtyRegion, subRegion);
56                         }
57                         public void setDocument(IDocument document) {
58                                 this.doc = document;
59                                 if (fsuperStrategy!=null) fsuperStrategy.setDocument(document);
60                         }                       
61                 };
62                 // Make a reconciler
63                 MonoReconciler m2 = new MonoReconciler(strategy, true);
64                 m2.setIsIncrementalReconciler(true);
65                 m2.setProgressMonitor(new NullProgressMonitor());
66                 m2.setDelay(500);
67                 // Done
68                 return m2;
69         }
70         
71         @SuppressWarnings("unused")
72         @Override
73         public ITextHover getTextHover(ISourceViewer sourceViewer,
74                         String contentType) {
75                 if (true) return super.getTextHover(sourceViewer, contentType);
76                 // Add hover support for images
77                 return new MDTextHover();
78         }
79 }
80
81