Search in sources :

Example 1 with DiffContent

use of com.intellij.openapi.diff.DiffContent in project intellij-community by JetBrains.

the class BaseDiffAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    DiffRequest diffData = getDiffData(e.getDataContext());
    if (diffData == null)
        return;
    final DiffContent[] contents = diffData.getContents();
    final FileDocumentManager documentManager = FileDocumentManager.getInstance();
    ApplicationManager.getApplication().runWriteAction(() -> {
        for (DiffContent content : contents) {
            Document document = content.getDocument();
            if (document != null) {
                documentManager.saveDocument(document);
            }
        }
    });
    DiffManager.getInstance().getDiffTool().show(diffData);
}
Also used : DiffRequest(com.intellij.openapi.diff.DiffRequest) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Document(com.intellij.openapi.editor.Document) DiffContent(com.intellij.openapi.diff.DiffContent)

Example 2 with DiffContent

use of com.intellij.openapi.diff.DiffContent in project intellij-community by JetBrains.

the class DiffSideView method getCurrentOpenFileDescriptor.

@Nullable
public OpenFileDescriptor getCurrentOpenFileDescriptor() {
    final EditorEx editor = myEditorSource.getEditor();
    final DiffContent content = myEditorSource.getContent();
    if (content == null || editor == null) {
        return null;
    }
    return content.getOpenFileDescriptor(editor.getCaretModel().getOffset());
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) DiffContent(com.intellij.openapi.diff.DiffContent) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with DiffContent

use of com.intellij.openapi.diff.DiffContent in project intellij-community by JetBrains.

the class ExternalToolContentExternalizer method getContentFile.

public File getContentFile() throws IOException {
    String extension = chooseExtension();
    String name = chooseName();
    if (name.length() <= 3)
        name = "___" + name;
    File tempFile;
    try {
        tempFile = FileUtil.createTempFile(name, extension);
    } catch (IOException e) {
        tempFile = FileUtil.createTempFile(STD_PREFIX, extension);
    }
    final DiffContent content = getContent();
    byte[] bytes = myRequest instanceof MergeRequest ? content.getDocument().getText().getBytes() : content.getBytes();
    FileUtil.writeToFile(tempFile, bytes);
    return tempFile;
}
Also used : MergeRequest(com.intellij.openapi.diff.MergeRequest) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) DiffContent(com.intellij.openapi.diff.DiffContent)

Example 4 with DiffContent

use of com.intellij.openapi.diff.DiffContent in project intellij-community by JetBrains.

the class ExternalToolContentExternalizer method chooseExtension.

private String chooseExtension() {
    DiffContent content = getContent();
    VirtualFile contentFile = content.getFile();
    String extension;
    if (contentFile != null) {
        extension = "." + contentFile.getExtension();
    } else {
        FileType contentType = content.getContentType();
        if (contentType == null)
            contentType = DiffUtil.chooseContentTypes(myRequest.getContents())[myIndex];
        extension = contentType != null ? "." + contentType.getDefaultExtension() : null;
    }
    return extension;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileType(com.intellij.openapi.fileTypes.FileType) DiffContent(com.intellij.openapi.diff.DiffContent)

Example 5 with DiffContent

use of com.intellij.openapi.diff.DiffContent in project intellij-community by JetBrains.

the class CompositeDiffTool method chooseTool.

@Nullable
private DiffTool chooseTool(DiffRequest data) {
    final DiffContent[] contents = data.getContents();
    if (contents.length == 2) {
        final FileType type1 = contents[0].getContentType();
        final FileType type2 = contents[1].getContentType();
        if (type1 == type2 && type1 instanceof UIBasedFileType) {
            return BinaryDiffTool.INSTANCE;
        }
        //todo[kb] register or not this instance in common diff tools ?
        if (type1 == type2 && type1 instanceof ArchiveFileType) {
            return ArchiveDiffTool.INSTANCE;
        }
    }
    for (DiffTool tool : myTools) {
        if (tool.canShow(data))
            return tool;
    }
    return null;
}
Also used : UIBasedFileType(com.intellij.openapi.fileTypes.UIBasedFileType) ArchiveFileType(com.intellij.ide.highlighter.ArchiveFileType) FileType(com.intellij.openapi.fileTypes.FileType) ArchiveFileType(com.intellij.ide.highlighter.ArchiveFileType) UIBasedFileType(com.intellij.openapi.fileTypes.UIBasedFileType) DiffTool(com.intellij.openapi.diff.DiffTool) DiffContent(com.intellij.openapi.diff.DiffContent) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DiffContent (com.intellij.openapi.diff.DiffContent)8 FileType (com.intellij.openapi.fileTypes.FileType)3 Nullable (org.jetbrains.annotations.Nullable)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ArchiveFileType (com.intellij.ide.highlighter.ArchiveFileType)1 DiffRequest (com.intellij.openapi.diff.DiffRequest)1 DiffTool (com.intellij.openapi.diff.DiffTool)1 MergeRequest (com.intellij.openapi.diff.MergeRequest)1 SimpleDiffRequest (com.intellij.openapi.diff.SimpleDiffRequest)1 Document (com.intellij.openapi.editor.Document)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 UIBasedFileType (com.intellij.openapi.fileTypes.UIBasedFileType)1 File (java.io.File)1 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1