use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter method decoratedPropNameRegion.
/**
*/
protected String decoratedPropNameRegion(CompoundRegion region, CSSCleanupStrategy stgy) {
if (isFormat())
return region.getText();
String text = null;
if (!stgy.isFormatSource())
text = region.getFullText();
else
text = region.getText();
if (region.getType() == CSSRegionContexts.CSS_STRING || region.getType() == CSSRegionContexts.CSS_URI)
return decoratedRegion(region, 1, stgy);
if (isCleanup()) {
if (stgy.getPropNameCase() == CSSCleanupStrategy.ASIS || region.getType() != CSSRegionContexts.CSS_DECLARATION_PROPERTY)
return text;
else if (stgy.getPropNameCase() == CSSCleanupStrategy.UPPER)
return text.toUpperCase();
else
return text.toLowerCase();
}
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
if (region.getType() != CSSRegionContexts.CSS_DECLARATION_PROPERTY)
return text;
else if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_NAME) == CSSCorePreferenceNames.UPPER)
return text.toUpperCase();
else
return text.toLowerCase();
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter 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 AttrFormatter method formatPre.
/**
*/
protected void formatPre(ICSSNode node, StringBuffer source) {
ICSSAttr attr = (ICSSAttr) node;
CSSCleanupStrategy stgy = getCleanupStrategy(node);
int end = ((IndexedRegion) node).getEndOffset();
if (end > 0) {
// format source
int start = ((IndexedRegion) node).getStartOffset();
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
if (attr.getName().equals(ICSSStyleRule.SELECTOR) || attr.getName().equals(ICSSPageRule.SELECTOR)) {
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBetween(node, regions[i - 1], regions[i], source);
source.append(decoratedRegion(regions[i], 0, stgy));
}
} else if (attr.getName().equals(ICSSImportRule.HREF)) {
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(decoratedPropValueRegion(regions[i], stgy));
}
} else if (attr.getName().equals(ICSSCharsetRule.ENCODING)) {
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(decoratedIdentRegion(regions[i], stgy));
}
} else if (attr.getName().equals(ICSSStyleDeclItem.IMPORTANT)) {
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(decoratedPropValueRegion(regions[i], stgy));
}
} else if (attr.getName() == null || attr.getName().length() == 0) {
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(decoratedIdentRegion(regions[i], stgy));
}
} else {
// counter attributes
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(decoratedPropValueRegion(regions[i], stgy));
}
}
} else {
// generate source
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
String value = attr.getValue();
if (value == null)
// $NON-NLS-1$
value = "";
if (attr.getName().equals(ICSSStyleRule.SELECTOR) || attr.getName().equals(ICSSPageRule.SELECTOR)) {
} else if (attr.getName().equals(ICSSImportRule.HREF)) {
String uri = org.eclipse.wst.css.core.internal.util.CSSLinkConverter.stripFunc(value);
// $NON-NLS-2$//$NON-NLS-1$
String func = preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER ? "URL(" : "url(";
if (preferences.getBoolean(CSSCorePreferenceNames.FORMAT_QUOTE_IN_URI)) {
String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
quote = CSSUtil.detectQuote(uri, quote);
// $NON-NLS-1$
value = func + quote + uri + quote + ")";
} else {
// $NON-NLS-1$
value = func + uri + ")";
}
} else if (attr.getName().equals(ICSSCharsetRule.ENCODING)) {
String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
if (// $NON-NLS-2$//$NON-NLS-1$
!value.startsWith("\"") && !value.startsWith("\'"))
value = quote + value;
if (// $NON-NLS-2$//$NON-NLS-1$
!value.endsWith("\"") && !value.endsWith("\'"))
value = value + quote;
} else if (attr.getName().equals(ICSSStyleDeclItem.IMPORTANT)) {
if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER)
value = value.toUpperCase();
else
value = value.toLowerCase();
} else if (attr.getName() == null || attr.getName().length() == 0) {
if (CSSCorePlugin.getDefault().getPluginPreferences().getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
value = value.toUpperCase();
else
value = value.toLowerCase();
} else {
if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER)
value = value.toUpperCase();
else
value = value.toLowerCase();
}
source.append(value);
}
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class CharsetRuleFormatter method formatPre.
/**
*/
protected void formatPre(ICSSNode node, StringBuffer source) {
int end = ((IndexedRegion) node).getEndOffset();
if (end > 0) {
// format source
int start = ((IndexedRegion) node).getStartOffset();
formatPre(node, new FormatRegion(start, end - start), source);
} else {
// generate source
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
String str = CHARSET;
if (preferences.getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
str = CHARSET.toUpperCase();
source.append(str);
String enc = ((ICSSCharsetRule) node).getEncoding();
quote = CSSUtil.detectQuote(enc, quote);
// $NON-NLS-1$ //$NON-NLS-2$
str = quote + ((enc != null) ? enc : "") + quote + ";";
appendSpaceBefore(node, str, source);
source.append(str);
}
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class StyleDeclItemFormatter 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();
}
Aggregations