Search in sources :

Example 21 with Preferences

use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.

the class StyleDeclItemFormatter method appendAfterColonSpace.

/**
 */
private void appendAfterColonSpace(ICSSNode node, StringBuffer source) {
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    int n = preferences.getInt(CSSCorePreferenceNames.FORMAT_PROP_POST_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 = getFirstChildRegionLength(node);
        if (length + n + append > preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH)) {
            source.append(getLineDelimiter(node));
            source.append(getIndent(node));
            source.append(getIndentString());
            // no space is necessary
            n = 0;
        }
    }
    // no delimiter case
    while (n-- > 0) // $NON-NLS-1$
    source.append(" ");
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 22 with Preferences

use of org.eclipse.core.runtime.Preferences 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 23 with Preferences

use of org.eclipse.core.runtime.Preferences 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)

Example 24 with Preferences

use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.

the class DefaultCSSSourceFormatter method appendSpaceBetween.

/**
 */
protected void appendSpaceBetween(ICSSNode node, CompoundRegion prev, CompoundRegion next, StringBuffer source) {
    if (isCleanup() && !getCleanupStrategy(node).isFormatSource())
        // for not formatting case on cleanup action
        return;
    final Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    // in selector
    String prevType = prev.getType();
    String nextType = next.getType();
    if (prevType == CSSRegionContexts.CSS_PAGE || prevType == CSSRegionContexts.CSS_CHARSET || prevType == CSSRegionContexts.CSS_ATKEYWORD || prevType == CSSRegionContexts.CSS_FONT_FACE || prevType == CSSRegionContexts.CSS_IMPORT || prevType == CSSRegionContexts.CSS_MEDIA) {
        appendSpaceBefore(node, next, source);
        return;
    }
    if (prevType == CSSRegionContexts.CSS_UNKNOWN && nextType != CSSRegionContexts.CSS_COMMENT) {
        if (prev.getEndOffset() != next.getStartOffset()) {
            // not
            // sequential
            appendSpaceBefore(node, next, source);
        }
        return;
    }
    if (prevType == CSSRegionContexts.CSS_DECLARATION_VALUE_OPERATOR || prevType == CSSRegionContexts.CSS_COMMENT || nextType == CSSRegionContexts.CSS_COMMENT || nextType == CSSRegionContexts.CSS_LBRACE || nextType == CSSRegionContexts.CSS_UNKNOWN || (prevType == CSSRegionContexts.CSS_SELECTOR_SEPARATOR && preferences.getBoolean(CSSCorePreferenceNames.FORMAT_SPACE_BETWEEN_SELECTORS))) {
        appendSpaceBefore(node, next, source);
        return;
    }
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 25 with Preferences

use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.

the class NewDTDWizard method addDefaultExtension.

/**
 * Adds default extension to the filename
 *
 * @param filename
 * @return
 */
String addDefaultExtension(String filename) {
    StringBuffer newFileName = new StringBuffer(filename);
    Preferences preference = DTDCorePlugin.getInstance().getPluginPreferences();
    String ext = preference.getString(DTDCorePreferenceNames.DEFAULT_EXTENSION);
    // $NON-NLS-1$
    newFileName.append(".");
    newFileName.append(ext);
    return newFileName.toString();
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Aggregations

Preferences (org.eclipse.core.runtime.Preferences)113 ByteArrayInputStream (java.io.ByteArrayInputStream)7 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)7 IFile (org.eclipse.core.resources.IFile)6 PartInitException (org.eclipse.ui.PartInitException)6 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)6 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 OutputStreamWriter (java.io.OutputStreamWriter)5 IStructuredFormatPreferences (org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences)5 ArrayList (java.util.ArrayList)4 CoreException (org.eclipse.core.runtime.CoreException)4 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)4 IStructuredCleanupPreferences (org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences)4 StructuredCleanupPreferences (org.eclipse.wst.sse.core.internal.cleanup.StructuredCleanupPreferences)4 List (java.util.List)3 Vector (java.util.Vector)3 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)3 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2