Search in sources :

Example 96 with CodeStyleSettings

use of com.intellij.psi.codeStyle.CodeStyleSettings in project idea-handlebars by dmarcotte.

the class HbFormatterIndentTest method testFormattingInsideDoNotIndentElems1.

public void testFormattingInsideDoNotIndentElems1() {
    CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
    settings.HTML_DO_NOT_INDENT_CHILDREN_OF = "body";
    doStringBasedTest("<body>\n" + "{{#foo}}\n" + "<div></div>\n" + "{{/foo}}\n" + "</body>", "<body>\n" + "{{#foo}}\n" + "    <div></div>\n" + "{{/foo}}\n" + "</body>");
}
Also used : CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings)

Example 97 with CodeStyleSettings

use of com.intellij.psi.codeStyle.CodeStyleSettings in project ideavim by JetBrains.

the class ChangeGroup method indentRange.

public void indentRange(@NotNull Editor editor, @NotNull DataContext context, @NotNull TextRange range, int count, int dir) {
    if (logger.isDebugEnabled()) {
        logger.debug("count=" + count);
    }
    // API change - don't merge
    Project proj = PlatformDataKeys.PROJECT.getData(context);
    int tabSize = 8;
    int indentSize = 8;
    boolean useTabs = true;
    VirtualFile file = EditorData.getVirtualFile(editor);
    if (file != null) {
        FileType type = FileTypeManager.getInstance().getFileTypeByFile(file);
        CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(proj);
        tabSize = settings.getTabSize(type);
        indentSize = settings.getIndentSize(type);
        useTabs = settings.useTabCharacter(type);
    }
    int sline = editor.offsetToLogicalPosition(range.getStartOffset()).line;
    int eline = editor.offsetToLogicalPosition(range.getEndOffset()).line;
    if (range.isMultiple()) {
        int col = editor.offsetToLogicalPosition(range.getStartOffset()).column;
        int size = indentSize * count;
        if (dir == 1) {
            // Right shift blockwise selection
            StringBuilder space = new StringBuilder();
            int tabCnt = 0;
            int spcCnt;
            if (useTabs) {
                tabCnt = size / tabSize;
                spcCnt = size % tabSize;
            } else {
                spcCnt = size;
            }
            for (int i = 0; i < tabCnt; i++) {
                space.append('\t');
            }
            for (int i = 0; i < spcCnt; i++) {
                space.append(' ');
            }
            for (int l = sline; l <= eline; l++) {
                int len = EditorHelper.getLineLength(editor, l);
                if (len > col) {
                    LogicalPosition spos = new LogicalPosition(l, col);
                    insertText(editor, editor.logicalPositionToOffset(spos), space.toString());
                }
            }
        } else {
            // Left shift blockwise selection
            CharSequence chars = editor.getDocument().getCharsSequence();
            for (int l = sline; l <= eline; l++) {
                int len = EditorHelper.getLineLength(editor, l);
                if (len > col) {
                    LogicalPosition spos = new LogicalPosition(l, col);
                    LogicalPosition epos = new LogicalPosition(l, col + size - 1);
                    int wsoff = editor.logicalPositionToOffset(spos);
                    int weoff = editor.logicalPositionToOffset(epos);
                    int pos;
                    for (pos = wsoff; pos <= weoff; pos++) {
                        if (CharacterHelper.charType(chars.charAt(pos), false) != CharacterHelper.CharacterType.WHITESPACE) {
                            break;
                        }
                    }
                    if (pos > wsoff) {
                        deleteText(editor, new TextRange(wsoff, pos), null);
                    }
                }
            }
        }
    } else {
        // Shift non-blockwise selection
        for (int l = sline; l <= eline; l++) {
            int soff = EditorHelper.getLineStartOffset(editor, l);
            int eoff = EditorHelper.getLineEndOffset(editor, l, true);
            int woff = VimPlugin.getMotion().moveCaretToLineStartSkipLeading(editor, l);
            int col = editor.offsetToVisualPosition(woff).column;
            int newCol = Math.max(0, col + dir * indentSize * count);
            if (col > 0 || soff != eoff) {
                StringBuilder space = new StringBuilder();
                int tabCnt = 0;
                int spcCnt;
                if (useTabs) {
                    tabCnt = newCol / tabSize;
                    spcCnt = newCol % tabSize;
                } else {
                    spcCnt = newCol;
                }
                for (int i = 0; i < tabCnt; i++) {
                    space.append('\t');
                }
                for (int i = 0; i < spcCnt; i++) {
                    space.append(' ');
                }
                replaceText(editor, soff, woff, space.toString());
            }
        }
    }
    if (!CommandState.inInsertMode(editor)) {
        if (!range.isMultiple()) {
            MotionGroup.moveCaret(editor, VimPlugin.getMotion().moveCaretToLineStartSkipLeading(editor, sline));
        } else {
            MotionGroup.moveCaret(editor, range.getStartOffset());
        }
    }
    EditorData.setLastColumn(editor, editor.getCaretModel().getVisualPosition().column);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) FileType(com.intellij.openapi.fileTypes.FileType) TextRange(com.maddyhome.idea.vim.common.TextRange)

