use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class StructuredAutoEditStrategyCSS method getIndentString.
private String getIndentString() {
StringBuffer indent = new StringBuffer();
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
if (preferences != null) {
char indentChar = ' ';
String indentCharPref = preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR);
if (CSSCorePreferenceNames.TAB.equals(indentCharPref)) {
indentChar = '\t';
}
int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE);
for (int i = 0; i < indentationWidth; i++) {
indent.append(indentChar);
}
}
return indent.toString();
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class StructuredAutoEditStrategyCSS method smartInsertForTab.
/**
* Insert spaces for tabs
*
* @param command
*/
private void smartInsertForTab(DocumentCommand command, IDocument document) {
// tab key was pressed. now check preferences to see if need to insert
// spaces instead of tab
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
if (CSSCorePreferenceNames.SPACE.equals(preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR))) {
int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE);
StringBuffer indent = new StringBuffer();
if (indentationWidth != 0) {
int indentSize = indentationWidth;
try {
IRegion firstLine = document.getLineInformationOfOffset(command.offset);
int offsetInLine = command.offset - firstLine.getOffset();
int remainder = offsetInLine % indentationWidth;
indentSize = indentationWidth - remainder;
} catch (BadLocationException e) {
Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
}
for (int i = 0; i < indentSize; i++) indent.append(' ');
}
// replace \t characters with spaces
command.text = indent.toString();
}
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class CSSProposalGenerator method generateBraces.
/**
*/
protected StringAndOffset generateBraces() {
StringBuffer buf = new StringBuffer();
String lineDelimiter = fContext.getStructuredDocument().getLineDelimiter();
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
String indentStr = getIndentString();
if (preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_NEWLINE_ON_OPEN_BRACE)) {
buf.append(lineDelimiter);
}
// $NON-NLS-1$
buf.append("{");
if (preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_ONE_PER_LINE)) {
buf.append(lineDelimiter);
buf.append(indentStr);
} else {
// $NON-NLS-1$
buf.append(" ");
}
int offset = buf.length();
if (preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_ONE_PER_LINE)) {
buf.append(lineDelimiter);
} else {
// $NON-NLS-1$
buf.append(" ");
}
// $NON-NLS-1$
buf.append("}");
return new StringAndOffset(buf.toString(), offset);
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class StructuredTextViewerConfigurationCSS method getIndentPrefixes.
public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
Vector vector = new Vector();
// prefix[0] is either '\t' or ' ' x tabWidth, depending on preference
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE);
String indentCharPref = preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR);
boolean useSpaces = CSSCorePreferenceNames.SPACE.equals(indentCharPref);
for (int i = 0; i <= indentationWidth; i++) {
StringBuffer prefix = new StringBuffer();
boolean appendTab = false;
if (useSpaces) {
for (int j = 0; j + i < indentationWidth; j++) prefix.append(' ');
if (i != 0)
appendTab = true;
} else {
for (int j = 0; j < i; j++) prefix.append(' ');
if (i != indentationWidth)
appendTab = true;
}
if (appendTab) {
prefix.append('\t');
vector.add(prefix.toString());
// remove the tab so that indentation - tab is also an indent
// prefix
prefix.deleteCharAt(prefix.length() - 1);
}
vector.add(prefix.toString());
}
// $NON-NLS-1$
vector.add("");
return (String[]) vector.toArray(new String[vector.size()]);
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class CSSSourcePreferencePage method performDefaultsForFormattingGroup.
private void performDefaultsForFormattingGroup() {
// Formatting
Preferences prefs = getModelPreferences();
fLineWidthText.setText(prefs.getDefaultString(CSSCorePreferenceNames.LINE_WIDTH));
fPropertyPerLine.setSelection(prefs.getDefaultBoolean(CSSCorePreferenceNames.WRAPPING_ONE_PER_LINE));
fNowrapAttr.setSelection(prefs.getDefaultBoolean(CSSCorePreferenceNames.WRAPPING_PROHIBIT_WRAP_ON_ATTR));
spaceBetweenSelectors.setSelection(prefs.getDefaultBoolean(CSSCorePreferenceNames.FORMAT_SPACE_BETWEEN_SELECTORS));
if (CSSCorePreferenceNames.TAB.equals(getModelPreferences().getDefaultString(CSSCorePreferenceNames.INDENTATION_CHAR))) {
fIndentUsingTabs.setSelection(true);
fIndentUsingSpaces.setSelection(false);
} else {
fIndentUsingSpaces.setSelection(true);
fIndentUsingTabs.setSelection(false);
}
fIndentationSize.setSelection(getModelPreferences().getDefaultInt(CSSCorePreferenceNames.INDENTATION_SIZE));
}
Aggregations