mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-21 16:05:25 +02:00
Template indentation will honor preference setting "Insert Space for Tabs". Fixing #131311
This commit is contained in:
parent
ea21457c94
commit
cf99e3b36d
1 changed files with 19 additions and 1 deletions
|
@ -14,7 +14,9 @@ package org.eclipse.cdt.internal.corext.template.c;
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.formatter.CodeFormatter;
|
import org.eclipse.cdt.core.formatter.CodeFormatter;
|
||||||
import org.eclipse.cdt.internal.corext.util.CodeFormatterUtil;
|
import org.eclipse.cdt.internal.corext.util.CodeFormatterUtil;
|
||||||
|
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||||
import org.eclipse.cdt.internal.ui.util.Strings;
|
import org.eclipse.cdt.internal.ui.util.Strings;
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -34,6 +36,7 @@ import org.eclipse.text.edits.MultiTextEdit;
|
||||||
import org.eclipse.text.edits.RangeMarker;
|
import org.eclipse.text.edits.RangeMarker;
|
||||||
import org.eclipse.text.edits.ReplaceEdit;
|
import org.eclipse.text.edits.ReplaceEdit;
|
||||||
import org.eclipse.text.edits.TextEdit;
|
import org.eclipse.text.edits.TextEdit;
|
||||||
|
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -204,7 +207,22 @@ public class CFormatter {
|
||||||
MultiTextEdit root= new MultiTextEdit(0, document.getLength());
|
MultiTextEdit root= new MultiTextEdit(0, document.getLength());
|
||||||
root.addChildren((TextEdit[]) positions.toArray(new TextEdit[positions.size()]));
|
root.addChildren((TextEdit[]) positions.toArray(new TextEdit[positions.size()]));
|
||||||
|
|
||||||
String indent= Strings.createIndentString(fInitialIndentLevel);
|
boolean useSpaces=
|
||||||
|
CUIPlugin.getDefault().getCombinedPreferenceStore().getBoolean(CEditor.SPACES_FOR_TABS);
|
||||||
|
String indent;
|
||||||
|
if (useSpaces) {
|
||||||
|
int iSpaceIndent =
|
||||||
|
CUIPlugin.getDefault().getCombinedPreferenceStore().getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH);
|
||||||
|
|
||||||
|
StringBuffer mystringbuf = new StringBuffer();
|
||||||
|
for ( int i=fInitialIndentLevel * iSpaceIndent; i>0; i-- )
|
||||||
|
mystringbuf.append ( ' ' );
|
||||||
|
|
||||||
|
indent = mystringbuf.toString();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
indent = Strings.createIndentString(fInitialIndentLevel);
|
||||||
|
}
|
||||||
// first line
|
// first line
|
||||||
int offset= document.getLineOffset(0);
|
int offset= document.getLineOffset(0);
|
||||||
TextEdit edit= new InsertEdit(offset, indent);
|
TextEdit edit= new InsertEdit(offset, indent);
|
||||||
|
|
Loading…
Add table
Reference in a new issue