1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Cleanup CSourceViewer: remove obsolete constructor and duplicate methods

This commit is contained in:
Anton Leherbauer 2006-10-18 09:05:18 +00:00
parent 9b75c68712
commit 39fd51b72a
3 changed files with 34 additions and 89 deletions

View file

@ -16,10 +16,8 @@ package org.eclipse.cdt.internal.ui.editor;
import java.text.CharacterIterator; import java.text.CharacterIterator;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Stack; import java.util.Stack;
@ -215,12 +213,9 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
class AdaptedSourceViewer extends CSourceViewer { class AdaptedSourceViewer extends CSourceViewer {
private List fTextConverters;
private boolean fIgnoreTextConverters= false;
public AdaptedSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, public AdaptedSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
boolean showAnnotationsOverview, int styles, IPreferenceStore store) { boolean showAnnotationsOverview, int styles, IPreferenceStore store) {
super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles); super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles, store);
} }
public IContentAssistant getContentAssistant() { public IContentAssistant getContentAssistant() {
@ -253,52 +248,11 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
msg= fQuickAssistAssistant.showPossibleQuickAssists(); msg= fQuickAssistAssistant.showPossibleQuickAssists();
setStatusLineErrorMessage(msg); setStatusLineErrorMessage(msg);
return; return;
case UNDO:
fIgnoreTextConverters= true;
super.doOperation(operation);
fIgnoreTextConverters= false;
return;
case REDO:
fIgnoreTextConverters= true;
super.doOperation(operation);
fIgnoreTextConverters= false;
return;
} }
super.doOperation(operation); super.doOperation(operation);
} }
public void insertTextConverter(ITextConverter textConverter, int index) {
throw new UnsupportedOperationException();
}
public void addTextConverter(ITextConverter textConverter) {
if (fTextConverters == null) {
fTextConverters= new ArrayList(1);
fTextConverters.add(textConverter);
} else if (!fTextConverters.contains(textConverter))
fTextConverters.add(textConverter);
}
public void removeTextConverter(ITextConverter textConverter) {
if (fTextConverters != null) {
fTextConverters.remove(textConverter);
if (fTextConverters.size() == 0)
fTextConverters= null;
}
}
/*
* @see TextViewer#customizeDocumentCommand(DocumentCommand)
*/
protected void customizeDocumentCommand(DocumentCommand command) {
super.customizeDocumentCommand(command);
if (!fIgnoreTextConverters && fTextConverters != null) {
for (Iterator e = fTextConverters.iterator(); e.hasNext();)
((ITextConverter) e.next()).customizeDocumentCommand(getDocument(), command);
}
}
public void updateIndentationPrefixes() { public void updateIndentationPrefixes() {
SourceViewerConfiguration configuration= getSourceViewerConfiguration(); SourceViewerConfiguration configuration= getSourceViewerConfiguration();
String[] types= configuration.getConfiguredContentTypes(this); String[] types= configuration.getConfiguredContentTypes(this);
@ -1836,6 +1790,13 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
} }
} }
/*
* @see org.eclipse.ui.texteditor.AbstractTextEditor#initializeViewerColors(org.eclipse.jface.text.source.ISourceViewer)
*/
protected void initializeViewerColors(ISourceViewer viewer) {
// is handled by CSourceViewer
}
/* /*
* Update the hovering behavior depending on the preferences. * Update the hovering behavior depending on the preferences.
*/ */
@ -2874,7 +2835,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
* @see org.eclipse.cdt.internal.ui.editor.IReconcilingParticipant#reconciled() * @see org.eclipse.cdt.internal.ui.editor.IReconcilingParticipant#reconciled()
*/ */
public void reconciled(boolean somethingHasChanged) { public void reconciled(boolean somethingHasChanged) {
if (getSourceViewer() == null) { if (getSourceViewer() == null || getSourceViewer().getTextWidget() == null) {
return; return;
} }
// this method must be called in a background thread // this method must be called in a background thread

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* QNX Software Systems - initial API and implementation * QNX Software Systems - initial API and implementation
* Sergey Prigogin, Google * Sergey Prigogin, Google
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.editor; package org.eclipse.cdt.internal.ui.editor;
@ -15,9 +16,9 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.core.runtime.Assert;
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.Assert;
import org.eclipse.jface.text.DocumentCommand; import org.eclipse.jface.text.DocumentCommand;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.IRegion;
@ -52,12 +53,11 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
/** Show outline operation id. */ /** Show outline operation id. */
public static final int SHOW_OUTLINE = 101; public static final int SHOW_OUTLINE = 101;
/** Editor. */
private CEditor editor;
/** Presents outline. */ /** Presents outline. */
private IInformationPresenter fOutlinePresenter; private IInformationPresenter fOutlinePresenter;
private List fTextConverters; private List fTextConverters;
private boolean fIgnoreTextConverters= false;
/** /**
* This viewer's foreground color. * This viewer's foreground color.
@ -104,19 +104,6 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
/** /**
* Creates new source viewer. * Creates new source viewer.
* @param parent
* @param ruler
* @param fOverviewRuler
* @param isOverviewRulerShowing
* @param styles
*/
public CSourceViewer(Composite parent, IVerticalRuler ruler, IOverviewRuler fOverviewRuler, boolean isOverviewRulerShowing,
int styles) {
super(parent, ruler, fOverviewRuler, isOverviewRulerShowing, styles);
}
/**
* Creates new source viewer.
* @param parent * @param parent
* @param ruler * @param ruler
* @param overviewRuler * @param overviewRuler
@ -132,7 +119,6 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
int styles, int styles,
IPreferenceStore store) { IPreferenceStore store) {
super(parent, ruler, overviewRuler, isOverviewRulerShowing, styles); super(parent, ruler, overviewRuler, isOverviewRulerShowing, styles);
this.editor= null;
setPreferenceStore(store); setPreferenceStore(store);
} }
@ -161,7 +147,6 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
fOutlinePresenter= cConfiguration.getOutlinePresenter(this); fOutlinePresenter= cConfiguration.getOutlinePresenter(this);
if (fOutlinePresenter != null) if (fOutlinePresenter != null)
fOutlinePresenter.install(this); fOutlinePresenter.install(this);
editor = (CEditor) cConfiguration.getEditor();
} }
if (fPreferenceStore != null) { if (fPreferenceStore != null) {
fPreferenceStore.addPropertyChangeListener(this); fPreferenceStore.addPropertyChangeListener(this);
@ -249,7 +234,7 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
return null; return null;
} }
/** /*
* @see org.eclipse.jface.text.source.SourceViewer#unconfigure() * @see org.eclipse.jface.text.source.SourceViewer#unconfigure()
*/ */
public void unconfigure() { public void unconfigure() {
@ -311,7 +296,7 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
} }
} }
/** /*
* @see org.eclipse.jface.text.ITextOperationTarget#doOperation(int) * @see org.eclipse.jface.text.ITextOperationTarget#doOperation(int)
*/ */
public void doOperation(int operation) { public void doOperation(int operation) {
@ -320,22 +305,24 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
return; return;
} }
switch (operation) { switch (operation) {
case CONTENTASSIST_PROPOSALS:
{
String msg= fContentAssistant.showPossibleCompletions();
editor.setStatusLineErrorMessage(msg);
return;
}
case SHOW_OUTLINE: case SHOW_OUTLINE:
{
fOutlinePresenter.showInformation(); fOutlinePresenter.showInformation();
return; return;
} case UNDO:
fIgnoreTextConverters= true;
super.doOperation(operation);
fIgnoreTextConverters= false;
return;
case REDO:
fIgnoreTextConverters= true;
super.doOperation(operation);
fIgnoreTextConverters= false;
return;
} }
super.doOperation(operation); super.doOperation(operation);
} }
/** /*
* @see org.eclipse.jface.text.source.projection.ProjectionViewer#canDoOperation(int) * @see org.eclipse.jface.text.source.projection.ProjectionViewer#canDoOperation(int)
*/ */
public boolean canDoOperation(int operation) { public boolean canDoOperation(int operation) {
@ -345,10 +332,6 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
return super.canDoOperation(operation); return super.canDoOperation(operation);
} }
public void insertTextConverter(ITextConverter textConverter, int index) {
throw new UnsupportedOperationException();
}
public void addTextConverter(ITextConverter textConverter) { public void addTextConverter(ITextConverter textConverter) {
if (fTextConverters == null) { if (fTextConverters == null) {
fTextConverters = new ArrayList(1); fTextConverters = new ArrayList(1);
@ -370,7 +353,7 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
*/ */
protected void customizeDocumentCommand(DocumentCommand command) { protected void customizeDocumentCommand(DocumentCommand command) {
super.customizeDocumentCommand(command); super.customizeDocumentCommand(command);
if (fTextConverters != null) { if (!fIgnoreTextConverters && fTextConverters != null) {
for (Iterator e = fTextConverters.iterator(); e.hasNext();) for (Iterator e = fTextConverters.iterator(); e.hasNext();)
((ITextConverter) e.next()).customizeDocumentCommand(getDocument(), command); ((ITextConverter) e.next()).customizeDocumentCommand(getDocument(), command);
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others. * Copyright (c) 2000, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Sergey Prigogin, Google * Sergey Prigogin, Google
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.preferences.formatter; package org.eclipse.cdt.internal.ui.preferences.formatter;
@ -114,7 +115,7 @@ public abstract class CPreview {
IPreferenceStore[] chain= { prioritizedSettings, CUIPlugin.getDefault().getCombinedPreferenceStore() }; IPreferenceStore[] chain= { prioritizedSettings, CUIPlugin.getDefault().getCombinedPreferenceStore() };
fPreferenceStore= new ChainedPreferenceStore(chain); fPreferenceStore= new ChainedPreferenceStore(chain);
fSourceViewer= new CSourceViewer(parent, null, null, false, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); fSourceViewer= new CSourceViewer(parent, null, null, false, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, fPreferenceStore);
fViewerConfiguration= new SimpleCSourceViewerConfiguration(tools.getColorManager(), fPreferenceStore, null, ICPartitions.C_PARTITIONING, true); fViewerConfiguration= new SimpleCSourceViewerConfiguration(tools.getColorManager(), fPreferenceStore, null, ICPartitions.C_PARTITIONING, true);
fSourceViewer.configure(fViewerConfiguration); fSourceViewer.configure(fViewerConfiguration);
fSourceViewer.getTextWidget().setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT)); fSourceViewer.getTextWidget().setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT));