Search in sources :

Example 21 with CSSCleanupStrategy

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

the class StyleSheetFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, IRegion region, java.lang.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]) || regions[i].getType() == CSSRegionContexts.CSS_CDO || node.getOwnerDocument().getModel().getStyleSheetType() == ICSSModel.EMBEDDED)
            appendDelimBefore(node, regions[i], source);
        source.append(decoratedRegion(regions[i], 0, stgy));
    }
    if (needS(outside[1])) {
        if (isIncludesPreEnd(node, region)) {
            if (source.length() > 0 || node.getOwnerDocument().getModel().getStyleSheetType() == ICSSModel.EMBEDDED) {
                String delim = getLineDelimiter(node);
                source.append(delim);
            }
        }
    }
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 22 with CSSCleanupStrategy

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

the class StyleSheetFormatter method formatPre.

/**
 */
protected void formatPre(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode node, java.lang.StringBuffer source) {
    int start = ((IndexedRegion) node).getStartOffset();
    int end = (node.getFirstChild() != null && ((IndexedRegion) node.getFirstChild()).getEndOffset() > 0) ? ((IndexedRegion) node.getFirstChild()).getStartOffset() : getChildInsertPos(node);
    if (end > 0) {
        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 || regions[i].getType() == CSSRegionContexts.CSS_CDO || node.getOwnerDocument().getModel().getStyleSheetType() == ICSSModel.EMBEDDED)
                appendDelimBefore(node, regions[i], source);
            source.append(decoratedRegion(regions[i], 0, stgy));
        }
        if (node.getLastChild() != null && (source.length() > 0 || node.getOwnerDocument().getModel().getStyleSheetType() == ICSSModel.EMBEDDED)) {
            appendDelimBefore(node, null, source);
        }
    } else if (node.getOwnerDocument().getModel() != null && node.getOwnerDocument().getModel().getStyleSheetType() == ICSSModel.EMBEDDED) {
        appendDelimBefore(node, null, source);
    // source.append("<!--");
    // appendDelimBefore(node,null, source);
    } else
        // nothing
        return;
}
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 23 with CSSCleanupStrategy

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

the class StyleSheetFormatter method formatPost.

/**
 */
protected void formatPost(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]))
            appendDelimBefore(node, regions[i], source);
        source.append(decoratedRegion(regions[i], 0, stgy));
    }
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 24 with CSSCleanupStrategy

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

the class CleanupDialogCSS method setCleanupOptions.

/**
 */
protected void setCleanupOptions() {
    CSSCleanupStrategy stgy = CSSCleanupStrategyImpl.getInstance();
    if (fRadioButtonIdentCaseAsis != null) {
        if (stgy.getIdentCase() == CSSCleanupStrategy.UPPER)
            fRadioButtonIdentCaseUpper.setSelection(true);
        else if (stgy.getIdentCase() == CSSCleanupStrategy.LOWER)
            fRadioButtonIdentCaseLower.setSelection(true);
        else
            fRadioButtonIdentCaseAsis.setSelection(true);
    }
    if (fRadioButtonPropNameCaseAsis != null) {
        if (stgy.getPropNameCase() == CSSCleanupStrategy.UPPER)
            fRadioButtonPropNameCaseUpper.setSelection(true);
        else if (stgy.getPropNameCase() == CSSCleanupStrategy.LOWER)
            fRadioButtonPropNameCaseLower.setSelection(true);
        else
            fRadioButtonPropNameCaseAsis.setSelection(true);
    }
    if (fRadioButtonPropValueCaseAsis != null) {
        if (stgy.getPropValueCase() == CSSCleanupStrategy.UPPER)
            fRadioButtonPropValueCaseUpper.setSelection(true);
        else if (stgy.getPropValueCase() == CSSCleanupStrategy.LOWER)
            fRadioButtonPropValueCaseLower.setSelection(true);
        else
            fRadioButtonPropValueCaseAsis.setSelection(true);
    }
    if (fRadioButtonSelectorTagCaseAsis != null) {
        if (stgy.getSelectorTagCase() == CSSCleanupStrategy.UPPER)
            fRadioButtonSelectorTagCaseUpper.setSelection(true);
        else if (stgy.getSelectorTagCase() == CSSCleanupStrategy.LOWER)
            fRadioButtonSelectorTagCaseLower.setSelection(true);
        else
            fRadioButtonSelectorTagCaseAsis.setSelection(true);
    }
    if (fRadioButtonSelectorIdCaseAsis != null) {
        if (stgy.getIdSelectorCase() == CSSCleanupStrategy.UPPER)
            fRadioButtonSelectorIdCaseUpper.setSelection(true);
        else if (stgy.getIdSelectorCase() == CSSCleanupStrategy.LOWER)
            fRadioButtonSelectorIdCaseLower.setSelection(true);
        else
            fRadioButtonSelectorIdCaseAsis.setSelection(true);
    }
    if (fRadioButtonSelectorClassCaseAsis != null) {
        if (stgy.getClassSelectorCase() == CSSCleanupStrategy.UPPER)
            fRadioButtonSelectorClassCaseUpper.setSelection(true);
        else if (stgy.getClassSelectorCase() == CSSCleanupStrategy.LOWER)
            fRadioButtonSelectorClassCaseLower.setSelection(true);
        else
            fRadioButtonSelectorClassCaseAsis.setSelection(true);
    }
    if (fCheckBoxQuoteValues != null)
        fCheckBoxQuoteValues.setSelection(stgy.isQuoteValues());
    if (fCheckBoxFormatSource != null)
        fCheckBoxFormatSource.setSelection(stgy.isFormatSource());
}
Also used : CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 25 with CSSCleanupStrategy

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

