use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class StyleDeclItemFormatter method appendAfterColonSpace.
/**
*/
private void appendAfterColonSpace(ICSSNode node, StringBuffer source) {
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
int n = preferences.getInt(CSSCorePreferenceNames.FORMAT_PROP_POST_DELIM);
if (preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH) > 0 && (!preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_PROHIBIT_WRAP_ON_ATTR) || node.getOwnerDocument().getNodeType() != ICSSNode.STYLEDECLARATION_NODE)) {
int length = getLastLineLength(node, source);
int append = getFirstChildRegionLength(node);
if (length + n + append > preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH)) {
source.append(getLineDelimiter(node));
source.append(getIndent(node));
source.append(getIndentString());
// no space is necessary
n = 0;
}
}
// no delimiter case
while (n-- > 0) // $NON-NLS-1$
source.append(" ");
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class StyleDeclItemFormatter method formatPre.
/**
*/
protected void formatPre(ICSSNode node, StringBuffer source) {
int start = ((IndexedRegion) node).getStartOffset();
int end = (node.getFirstChild() != null && ((IndexedRegion) node.getFirstChild()).getEndOffset() > 0) ? ((IndexedRegion) node.getFirstChild()).getStartOffset() : getChildInsertPos(node);
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
if (end > 0) {
// format source
CSSCleanupStrategy stgy = getCleanupStrategy(node);
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(decoratedPropNameRegion(regions[i], stgy));
}
} else {
// generatoe source
ICSSStyleDeclItem item = (ICSSStyleDeclItem) node;
if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_NAME) == CSSCorePreferenceNames.UPPER)
source.append(item.getPropertyName().toUpperCase());
else
source.append(item.getPropertyName());
int k = preferences.getInt(CSSCorePreferenceNames.FORMAT_PROP_PRE_DELIM);
if (preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH) > 0 && (!preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_PROHIBIT_WRAP_ON_ATTR) || node.getOwnerDocument().getNodeType() != ICSSNode.STYLEDECLARATION_NODE)) {
int length = getLastLineLength(node, source);
int append = 1;
if (length + k + append > preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH)) {
source.append(getLineDelimiter(node));
source.append(getIndent(node));
source.append(getIndentString());
// no space is necessary
k = 0;
}
}
// no delimiter case
while (k-- > 0) // $NON-NLS-1$
source.append(" ");
// $NON-NLS-1$
source.append(":");
}
if (node.getFirstChild() != null && (!isCleanup() || getCleanupStrategy(node).isFormatSource())) {
appendAfterColonSpace(node, source);
}
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class StyleDeclarationFormatter method formatBefore.
/**
*/
protected void formatBefore(ICSSNode node, ICSSNode child, IRegion region, String toAppend, StringBuffer source) {
CSSCleanupStrategy stgy = getCleanupStrategy(node);
ICSSModel cssModel = node.getOwnerDocument().getModel();
// with no model associated with it
if (cssModel != null) {
IStructuredDocument structuredDocument = cssModel.getStructuredDocument();
if (structuredDocument != null) {
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, region, stgy);
CompoundRegion[] outside = getOutsideRegions(structuredDocument, region);
for (int i = 0; i < regions.length; i++) {
if (i != 0 || needS(outside[0]))
appendSpaceBefore(node, regions[i], source);
// must
source.append(decoratedRegion(regions[i], 0, stgy));
// be
// comments
}
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
if (needS(outside[1])) {
if (((IndexedRegion) child).getStartOffset() == region.getOffset() + region.getLength() && preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_ONE_PER_LINE) && (node.getOwnerDocument() != node || !preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_PROHIBIT_WRAP_ON_ATTR))) {
appendDelimBefore(node, null, source);
} else
appendSpaceBefore(node, toAppend, source);
}
}
}
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class DefaultCSSSourceFormatter method appendSpaceBetween.
/**
*/
protected void appendSpaceBetween(ICSSNode node, CompoundRegion prev, CompoundRegion next, StringBuffer source) {
if (isCleanup() && !getCleanupStrategy(node).isFormatSource())
// for not formatting case on cleanup action
return;
final Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
// in selector
String prevType = prev.getType();
String nextType = next.getType();
if (prevType == CSSRegionContexts.CSS_PAGE || prevType == CSSRegionContexts.CSS_CHARSET || prevType == CSSRegionContexts.CSS_ATKEYWORD || prevType == CSSRegionContexts.CSS_FONT_FACE || prevType == CSSRegionContexts.CSS_IMPORT || prevType == CSSRegionContexts.CSS_MEDIA) {
appendSpaceBefore(node, next, source);
return;
}
if (prevType == CSSRegionContexts.CSS_UNKNOWN && nextType != CSSRegionContexts.CSS_COMMENT) {
if (prev.getEndOffset() != next.getStartOffset()) {
// not
// sequential
appendSpaceBefore(node, next, source);
}
return;
}
if (prevType == CSSRegionContexts.CSS_DECLARATION_VALUE_OPERATOR || prevType == CSSRegionContexts.CSS_COMMENT || nextType == CSSRegionContexts.CSS_COMMENT || nextType == CSSRegionContexts.CSS_LBRACE || nextType == CSSRegionContexts.CSS_UNKNOWN || (prevType == CSSRegionContexts.CSS_SELECTOR_SEPARATOR && preferences.getBoolean(CSSCorePreferenceNames.FORMAT_SPACE_BETWEEN_SELECTORS))) {
appendSpaceBefore(node, next, source);
return;
}
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class NewDTDWizard method addDefaultExtension.
/**
* Adds default extension to the filename
*
* @param filename
* @return
*/
String addDefaultExtension(String filename) {
StringBuffer newFileName = new StringBuffer(filename);
Preferences preference = DTDCorePlugin.getInstance().getPluginPreferences();
String ext = preference.getString(DTDCorePreferenceNames.DEFAULT_EXTENSION);
// $NON-NLS-1$
newFileName.append(".");
newFileName.append(ext);
return newFileName.toString();
}
Aggregations