Example 98 with CodeStyleSettings

use of com.intellij.psi.codeStyle.CodeStyleSettings in project android by JetBrains.

the class GradleSpecificInitializer method run.

@Override
public void run() {
    setUpNewProjectActions();
    setUpWelcomeScreenActions();
    replaceProjectPopupActions();
    checkInstallPath();
    ActionManager actionManager = ActionManager.getInstance();
    // "Configure Plugins..." Not sure why it's called StartupWizard.
    AnAction pluginAction = actionManager.getAction("StartupWizard");
    // Never applicable in the context of android studio, so just set to invisible.
    pluginAction.getTemplatePresentation().setVisible(false);
    if (AndroidSdkUtils.isAndroidSdkManagerEnabled()) {
        try {
            // Setup JDK and Android SDK if necessary
            setupSdks();
            checkAndroidSdkHome();
        } catch (Exception e) {
            LOG.error("Unexpected error while setting up SDKs: ", e);
        }
        checkAndSetAndroidSdkSources();
    }
    registerAppClosing();
    // Always reset the Default scheme to match Android standards
    // User modifications won't be lost since they are made in a separate scheme (copied off of this default scheme)
    CodeStyleScheme scheme = CodeStyleSchemes.getInstance().getDefaultScheme();
    if (scheme != null) {
        CodeStyleSettings settings = scheme.getCodeStyleSettings();
        if (settings != null) {
            AndroidCodeStyleSettingsModifier.modify(settings);
        }
    }
}
Also used : CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) CodeStyleScheme(com.intellij.psi.codeStyle.CodeStyleScheme) IOException(java.io.IOException)

Example 99 with CodeStyleSettings

use of com.intellij.psi.codeStyle.CodeStyleSettings in project intellij-plugins by JetBrains.

the class FlexCssCompletionTest method setUp.

@Override
protected void setUp() throws Exception {
    VfsRootAccess.allowRootAccess(getTestRootDisposable(), urlToPath(convertFromUrl(FlexSchemaHandler.class.getResource("z.xsd"))), urlToPath(convertFromUrl(FlexStylesIndexableSetContributor.class.getResource("FlexStyles.as"))));
    super.setUp();
    myAfterCommitRunnable = null;
    CodeStyleSettings globalSettings = CodeStyleSettingsManager.getSettings(getProject());
    CssCodeStyleSettings settings = globalSettings.getCustomSettings(CssCodeStyleSettings.class);
    settings.SPACE_AFTER_COLON = false;
    CamelHumpMatcher.forceStartMatching(getTestRootDisposable());
}
Also used : CssCodeStyleSettings(com.intellij.psi.css.codeStyle.CssCodeStyleSettings) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) CssCodeStyleSettings(com.intellij.psi.css.codeStyle.CssCodeStyleSettings) FlexSchemaHandler(com.intellij.javascript.flex.mxml.schema.FlexSchemaHandler) FlexStylesIndexableSetContributor(com.intellij.javascript.flex.css.FlexStylesIndexableSetContributor)

Example 100 with CodeStyleSettings

use of com.intellij.psi.codeStyle.CodeStyleSettings in project intellij-plugins by JetBrains.

the class CfmlFormatterTest method setTestStyleSettings.

private void setTestStyleSettings() {
    Project project = getProject();
    CodeStyleSettings currSettings = CodeStyleSettingsManager.getSettings(project);
    Assert.assertNotNull(currSettings);
    CodeStyleSettings tempSettings = currSettings.clone();
    CodeStyleSettings.IndentOptions indentOptions = tempSettings.getIndentOptions(CfmlFileType.INSTANCE);
    Assert.assertNotNull(indentOptions);
    defineStyleSettings(tempSettings);
    CodeStyleSettingsManager.getInstance(project).setTemporarySettings(tempSettings);
}
Also used : Project(com.intellij.openapi.project.Project) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings)

Aggregations

CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)190 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)84 Project (com.intellij.openapi.project.Project)12 XmlCodeStyleSettings (com.intellij.psi.formatter.xml.XmlCodeStyleSettings)12 ECMA4CodeStyleSettings (com.intellij.lang.javascript.formatter.ECMA4CodeStyleSettings)9 JSCodeStyleSettings (com.intellij.lang.javascript.formatter.JSCodeStyleSettings)9 Document (com.intellij.openapi.editor.Document)9 JavaCodeStyleSettings (com.intellij.psi.codeStyle.JavaCodeStyleSettings)9 NotNull (org.jetbrains.annotations.NotNull)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 PsiFile (com.intellij.psi.PsiFile)5 Nullable (org.jetbrains.annotations.Nullable)5 FormattingModel (com.intellij.formatting.FormattingModel)4 PsiElement (com.intellij.psi.PsiElement)4 CodeStyleSettingsManager (com.intellij.psi.codeStyle.CodeStyleSettingsManager)4 File (java.io.File)4 FormattingModelBuilder (com.intellij.formatting.FormattingModelBuilder)3 ASTNode (com.intellij.lang.ASTNode)3 Language (com.intellij.lang.Language)3 JSTestOptions (com.intellij.lang.javascript.JSTestOptions)3