Search in sources :

Example 1 with LineSeparator

use of com.intellij.util.LineSeparator in project intellij-community by JetBrains.

the class AnsiEscapeDecoder method normalizeAsciiControlCharacters.

@NotNull
private static String normalizeAsciiControlCharacters(@NotNull String text) {
    int ind = text.indexOf(BACKSPACE);
    if (ind == -1) {
        return text;
    }
    StringBuilder result = new StringBuilder();
    int i = 0;
    int guardIndex = 0;
    boolean removalFromPrevTextAttempted = false;
    while (i < text.length()) {
        LineSeparator lineSeparator = StringUtil.getLineSeparatorAt(text, i);
        if (lineSeparator != null) {
            i += lineSeparator.getSeparatorString().length();
            result.append(lineSeparator.getSeparatorString());
            guardIndex = result.length();
        } else {
            if (text.charAt(i) == BACKSPACE) {
                if (result.length() > guardIndex) {
                    result.setLength(result.length() - 1);
                } else if (guardIndex == 0) {
                    removalFromPrevTextAttempted = true;
                }
            } else {
                result.append(text.charAt(i));
            }
            i++;
        }
    }
    if (removalFromPrevTextAttempted) {
        // This workaround allows to pretty print progress splitting it into several lines:
        //  25% 1/4 build modules
        //  40% 2/4 build modules
        // instead of one single line "25% 1/4 build modules 40% 2/4 build modules"
        result.insert(0, LineSeparator.LF.getSeparatorString());
    }
    return result.toString();
}
Also used : LineSeparator(com.intellij.util.LineSeparator) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with LineSeparator

use of com.intellij.util.LineSeparator in project intellij-community by JetBrains.

the class ExternalDiffToolUtil method createTempFile.

@NotNull
private static File createTempFile(@NotNull final DocumentContent content, @NotNull FileNameInfo fileName) throws IOException {
    FileDocumentManager.getInstance().saveDocument(content.getDocument());
    LineSeparator separator = content.getLineSeparator();
    if (separator == null)
        separator = LineSeparator.getSystemLineSeparator();
    Charset charset = content.getCharset();
    if (charset == null)
        charset = Charset.defaultCharset();
    Boolean hasBom = content.hasBom();
    if (hasBom == null)
        hasBom = CharsetToolkit.getMandatoryBom(charset) != null;
    String contentData = ReadAction.compute(() -> {
        return content.getDocument().getText();
    });
    if (separator != LineSeparator.LF) {
        contentData = StringUtil.convertLineSeparators(contentData, separator.getSeparatorString());
    }
    byte[] bytes = contentData.getBytes(charset);
    byte[] bom = hasBom ? CharsetToolkit.getPossibleBom(charset) : null;
    if (bom != null) {
        bytes = ArrayUtil.mergeArrays(bom, bytes);
    }
    return createFile(bytes, fileName);
}
Also used : Charset(java.nio.charset.Charset) LineSeparator(com.intellij.util.LineSeparator) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with LineSeparator

use of com.intellij.util.LineSeparator in project intellij-community by JetBrains.

the class DiffPanelImpl method setTitles.

private void setTitles(@NotNull DiffRequest data) {
    LineSeparator sep1 = data.getContents()[0].getLineSeparator();
    LineSeparator sep2 = data.getContents()[1].getLineSeparator();
    String title1 = addReadOnly(data.getContentTitles()[0], myLeftSide.getEditor());
    String title2 = addReadOnly(data.getContentTitles()[1], myRightSide.getEditor());
    setTitle1(createComponentForTitle(title1, sep1, sep2, true));
    setTitle2(createComponentForTitle(title2, sep1, sep2, false));
}
Also used : LineSeparator(com.intellij.util.LineSeparator)

Example 4 with LineSeparator

use of com.intellij.util.LineSeparator in project intellij-community by JetBrains.

the class DiffPanelImpl method setFileContentsAreIdentical.

public void setFileContentsAreIdentical() {
    if (myTopMessageDiffPanel == null || myTopMessageDiffPanel instanceof FileContentsAreIdenticalDiffPanel) {
        LineSeparator sep1 = myData.getContent1() == null ? null : myData.getContent1().getLineSeparator();
        LineSeparator sep2 = myData.getContent2() == null ? null : myData.getContent2().getLineSeparator();
        if (LineSeparator.knownAndDifferent(sep1, sep2)) {
            myTopMessageDiffPanel = new LineSeparatorsOnlyDiffPanel();
        } else {
            myTopMessageDiffPanel = new FileContentsAreIdenticalDiffPanel();
        }
        myPanel.insertTopComponent(myTopMessageDiffPanel);
    }
}
Also used : LineSeparator(com.intellij.util.LineSeparator)

Example 5 with LineSeparator

use of com.intellij.util.LineSeparator in project intellij-community by JetBrains.

the class LineEndingsManager method applySettings.

private void applySettings(VirtualFile file) {
    if (file == null)
        return;
    if (!Utils.isEnabled(CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings()))
        return;
    final String filePath = Utils.getFilePath(myProject, file);
    final List<EditorConfig.OutPair> outPairs = SettingsProviderComponent.getInstance().getOutPairs(myProject, filePath);
    final String lineEndings = Utils.configValueForKey(outPairs, lineEndingsKey);
    if (!lineEndings.isEmpty()) {
        try {
            LineSeparator separator = LineSeparator.valueOf(lineEndings.toUpperCase(Locale.US));
            String oldSeparator = file.getDetectedLineSeparator();
            String newSeparator = separator.getSeparatorString();
            if (!StringUtil.equals(oldSeparator, newSeparator)) {
                file.setDetectedLineSeparator(newSeparator);
                if (!statusBarUpdated) {
                    statusBarUpdated = true;
                    updateStatusBar();
                }
            }
        } catch (IllegalArgumentException e) {
            Utils.invalidConfigMessage(myProject, lineEndings, lineEndingsKey, filePath);
        }
    }
}
Also used : LineSeparator(com.intellij.util.LineSeparator)

Aggregations

LineSeparator (com.intellij.util.LineSeparator)8 NotNull (org.jetbrains.annotations.NotNull)3 Charset (java.nio.charset.Charset)2 DocumentContent (com.intellij.diff.contents.DocumentContent)1 EmptyContent (com.intellij.diff.contents.EmptyContent)1 Document (com.intellij.openapi.editor.Document)1 JBLabel (com.intellij.ui.components.JBLabel)1