1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Patch for Anton Leherbauer bug 81555. Use a CDT specific partitioning for (almost) all C documents.

This commit is contained in:
Doug Schaefer 2006-04-04 18:46:38 +00:00
parent acd5b19ae7
commit 9c893eb485
5 changed files with 50 additions and 14 deletions

View file

@ -30,8 +30,10 @@ import org.eclipse.compare.internal.TokenComparator;
import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.jface.text.IDocumentPartitioner; import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.TextViewer; import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.util.PropertyChangeEvent;
@ -127,7 +129,12 @@ public class CMergeViewer extends TextMergeViewer {
private CSourceViewerConfiguration getSourceViewerConfiguration() { private CSourceViewerConfiguration getSourceViewerConfiguration() {
if (fSourceViewerConfiguration == null) { if (fSourceViewerConfiguration == null) {
CTextTools tools= CUIPlugin.getDefault().getTextTools(); CTextTools tools= CUIPlugin.getDefault().getTextTools();
fSourceViewerConfiguration = new CSourceViewerConfiguration(tools, null); fSourceViewerConfiguration = new CSourceViewerConfiguration(tools, null) {
public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
return IDocumentExtension3.DEFAULT_PARTITIONING;
}
};
} }
return fSourceViewerConfiguration; return fSourceViewerConfiguration;
} }
@ -143,10 +150,9 @@ public class CMergeViewer extends TextMergeViewer {
protected IDocumentPartitioner getDocumentPartitioner() { protected IDocumentPartitioner getDocumentPartitioner() {
return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner(); return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner();
} }
protected void configureTextViewer(TextViewer textViewer) { protected void configureTextViewer(TextViewer textViewer) {
if (textViewer instanceof SourceViewer) { if (textViewer instanceof SourceViewer) {
CTextTools tools= CUIPlugin.getDefault().getTextTools();
((SourceViewer)textViewer).configure(getSourceViewerConfiguration()); ((SourceViewer)textViewer).configure(getSourceViewerConfiguration());
} }
} }

View file

@ -29,7 +29,6 @@ import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.Document; import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.SelectionListener;
@ -289,9 +288,7 @@ public class CEditorPreferencePage extends AbstractPreferencePage implements IWo
String content = loadPreviewContentFromFile("ColorSettingPreviewCode.txt"); //$NON-NLS-1$ String content = loadPreviewContentFromFile("ColorSettingPreviewCode.txt"); //$NON-NLS-1$
IDocument document = new Document(content); IDocument document = new Document(content);
IDocumentPartitioner partitioner = fCTextTools.createDocumentPartitioner(); fCTextTools.setupCDocument(document);
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
fPreviewViewer.setDocument(document); fPreviewViewer.setDocument(document);

View file

@ -18,6 +18,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.Document; import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.AccessibleAdapter; import org.eclipse.swt.accessibility.AccessibleAdapter;
@ -70,9 +71,11 @@ public class CTemplatePreferencePage extends TemplatePreferencePage {
protected SourceViewer createViewer(Composite parent) { protected SourceViewer createViewer(Composite parent) {
SourceViewer viewer= new SourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); SourceViewer viewer= new SourceViewer(parent, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
CTextTools tools= CUIPlugin.getDefault().getTextTools(); CTextTools tools= CUIPlugin.getDefault().getTextTools();
IDocument document = new Document();
tools.setupCDocument(document);
viewer.configure(new CSourceViewerConfiguration(tools, null)); viewer.configure(new CSourceViewerConfiguration(tools, null));
viewer.setEditable(false); viewer.setEditable(false);
viewer.setDocument(new Document()); viewer.setDocument(document);
viewer.getTextWidget().setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); viewer.getTextWidget().setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
Font font= JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT); Font font= JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT);

View file

@ -151,6 +151,7 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
PresentationReconciler reconciler= new PresentationReconciler(); PresentationReconciler reconciler= new PresentationReconciler();
reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
RuleBasedScanner scanner; RuleBasedScanner scanner;
@ -469,8 +470,15 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
return detectors; return detectors;
} }
/** /*
* @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
*/
public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
return fTextTools.getDocumentPartitioning();
}
/**
* Creates control for outline presentation in editor. * Creates control for outline presentation in editor.
* @param editor Editor. * @param editor Editor.
* @return Control. * @return Control.

View file

@ -41,6 +41,8 @@ public class CTextTools {
adaptToPreferenceChange(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event.getNewValue())); adaptToPreferenceChange(new PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event.getNewValue()));
} }
} }
private static final String DEFAULT_PARTITIONING = "__c_partitioning"; //$NON-NLS-1$
/** The color manager */ /** The color manager */
private CColorManager fColorManager; private CColorManager fColorManager;
@ -63,7 +65,8 @@ public class CTextTools {
private Preferences fCorePreferenceStore; private Preferences fCorePreferenceStore;
/** The preference change listener */ /** The preference change listener */
private PreferenceListener fPreferenceListener= new PreferenceListener(); private PreferenceListener fPreferenceListener= new PreferenceListener();
/** The document partitioning used for the C partitioner */
private String fDocumentPartitioning = DEFAULT_PARTITIONING;
/** /**
* Creates a new C text tools collection and eagerly creates * Creates a new C text tools collection and eagerly creates
@ -273,7 +276,26 @@ public class CTextTools {
* @since 3.0 * @since 3.0
*/ */
public void setupCDocument(IDocument document) { public void setupCDocument(IDocument document) {
setupCDocumentPartitioner(document, IDocumentExtension3.DEFAULT_PARTITIONING); setupCDocumentPartitioner(document, fDocumentPartitioning);
} }
} /**
* Get the document partitioning used for the C partitioner.
*
* @return the document partitioning used for the C partitioner
* @since 3.1
*/
public String getDocumentPartitioning() {
return fDocumentPartitioning;
}
/**
* Set the document partitioning to be used for the C partitioner.
*
* @since 3.1
*/
public void setDocumentPartitioning(String documentPartitioning) {
fDocumentPartitioning = documentPartitioning;
}
}