Bug 178031 - Adopt tabs to spaces support from Platform Text
diff --git a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditor.java b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditor.java
index 2588ab5..f275f07 100644
--- a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditor.java
+++ b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditor.java
@@ -61,15 +61,12 @@
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DefaultLineTracker;
-import org.eclipse.jface.text.DocumentCommand;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.ILineTracker;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ISelectionValidator;
import org.eclipse.jface.text.ISynchronizable;
@@ -192,86 +189,8 @@
}
}
- static class TabConverter {
-
- private int fTabRatio;
- private ILineTracker fLineTracker;
-
- public void setNumberOfSpacesPerTab(int ratio) {
- fTabRatio= ratio;
- }
-
- public void setLineTracker(ILineTracker lineTracker) {
- fLineTracker= lineTracker;
- }
-
- private int insertTabString(StringBuffer buffer, int offsetInLine) {
-
- if (fTabRatio == 0) {
- return 0;
- }
-
- int remainder= offsetInLine % fTabRatio;
- remainder= fTabRatio - remainder;
- for (int i= 0; i < remainder; i++) {
- buffer.append(' ');
- }
- return remainder;
- }
-
- public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
- String text= command.text;
- if (text == null) {
- return;
- }
-
- int index= text.indexOf('\t');
- if (index > -1) {
-
- StringBuffer buffer= new StringBuffer();
-
- fLineTracker.set(command.text);
- int lines= fLineTracker.getNumberOfLines();
-
- try {
-
- for (int i= 0; i < lines; i++) {
-
- int offset= fLineTracker.getLineOffset(i);
- int endOffset= offset + fLineTracker.getLineLength(i);
- String line= text.substring(offset, endOffset);
-
- int position= 0;
- if (i == 0) {
- IRegion firstLine= document.getLineInformationOfOffset(command.offset);
- position= command.offset - firstLine.getOffset();
- }
-
- int length= line.length();
- for (int j= 0; j < length; j++) {
- char c= line.charAt(j);
- if (c == '\t') {
- position += insertTabString(buffer, position);
- } else {
- buffer.append(c);
- ++ position;
- }
- }
-
- }
-
- command.text= buffer.toString();
-
- } catch (BadLocationException x) {
- }
- }
- }
- }
-
class StatusLineSourceViewer extends ProjectionViewer{
- private boolean fIgnoreTextConverters= false;
-
public StatusLineSourceViewer(Composite composite, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, int styles) {
super(composite, verticalRuler, overviewRuler, isOverviewRulerVisible(), styles);
}
@@ -289,42 +208,12 @@
String msg= fContentAssistant.showPossibleCompletions();
setStatusLineErrorMessage(msg);
return;
- case UNDO:
- fIgnoreTextConverters= true;
- break;
- case REDO:
- fIgnoreTextConverters= true;
- break;
}
super.doOperation(operation);
}
-
- protected void setTextConverter(TabConverter tabConverter) {
- fTabConverter= tabConverter;
- }
-
- protected void updateIndentationPrefixes() {
- SourceViewerConfiguration configuration= getSourceViewerConfiguration();
- String[] types= configuration.getConfiguredContentTypes(this);
- for (int i= 0; i < types.length; i++) {
- String[] prefixes= configuration.getIndentPrefixes(this, types[i]);
- if (prefixes != null && prefixes.length > 0) {
- setIndentPrefixes(prefixes, types[i]);
- }
- }
- }
- /* (non-Javadoc)
- * @see org.eclipse.jface.text.TextViewer#customizeDocumentCommand(org.eclipse.jface.text.DocumentCommand)
- */
- protected void customizeDocumentCommand(DocumentCommand command) {
- super.customizeDocumentCommand(command);
- if (!fIgnoreTextConverters && fTabConverter != null) {
- fTabConverter.customizeDocumentCommand(getDocument(), command);
- }
- fIgnoreTextConverters= false;
- }
}
+
/**
* Finds and marks occurrence annotations.
@@ -573,8 +462,6 @@
*/
protected AntEditorContentOutlinePage fOutlinePage;
- /** The editor's tab to spaces converter */
- private TabConverter fTabConverter;
private boolean fInitialReconcile= true;
@@ -819,18 +706,6 @@
}
if (newValue != -1) {
viewer.getTextWidget().setTabs(newValue);
- if (fTabConverter != null) {
- fTabConverter.setNumberOfSpacesPerTab(newValue);
- }
- }
- return;
- }
-
- if (AntEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS.equals(property)) {
- if (isTabConversionEnabled()) {
- startTabConversion();
- } else {
- stopTabConversion();
}
return;
}
@@ -1057,33 +932,6 @@
}
}
- private void startTabConversion() {
- if (fTabConverter == null) {
- fTabConverter= new TabConverter();
- fTabConverter.setLineTracker(new DefaultLineTracker());
- fTabConverter.setNumberOfSpacesPerTab(getTabSize());
- StatusLineSourceViewer viewer= (StatusLineSourceViewer) getSourceViewer();
- viewer.setTextConverter(fTabConverter);
- // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
- viewer.updateIndentationPrefixes();
- }
- }
-
- private void stopTabConversion() {
- if (fTabConverter != null) {
- StatusLineSourceViewer viewer= (StatusLineSourceViewer) getSourceViewer();
- viewer.setTextConverter(null);
- // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270
- viewer.updateIndentationPrefixes();
- fTabConverter= null;
- }
- }
-
- protected int getTabSize() {
- IPreferenceStore preferences= getPreferenceStore();
- return preferences.getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH);
- }
-
/* (non-Javadoc)
* @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@@ -1096,10 +944,6 @@
projectionViewer.doOperation(ProjectionViewer.TOGGLE);
}
- if (isTabConversionEnabled()) {
- startTabConversion();
- }
-
if (fMarkOccurrenceAnnotations) {
installOccurrencesFinder();
}
@@ -1127,9 +971,12 @@
return store.getBoolean(AntEditorPreferenceConstants.EDITOR_FOLDING_ENABLED);
}
- protected boolean isTabConversionEnabled() {
- IPreferenceStore store= getPreferenceStore();
- return store.getBoolean(AntEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS);
+ /*
+ * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#isTabsToSpacesConversionEnabled()
+ * @since 3.3
+ */
+ protected boolean isTabsToSpacesConversionEnabled() {
+ return super.isTabsToSpacesConversionEnabled();
}
/* (non-Javadoc)
diff --git a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditorSourceViewerConfiguration.java b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditorSourceViewerConfiguration.java
index 15e2fa5..f9bfcbb 100644
--- a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditorSourceViewerConfiguration.java
+++ b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditorSourceViewerConfiguration.java
@@ -262,8 +262,8 @@
// prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
- int tabWidth= fEditor.getTabSize();
- boolean useSpaces= fEditor.isTabConversionEnabled();
+ int tabWidth= getTabWidth(sourceViewer);
+ boolean useSpaces= fEditor.isTabsToSpacesConversionEnabled();
for (int i= 0; i <= tabWidth; i++) {
StringBuffer prefix= new StringBuffer();
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferenceConstants.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferenceConstants.java
index 115979e..f6d65fd 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferenceConstants.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferenceConstants.java
@@ -72,15 +72,6 @@
*/
public final static String CODEASSIST_PROPOSALS_BACKGROUND= "org.eclipse.ant.ui.codeAssistProposalsBackgroundColor"; //$NON-NLS-1$
public final static String CODEASSIST_PROPOSALS_FOREGROUND= "org.eclipse.ant.ui.codeAssistProposalsForegroundColor"; //$NON-NLS-1$
- /**
- * A named preference that specifies if the editor uses spaces for tabs.
- * <p>
- * Value is of type <code>Boolean</code>. If <code>true</code>spaces instead of tabs are used
- * in the editor. If <code>false</code> the editor inserts a tab character when pressing the tab
- * key.
- * </p>
- */
- public final static String EDITOR_SPACES_FOR_TABS= "spaces_for_tabs"; //$NON-NLS-1$
/**
* A named preference that specifies the tab size for the Ant formatter.
@@ -305,8 +296,6 @@
PreferenceConverter.setDefault(store, CODEASSIST_PROPOSALS_FOREGROUND, new RGB(0, 0, 0));
store.setDefault(CODEASSIST_AUTOACTIVATION_TRIGGERS, "<${"); //$NON-NLS-1$
- store.setDefault(EDITOR_SPACES_FOR_TABS, false);
-
store.setDefault(FORMATTER_TAB_CHAR, true);
store.setDefault(FORMATTER_TAB_SIZE, 4);
store.setDefault(FORMATTER_ALIGN, false);
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferencePage.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferencePage.java
index 134c033..699ebed 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferencePage.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntEditorPreferencePage.java
@@ -277,8 +277,6 @@
};
ArrayList overlayKeys= new ArrayList();
- overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS));
-
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.CODEASSIST_AUTOINSERT));
@@ -330,9 +328,6 @@
labelText= AntPreferencesMessages.AntEditorPreferencePage_4;
addCheckBox(appearanceComposite, labelText, AntEditorPreferenceConstants.EDITOR_STICKY_OCCURRENCES, 0);
- labelText= AntPreferencesMessages.AntEditorPreferencePage_40;
- addCheckBox(appearanceComposite, labelText, AntEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS, 0);
-
return appearanceComposite;
}
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.java b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.java
index dd605c6..7dd5695 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.java
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.java
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2000, 2007 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@@ -129,7 +129,6 @@
public static String AntEditorPreferencePage_Ant_editor_tags_4;
public static String AntEditorPreferencePage_Ant_editor_comments_5;
public static String AntEditorPreferencePage_30;
- public static String AntEditorPreferencePage_40;
public static String AntEditorPreferencePage_1;
public static String AntEditorPreferencePage_10;
public static String AntEditorPreferencePage_11;
diff --git a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.properties b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.properties
index 4d7e83f..ce223cd 100644
--- a/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.properties
+++ b/ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencesMessages.properties
@@ -126,7 +126,6 @@
AntEditorPreferencePage_Ant_editor_tags_4=Tags
AntEditorPreferencePage_Ant_editor_comments_5=Comments
AntEditorPreferencePage_30=Na&mes:
-AntEditorPreferencePage_40=&Insert spaces for tabs when typing
AntEditorPreferencePage_1=Synta&x
AntEditorPreferencePage_10=&Problems
AntEditorPreferencePage_11=Error