import com.android.ide.eclipse.adt.internal.preferences.AttributeSortOrder;
import org.eclipse.core.runtime.Preferences;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.ui.internal.editors.text.EditorsPlugin;
+import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames;
/** The string to insert for each indentation level */
private String mOneIndentUnit = " "; //$NON-NLS-1$
+ /** Tab width (number of spaces to display for a tab) */
+ private int mTabWidth = -1; // -1: uninitialized
+
private XmlFormatPreferences() {
}
return mOneIndentUnit;
}
+
+ /**
+ * Returns the number of spaces used to display a single tab character
+ *
+ * @return the number of spaces used to display a single tab character
+ */
+ @SuppressWarnings("restriction") // Editor settings
+ public int getTabWidth() {
+ if (mTabWidth == -1) {
+ String key = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH;
+ try {
+ IPreferenceStore prefs = EditorsPlugin.getDefault().getPreferenceStore();
+ mTabWidth = prefs.getInt(key);
+ } catch (Throwable t) {
+ // Pass: We'll pick a suitable default instead below
+ }
+ if (mTabWidth <= 0) {
+ mTabWidth = 4;
+ }
+ }
+
+ return mTabWidth;
+ }
}
if (!startsWithNewline) {
Node previous = node.getPreviousSibling();
if (previous != null && previous.getNodeType() == Node.TEXT_NODE) {
- int TAB_SIZE = 4; // TODO: Look up Eclipse settings
String prevText = previous.getNodeValue();
int indentation = COMMENT_BEGIN.length();
for (int i = prevText.length() - 1; i >= 0; i--) {
if (c == '\n') {
break;
} else {
- indentation += (c == '\t') ? TAB_SIZE : 1;
+ indentation += (c == '\t') ? mPrefs.getTabWidth() : 1;
}
}
}
break;
} else {
- indent += (c == '\t') ? TAB_SIZE : 1;
+ indent += (c == '\t') ? mPrefs.getTabWidth() : 1;
}
}
}
if (!Character.isWhitespace(c)) {
break;
} else {
- indentation -= (c == '\t') ? TAB_SIZE : 1;
+ indentation -= (c == '\t') ? mPrefs.getTabWidth() : 1;
}
}
}