Search in sources :

Example 1 with ICounter

use of org.eclipse.wst.css.core.internal.provisional.document.ICounter in project webtools.sourceediting by eclipse.

the class CounterFormatter method formatAttrChanged.

/**
 */
public StringBuffer formatAttrChanged(ICSSNode node, ICSSAttr attr, boolean insert, AttrChangeContext context) {
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    StringBuffer source = new StringBuffer();
    if (node == null || attr == null)
        return source;
    if (!ICounter.IDENTIFIER.equalsIgnoreCase(attr.getName()) && !ICounter.LISTSTYLE.equalsIgnoreCase(attr.getName()) && !ICounter.SEPARATOR.equalsIgnoreCase(attr.getName()))
        return source;
    // get region to replace
    IndexedRegion iNode = (IndexedRegion) node;
    context.start = iNode.getStartOffset();
    context.end = iNode.getEndOffset();
    ICounter counter = (ICounter) node;
    String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
    String sep = counter.getSeparator();
    String ident = counter.getIdentifier();
    String style = counter.getListStyle();
    if (ICounter.IDENTIFIER.equalsIgnoreCase(attr.getName())) {
        if (insert)
            ident = attr.getValue();
        else
            // $NON-NLS-1$
            ident = "";
    } else if (ICounter.LISTSTYLE.equalsIgnoreCase(attr.getName())) {
        if (insert)
            style = attr.getValue();
        else
            style = null;
    } else if (ICounter.SEPARATOR.equalsIgnoreCase(attr.getName())) {
        if (insert)
            sep = attr.getValue();
        else
            sep = null;
    }
    quote = CSSUtil.detectQuote(sep, quote);
    sep = (sep == null || sep.length() == 0) ? null : (quote + sep + quote);
    // $NON-NLS-2$//$NON-NLS-1$
    String func = (sep == null || sep.length() == 0) ? "counter(" : "counters(";
    if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER) {
        ident = ident.toUpperCase();
        style = style.toUpperCase();
        func = func.toUpperCase();
    } else {
        ident = ident.toLowerCase();
        style = style.toLowerCase();
    }
    if (sep == null || sep.length() == 0) {
        source.append(func);
        appendSpaceBefore(node, ident, source);
        source.append(ident);
    } else {
        source.append(func);
        appendSpaceBefore(node, ident, source);
        source.append(ident);
        // $NON-NLS-1$
        source.append(",");
        appendSpaceBefore(node, sep, source);
        source.append(sep);
    }
    if (style != null && style.length() != 0) {
        // $NON-NLS-1$
        source.append(",");
        appendSpaceBefore(node, style, source);
    }
    // $NON-NLS-1$
    source.append(")");
    /*
		 * IStructuredDocument structuredDocument =
		 * node.getOwnerDocument().getModel().getStructuredDocument();
		 * ITextRegion[] regions =
		 * getRegionsWithoutWhiteSpaces(structuredDocument, new
		 * FormatRegion(context.start, context.end - context.start + 1)); int
		 * commas[2]; int numComma = 0; for(int j = 0; j <regions.length; j++) {
		 * if (regions[j].getType() == CSSRegionContexts.COMMA) {
		 * commas[numComma++] = j; if (numComma > 1) break; } }
		 * 
		 * if (ICounter.IDENTIFIER.equalsIgnoreCase(attr.getName())) { } else
		 * if (ICounter.LISTSTYLE.equalsIgnoreCase(attr.getName())) { } else
		 * if (ICounter.SEPARATOR.equalsIgnoreCase(attr.getName())) { boolean
		 * skipSpace = false; String func = insert ? "counters(" : "counter(";
		 * if (mgr.isPropValueUpperCase()) func = func.toUpperCase();
		 * 
		 * for(int i=0; i <regions.length; i++) { if (regions[i].getType() ==
		 * CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION)
		 * source.append(func); else { if (numComma == 2 && commas[1] < i) {
		 *  } else if (numComma == 1 && commas[0] < i && insert) {
		 *  } else if (numComma == 1 && commas[0] < i && ! insert) { } else if
		 * (numComma == 0 && insert && regions[i].getType ==
		 * CSSRegionContexts.PARENTHESIS_CLOSE) { source.append(",");
		 * appendSpaceBefore(node,attr.getValue(),source);
		 * source.append(attr.getValue()); }
		 * 
		 * if (i != 0 && !skipSpace)
		 * appendSpaceBefore(node,regions[i],source);
		 * source.append(decoratedPropValueRegion(regions[i])); } skipSpace =
		 * false;
		 * 
		 * if (regions[i].getType() ==
		 * CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION) skipSpace = true; } }
		 */
    return source;
}
Also used : ICounter(org.eclipse.wst.css.core.internal.provisional.document.ICounter) Preferences(org.eclipse.core.runtime.Preferences) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 2 with ICounter

use of org.eclipse.wst.css.core.internal.provisional.document.ICounter in project webtools.sourceediting by eclipse.

the class CounterFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, StringBuffer source) {
    int start = ((IndexedRegion) node).getStartOffset();
    int end = ((IndexedRegion) node).getEndOffset();
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    CSSCleanupStrategy stgy = getCleanupStrategy(node);
    if (end > 0) {
        // format source
        IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
        CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
        boolean skipSpace = false;
        for (int i = 0; i < regions.length; i++) {
            if (i != 0 && !skipSpace)
                appendSpaceBefore(node, regions[i], source);
            skipSpace = false;
            source.append(decoratedPropValueRegion(regions[i], stgy));
            if (regions[i].getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION)
                skipSpace = true;
        }
    } else {
        // generate source
        ICounter counter = (ICounter) node;
        String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
        String separator = counter.getSeparator();
        quote = CSSUtil.detectQuote(separator, quote);
        String sep = (separator == null || separator.length() == 0) ? null : (quote + separator + quote);
        String ident = counter.getIdentifier();
        String style = counter.getListStyle();
        // $NON-NLS-2$//$NON-NLS-1$
        String func = (sep == null || sep.length() == 0) ? "counter(" : "counters(";
        // normalize
        if (ident == null)
            // $NON-NLS-1$
            ident = "";
        if (style == null)
            // $NON-NLS-1$
            style = "";
        if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER) {
            ident = ident.toUpperCase();
            style = style.toUpperCase();
            func = func.toUpperCase();
        } else {
            ident = ident.toLowerCase();
            style = style.toLowerCase();
        }
        if (sep == null || sep.length() == 0) {
            source.append(func);
            appendSpaceBefore(node, ident, source);
            source.append(ident);
        } else {
            source.append(func);
            appendSpaceBefore(node, ident, source);
            source.append(ident);
            // $NON-NLS-1$
            source.append(",");
            appendSpaceBefore(node, sep, source);
            source.append(sep);
        }
        if (style != null && style.length() != 0) {
            // $NON-NLS-1$
            source.append(",");
            appendSpaceBefore(node, style, source);
        }
        // $NON-NLS-1$
        source.append(")");
    }
}
Also used : ICounter(org.eclipse.wst.css.core.internal.provisional.document.ICounter) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Preferences(org.eclipse.core.runtime.Preferences) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Aggregations

Preferences (org.eclipse.core.runtime.Preferences)2 ICounter (org.eclipse.wst.css.core.internal.provisional.document.ICounter)2 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)2 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1