Search in sources :

Example 1 with ICSSCharsetRule

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

the class CharsetRuleFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, StringBuffer source) {
    int end = ((IndexedRegion) node).getEndOffset();
    if (end > 0) {
        // format source
        int start = ((IndexedRegion) node).getStartOffset();
        formatPre(node, new FormatRegion(start, end - start), source);
    } else {
        // generate source
        Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
        String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
        String str = CHARSET;
        if (preferences.getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
            str = CHARSET.toUpperCase();
        source.append(str);
        String enc = ((ICSSCharsetRule) node).getEncoding();
        quote = CSSUtil.detectQuote(enc, quote);
        // $NON-NLS-1$ //$NON-NLS-2$
        str = quote + ((enc != null) ? enc : "") + quote + ";";
        appendSpaceBefore(node, str, source);
        source.append(str);
    }
}
Also used : ICSSCharsetRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSCharsetRule) Preferences(org.eclipse.core.runtime.Preferences) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 2 with ICSSCharsetRule

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

the class CSSProposalGeneratorForAtmarkRule method getCandidateImportRule.

/**
 */
private CSSCACandidate getCandidateImportRule() {
    // check content model
    CSSMetaModelUtil util = new CSSMetaModelUtil(fContext.getMetaModel());
    if (!util.collectNodesByType(CSSMMNode.TYPE_IMPORT_RULE).hasNext()) {
        return null;
    }
    // charset and import can precede import rule.
    int offset = fContext.getCursorPos();
    if (0 < offset) {
        SelectionCollector trav = new SelectionCollector();
        trav.setRegion(0, offset - 1);
        trav.apply(fContext.getModel().getDocument());
        Iterator i = trav.getSelectedNodes().iterator();
        while (i.hasNext()) {
            Object obj = i.next();
            if (obj instanceof ICSSNode && !(obj instanceof ICSSDocument || obj instanceof ICSSCharsetRule || obj instanceof ICSSImportRule)) {
                return null;
            }
        }
    }
    int cursorPos = 0;
    String ident = (fUseUpperCase) ? IMPORT.toUpperCase() : IMPORT.toLowerCase();
    StringBuffer buf = new StringBuffer();
    buf.append(ident);
    // $NON-NLS-1$
    buf.append(" ");
    cursorPos = buf.length();
    StringAndOffset sao;
    sao = generateURI();
    buf.append(sao.fString);
    cursorPos += sao.fOffset;
    sao = generateSemicolon();
    buf.append(sao.fString);
    String text = buf.toString();
    if (isMatch(text)) {
        CSSCACandidate item = new CSSCACandidate();
        item.setReplacementString(buf.toString());
        item.setCursorPosition(cursorPos);
        item.setDisplayString(ident);
        item.setImageType(CSSImageType.RULE_IMPORT);
        return item;
    } else {
        return null;
    }
}
Also used : CSSMetaModelUtil(org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil) ICSSCharsetRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSCharsetRule) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) Iterator(java.util.Iterator) SelectionCollector(org.eclipse.wst.css.core.internal.util.SelectionCollector) ICSSImportRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)

Aggregations

ICSSCharsetRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSCharsetRule)2 Iterator (java.util.Iterator)1 Preferences (org.eclipse.core.runtime.Preferences)1 CSSMetaModelUtil (org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil)1 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)1 ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)1 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)1 SelectionCollector (org.eclipse.wst.css.core.internal.util.SelectionCollector)1 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)1