Search in sources :

Example 16 with CSSCleanupStrategy

use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.

the class MediaListFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, StringBuffer source) {
    CSSCleanupStrategy stgy = getCleanupStrategy(node);
    int start = ((IndexedRegion) node).getStartOffset();
    int end = ((IndexedRegion) node).getEndOffset();
    if (end > 0) {
        // format source
        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(decoratedIdentRegion(regions[i], stgy));
        }
    } else {
        // generate source
        MediaList list = (MediaList) node;
        int n = list.getLength();
        for (int i = 0; i < n; i++) {
            String medium = list.item(i);
            if (CSSCorePlugin.getDefault().getPluginPreferences().getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
                medium = medium.toUpperCase();
            else
                medium = medium.toLowerCase();
            if (i != 0) {
                // $NON-NLS-1$
                source.append(",");
                appendSpaceBefore(node, medium, source);
            }
            source.append(medium);
        }
    }
}
Also used : MediaList(org.w3c.dom.stylesheets.MediaList) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 17 with CSSCleanupStrategy

use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.

the class MediaListFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, IRegion region, StringBuffer source) {
    CSSCleanupStrategy stgy = getCleanupStrategy(node);
    IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
    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);
        source.append(decoratedIdentRegion(regions[i], stgy));
    }
    if (needS(outside[1]) && !isIncludesPreEnd(node, region))
        appendSpaceBefore(node, outside[1], source);
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 18 with CSSCleanupStrategy

use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.

the class PageRuleFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, IRegion region, StringBuffer source) {
    CSSCleanupStrategy stgy = getCleanupStrategy(node);
    IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
    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]))
            appendSpaceBetween(node, (i == 0) ? outside[0] : regions[i - 1], regions[i], source);
        source.append(decoratedIdentRegion(regions[i], stgy));
    }
    if (needS(outside[1])) {
        if (isIncludesPreEnd(node, region))
            appendDelimBefore(node, null, source);
        else
            appendSpaceBetween(node, regions[regions.length - 1], outside[1], source);
    }
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 19 with CSSCleanupStrategy

use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.

the class PageRuleFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, StringBuffer source) {
    CSSCleanupStrategy stgy = getCleanupStrategy(node);
    int start = ((IndexedRegion) node).getStartOffset();
    int end = (node.getFirstChild() != null && ((IndexedRegion) node.getFirstChild()).getEndOffset() > 0) ? ((IndexedRegion) node.getFirstChild()).getStartOffset() : getChildInsertPos(node);
    if (end > 0) {
        // format source
        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)
                appendSpaceBetween(node, regions[i - 1], regions[i], source);
            source.append(decoratedIdentRegion(regions[i], stgy));
        }
    } else {
        // generate source
        String str = PAGE;
        if (CSSCorePlugin.getDefault().getPluginPreferences().getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
            str = PAGE.toUpperCase();
        source.append(str);
        str = ((ICSSPageRule) node).getSelectorText();
        if (str != null && str.length() > 0) {
            appendSpaceBefore(node, str, source);
            source.append(str);
        }
        // $NON-NLS-1$
        appendSpaceBefore(node, "{", source);
        // $NON-NLS-1$
        source.append("{");
    }
    appendDelimBefore(node, null, source);
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 20 with CSSCleanupStrategy

use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy 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);
            }
        }
    }
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Preferences(org.eclipse.core.runtime.Preferences) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Aggregations

CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)50 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)44 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)20 Preferences (org.eclipse.core.runtime.Preferences)6 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)5 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)3 MediaList (org.w3c.dom.stylesheets.MediaList)3 ICSSAttr (org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr)2 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)2 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)2 CSSCleanupStrategyImpl (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategyImpl)1 CSSRegionContainer (org.eclipse.wst.css.core.internal.document.CSSRegionContainer)1 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)1 ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)1 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)1 ICounter (org.eclipse.wst.css.core.internal.provisional.document.ICounter)1 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)1 CSSUnknownRule (org.w3c.dom.css.CSSUnknownRule)1