the class CleanupDialogCSS method updateCleanupOptions.

/**
 */
protected void updateCleanupOptions() {
    CSSCleanupStrategy stgy = CSSCleanupStrategyImpl.getInstance();
    if (fRadioButtonIdentCaseAsis != null) {
        if (fRadioButtonIdentCaseUpper.getSelection())
            stgy.setIdentCase(CSSCleanupStrategy.UPPER);
        else if (fRadioButtonIdentCaseLower.getSelection())
            stgy.setIdentCase(CSSCleanupStrategy.LOWER);
        else
            stgy.setIdentCase(CSSCleanupStrategy.ASIS);
    }
    if (fRadioButtonPropNameCaseAsis != null) {
        if (fRadioButtonPropNameCaseUpper.getSelection())
            stgy.setPropNameCase(CSSCleanupStrategy.UPPER);
        else if (fRadioButtonPropNameCaseLower.getSelection())
            stgy.setPropNameCase(CSSCleanupStrategy.LOWER);
        else
            stgy.setPropNameCase(CSSCleanupStrategy.ASIS);
    }
    if (fRadioButtonPropValueCaseAsis != null) {
        if (fRadioButtonPropValueCaseUpper.getSelection())
            stgy.setPropValueCase(CSSCleanupStrategy.UPPER);
        else if (fRadioButtonPropValueCaseLower.getSelection())
            stgy.setPropValueCase(CSSCleanupStrategy.LOWER);
        else
            stgy.setPropValueCase(CSSCleanupStrategy.ASIS);
    }
    if (fRadioButtonSelectorTagCaseAsis != null) {
        if (fRadioButtonSelectorTagCaseUpper.getSelection())
            stgy.setSelectorTagCase(CSSCleanupStrategy.UPPER);
        else if (fRadioButtonSelectorTagCaseLower.getSelection())
            stgy.setSelectorTagCase(CSSCleanupStrategy.LOWER);
        else
            stgy.setSelectorTagCase(CSSCleanupStrategy.ASIS);
    }
    if (fRadioButtonSelectorIdCaseAsis != null) {
        if (fRadioButtonSelectorIdCaseUpper.getSelection())
            stgy.setIdSelectorCase(CSSCleanupStrategy.UPPER);
        else if (fRadioButtonSelectorIdCaseLower.getSelection())
            stgy.setIdSelectorCase(CSSCleanupStrategy.LOWER);
        else
            stgy.setIdSelectorCase(CSSCleanupStrategy.ASIS);
    }
    if (fRadioButtonSelectorClassCaseAsis != null) {
        if (fRadioButtonSelectorClassCaseUpper.getSelection())
            stgy.setClassSelectorCase(CSSCleanupStrategy.UPPER);
        else if (fRadioButtonSelectorClassCaseLower.getSelection())
            stgy.setClassSelectorCase(CSSCleanupStrategy.LOWER);
        else
            stgy.setClassSelectorCase(CSSCleanupStrategy.ASIS);
    }
    if (fCheckBoxQuoteValues != null)
        stgy.setQuoteValues(fCheckBoxQuoteValues.getSelection());
    if (fCheckBoxFormatSource != null)
        stgy.setFormatSource(fCheckBoxFormatSource.getSelection());
    // save these values to preferences
    ((CSSCleanupStrategyImpl) stgy).saveOptions();
}
Also used : CSSCleanupStrategyImpl(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategyImpl) 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