Search in sources :

Example 6 with LineSeparator

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

the class DiffUtil method createTitle.

@Nullable
private static JComponent createTitle(@NotNull String title, @NotNull DiffContent content, boolean equalCharsets, boolean equalSeparators, @Nullable Editor editor) {
    if (content instanceof EmptyContent)
        return null;
    DocumentContent documentContent = (DocumentContent) content;
    Charset charset = equalCharsets ? null : documentContent.getCharset();
    Boolean bom = equalCharsets ? null : documentContent.hasBom();
    LineSeparator separator = equalSeparators ? null : documentContent.getLineSeparator();
    boolean isReadOnly = editor == null || editor.isViewer() || !canMakeWritable(editor.getDocument());
    return createTitle(title, separator, charset, bom, isReadOnly);
}
Also used : DocumentContent(com.intellij.diff.contents.DocumentContent) Charset(java.nio.charset.Charset) LineSeparator(com.intellij.util.LineSeparator) EmptyContent(com.intellij.diff.contents.EmptyContent)

Example 7 with LineSeparator

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

the class DiffContentFactoryImpl method createImpl.

@NotNull
private static DocumentContent createImpl(@Nullable Project project, @NotNull String text, @Nullable FileType fileType, @Nullable String fileName, @Nullable VirtualFile highlightFile, @Nullable Charset charset, @Nullable Boolean bom, boolean respectLineSeparators, boolean readOnly) {
    if (FileTypes.UNKNOWN.equals(fileType))
        fileType = PlainTextFileType.INSTANCE;
    // TODO: detect invalid (different across the file) separators ?
    LineSeparator separator = respectLineSeparators ? StringUtil.detectSeparators(text) : null;
    String correctedContent = StringUtil.convertLineSeparators(text);
    Document document = createDocument(project, correctedContent, fileType, fileName, readOnly);
    DocumentContent content = new DocumentContentImpl(project, document, fileType, highlightFile, separator, charset, bom);
    if (fileName != null)
        content.putUserData(DiffUserDataKeysEx.FILE_NAME, fileName);
    return content;
}
Also used : Document(com.intellij.openapi.editor.Document) LineSeparator(com.intellij.util.LineSeparator) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with LineSeparator

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

the class DiffPanelImpl method createComponentForTitle.

static JComponent createComponentForTitle(@Nullable String title, @Nullable final LineSeparator sep1, @Nullable final LineSeparator sep2, boolean left) {
    if (sep1 != null && sep2 != null && !sep1.equals(sep2)) {
        LineSeparator separator = left ? sep1 : sep2;
        JPanel bottomPanel = new JPanel(new BorderLayout());
        JLabel sepLabel = new JLabel(separator.name());
        sepLabel.setForeground(separator.equals(LineSeparator.CRLF) ? JBColor.RED : PlatformColors.BLUE);
        bottomPanel.add(sepLabel, left ? BorderLayout.EAST : BorderLayout.WEST);
        JPanel panel = new JPanel(new BorderLayout());
        panel.add(new JLabel(title == null ? "" : title));
        panel.add(bottomPanel, BorderLayout.SOUTH);
        return panel;
    } else {
        return new JBLabel(title == null ? "" : title);
    }
}
Also used : JBLabel(com.intellij.ui.components.JBLabel) 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