Bug 131311 - Code template inserts TABs when it should insert spaces
Summary: Code template inserts TABs when it should insert spaces
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1   Edit
Assignee: Norbert Plött CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2006-03-10 07:19 EST by Michael Luber CLA
Modified: 2009-01-12 09:08 EST (History)
1 user (show)

See Also:


Attachments
Fix described below in patch format (2.13 KB, patch)
2006-03-13 05:23 EST, Norbert Plött CLA
bjorn.freeman-benson: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Luber CLA 2006-03-10 07:19:27 EST
Go to the prefences page "C/C++ -> Editor", and tick "Insert space for tabs".
Now open a C source file, indent somewhere, type "switch", hit CTRL+Space,
and choose to insert a switch-case-statement.

Now inspect the characters that have been inserted for indentation.
You only find tabs. Those that came from the template itself are OK, but
those that indent the whole template to fit the rest of the code should be spaces.

Suggestion:
In package org.eclipse.cdt.internal.corext.template.c you find CFormatter.java.

in method "private void indent", change 
#############################################################################
  String indent= Strings.createIndentString(fInitialIndentLevel);
#############################################################################
to 

#############################################################################
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);
}
#############################################################################
Comment 1 Norbert Plött CLA 2006-03-13 05:23:15 EST
Created attachment 36123 [details]
Fix described below in patch format

Adding a patch which implements the fix described below.
Pse always try submit your suggestions in patch format.
Comment 2 Norbert Plött CLA 2006-03-13 05:33:52 EST
Patch applied.
Thank you.