Search in sources :

Example 6 with IStructuredDocument

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.

the class StyleDeclItemFormatter 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]))
            appendSpaceBefore(node, regions[i], source);
        source.append(decoratedIdentRegion(regions[i], stgy));
    }
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 7 with IStructuredDocument

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

Example 8 with IStructuredDocument

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.

the class UnknownRuleFormatter 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(decoratedPropValueRegion(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 9 with IStructuredDocument

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.

the class CSSStyleSheetImpl method insertRule.

/**
 * Used to insert a new rule into the style sheet. The new rule now
 * becomes part of the cascade.
 *
 * @param rule
 *            The parsable text representing the rule. For rule sets this
 *            contains both the selector and the style declaration. For
 *            at-rules, this specifies both the at-identifier and the rule
 *            content.
 * @param index
 *            The index within the style sheet's rule list of the rule
 *            before which to insert the specified rule. If the specified
 *            index is equal to the length of the style sheet's rule
 *            collection, the rule will be added to the end of the style
 *            sheet.
 * @return The index within the style sheet's rule collection of the newly
 *         inserted rule.
 * @exception DOMException
 *                HIERARCHY_REQUEST_ERR: Raised if the rule cannot be
 *                inserted at the specified index e.g. if an
 *                <code>@import</code> rule is inserted after a standard rule set or other
 *         at-rule. <br>
 *         INDEX_SIZE_ERR: Raised if the specified index is not a valid
 *         insertion point. <br>
 *         NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is
 *         readonly. <br>
 *         SYNTAX_ERR: Raised if the specified rule has a syntax error and
 *         is unparsable.
 */
public int insertRule(String rule, int index) throws DOMException {
    int length = getCssRules().getLength();
    if (index < 0 || length < index)
        // $NON-NLS-1$
        throw new DOMException(DOMException.INDEX_SIZE_ERR, "");
    IStructuredDocument doc = getModel().getStructuredDocument();
    CSSRuleImpl refRule = (length != index) ? getIndexedRule(index) : null;
    int offset = (refRule != null) ? refRule.getStartOffset() : doc.getLength();
    doc.replaceText(this, offset, 0, rule);
    // insertBefore((CSSNodeImpl) createCSSRule(rule),refRule);
    return index;
}
Also used : DOMException(org.w3c.dom.DOMException) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 10 with IStructuredDocument

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.

the class CSSModelUpdater method removeText.

/**
 */
private StructuredDocumentEvent removeText(int start, int length) {
    StructuredDocumentEvent result = null;
    IStructuredDocument structuredDocument = fModel.getStructuredDocument();
    if (structuredDocument != null) {
        // $NON-NLS-1$
        result = structuredDocument.replaceText(fModel, start, length, new String(""));
    }
    return result;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Aggregations

IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)432 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)96 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)79 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)68 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)44 Node (org.w3c.dom.Node)42 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)41 Document (org.w3c.dom.Document)36 BadLocationException (org.eclipse.jface.text.BadLocationException)35 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)34 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)34 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)33 Element (org.w3c.dom.Element)30 IDocument (org.eclipse.jface.text.IDocument)29 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)28 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)26 StructuredDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)23 Test (org.junit.Test)22 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)20 RegionChangedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent)20