Search in sources :

Example 31 with Preferences

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

the class StructuredAutoEditStrategyCSS method getIndentString.

private String getIndentString() {
    StringBuffer indent = new StringBuffer();
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    if (preferences != null) {
        char indentChar = ' ';
        String indentCharPref = preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR);
        if (CSSCorePreferenceNames.TAB.equals(indentCharPref)) {
            indentChar = '\t';
        }
        int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE);
        for (int i = 0; i < indentationWidth; i++) {
            indent.append(indentChar);
        }
    }
    return indent.toString();
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 32 with Preferences

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

the class StructuredAutoEditStrategyCSS method smartInsertForTab.

/**
 * Insert spaces for tabs
 *
 * @param command
 */
private void smartInsertForTab(DocumentCommand command, IDocument document) {
    // tab key was pressed. now check preferences to see if need to insert
    // spaces instead of tab
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    if (CSSCorePreferenceNames.SPACE.equals(preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR))) {
        int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE);
        StringBuffer indent = new StringBuffer();
        if (indentationWidth != 0) {
            int indentSize = indentationWidth;
            try {
                IRegion firstLine = document.getLineInformationOfOffset(command.offset);
                int offsetInLine = command.offset - firstLine.getOffset();
                int remainder = offsetInLine % indentationWidth;
                indentSize = indentationWidth - remainder;
            } catch (BadLocationException e) {
                Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
            }
            for (int i = 0; i < indentSize; i++) indent.append(' ');
        }
        // replace \t characters with spaces
        command.text = indent.toString();
    }
}
Also used : Preferences(org.eclipse.core.runtime.Preferences) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 33 with Preferences

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

the class CSSProposalGenerator method generateBraces.

/**
 */
protected StringAndOffset generateBraces() {
    StringBuffer buf = new StringBuffer();
    String lineDelimiter = fContext.getStructuredDocument().getLineDelimiter();
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    String indentStr = getIndentString();
    if (preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_NEWLINE_ON_OPEN_BRACE)) {
        buf.append(lineDelimiter);
    }
    // $NON-NLS-1$
    buf.append("{");
    if (preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_ONE_PER_LINE)) {
        buf.append(lineDelimiter);
        buf.append(indentStr);
    } else {
        // $NON-NLS-1$
        buf.append(" ");
    }
    int offset = buf.length();
    if (preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_ONE_PER_LINE)) {
        buf.append(lineDelimiter);
    } else {
        // $NON-NLS-1$
        buf.append(" ");
    }
    // $NON-NLS-1$
    buf.append("}");
    return new StringAndOffset(buf.toString(), offset);
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 34 with Preferences

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

the class StructuredTextViewerConfigurationCSS method getIndentPrefixes.

public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
    Vector vector = new Vector();
    // prefix[0] is either '\t' or ' ' x tabWidth, depending on preference
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE);
    String indentCharPref = preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR);
    boolean useSpaces = CSSCorePreferenceNames.SPACE.equals(indentCharPref);
    for (int i = 0; i <= indentationWidth; i++) {
        StringBuffer prefix = new StringBuffer();
        boolean appendTab = false;
        if (useSpaces) {
            for (int j = 0; j + i < indentationWidth; j++) prefix.append(' ');
            if (i != 0)
                appendTab = true;
        } else {
            for (int j = 0; j < i; j++) prefix.append(' ');
            if (i != indentationWidth)
                appendTab = true;
        }
        if (appendTab) {
            prefix.append('\t');
            vector.add(prefix.toString());
            // remove the tab so that indentation - tab is also an indent
            // prefix
            prefix.deleteCharAt(prefix.length() - 1);
        }
        vector.add(prefix.toString());
    }
    // $NON-NLS-1$
    vector.add("");
    return (String[]) vector.toArray(new String[vector.size()]);
}
Also used : Preferences(org.eclipse.core.runtime.Preferences) Vector(java.util.Vector)

Example 35 with Preferences

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

the class CSSSourcePreferencePage method performDefaultsForFormattingGroup.

private void performDefaultsForFormattingGroup() {
    // Formatting
    Preferences prefs = getModelPreferences();
    fLineWidthText.setText(prefs.getDefaultString(CSSCorePreferenceNames.LINE_WIDTH));
    fPropertyPerLine.setSelection(prefs.getDefaultBoolean(CSSCorePreferenceNames.WRAPPING_ONE_PER_LINE));
    fNowrapAttr.setSelection(prefs.getDefaultBoolean(CSSCorePreferenceNames.WRAPPING_PROHIBIT_WRAP_ON_ATTR));
    spaceBetweenSelectors.setSelection(prefs.getDefaultBoolean(CSSCorePreferenceNames.FORMAT_SPACE_BETWEEN_SELECTORS));
    if (CSSCorePreferenceNames.TAB.equals(getModelPreferences().getDefaultString(CSSCorePreferenceNames.INDENTATION_CHAR))) {
        fIndentUsingTabs.setSelection(true);
        fIndentUsingSpaces.setSelection(false);
    } else {
        fIndentUsingSpaces.setSelection(true);
        fIndentUsingTabs.setSelection(false);
    }
    fIndentationSize.setSelection(getModelPreferences().getDefaultInt(CSSCorePreferenceNames.INDENTATION_SIZE));
}
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