Search in sources :

Example 1 with UIBasedFileType

use of com.intellij.openapi.fileTypes.UIBasedFileType in project intellij-community by JetBrains.

the class BinaryDiffTool method show.

public void show(final DiffRequest data) {
    final DiffContent current = data.getContents()[0];
    final DiffContent upToDate = data.getContents()[1];
    final Project project = data.getProject();
    if ((current instanceof FileContent && upToDate instanceof FileContent) || (current.getContentType() instanceof UIBasedFileType && upToDate.getContentType() instanceof UIBasedFileType)) {
        final VirtualFile src = current.getFile();
        final VirtualFile trg = upToDate.getFile();
        if (src != null && trg != null) {
            final PanelCreator creator = new PanelCreator(data);
            if (creator.isCanCreatePanel()) {
                new DialogWrapper(data.getProject()) {

                    public DiffPanel myPanel;

                    {
                        setModal(false);
                        init();
                    }

                    @Override
                    protected String getDimensionServiceKey() {
                        return "BinaryDiffDialog";
                    }

                    @NotNull
                    @Override
                    protected Action[] createActions() {
                        final Action close = getCancelAction();
                        close.putValue(Action.NAME, "&Close");
                        return new Action[] { close };
                    }

                    @Override
                    protected JComponent createCenterPanel() {
                        myPanel = creator.create(getWindow(), getDisposable(), BinaryDiffTool.this);
                        return myPanel.getComponent();
                    }
                }.show();
                return;
            } else {
                final DirDiffManager diffManager = DirDiffManager.getInstance(project);
                final DiffElement before = diffManager.createDiffElement(src);
                final DiffElement after = diffManager.createDiffElement(trg);
                if (before != null && after != null && diffManager.canShow(after, before)) {
                    diffManager.showDiff(before, after);
                    return;
                }
            }
        }
    }
    try {
        final boolean equal = Arrays.equals(current.getBytes(), upToDate.getBytes());
        Messages.showMessageDialog(equal ? DiffBundle.message("binary.files.are.identical.message") : DiffBundle.message("binary.files.are.different.message"), equal ? DiffBundle.message("files.are.identical.dialog.title") : DiffBundle.message("files.are.different.dialog.title"), Messages.getInformationIcon());
    } catch (IOException e) {
        LOG.error(e);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DiffElement(com.intellij.ide.diff.DiffElement) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Project(com.intellij.openapi.project.Project) UIBasedFileType(com.intellij.openapi.fileTypes.UIBasedFileType)

Example 2 with UIBasedFileType

use of com.intellij.openapi.fileTypes.UIBasedFileType in project intellij-community by JetBrains.

the class EditorPlaceHolder method setContent.

public void setContent(final DiffContent content) {
    runRegisteredDisposables();
    myContent = content;
    if (myContent != null) {
        Document document = myContent.getDocument();
        if (myContent.isBinary() || document == null || myContent.getContentType() instanceof UIBasedFileType) {
            final VirtualFile file = myContent.getFile();
            if (file != null) {
                final FileEditorProvider[] providers = FileEditorProviderManager.getInstance().getProviders(getProject(), file);
                if (providers.length > 0) {
                    myFileEditor = providers[0].createEditor(getProject(), file);
                    if (myFileEditor instanceof TextEditor) {
                        myEditor = (EditorEx) ((TextEditor) myFileEditor).getEditor();
                        ContentDocumentListener.install(myContent, this);
                    }
                    myFileEditorProvider = providers[0];
                    addDisposable(new Disposable() {

                        @Override
                        public void dispose() {
                            myFileEditorProvider.disposeEditor(myFileEditor);
                            myFileEditor = null;
                            myFileEditorProvider = null;
                            myEditor = null;
                        }
                    });
                } else {
                    document = new DocumentImpl("Can not show", true);
                    final EditorFactory editorFactory = EditorFactory.getInstance();
                    myEditor = DiffUtil.createEditor(document, getProject(), true, content.getContentType());
                    addDisposable(new Disposable() {

                        public void dispose() {
                            editorFactory.releaseEditor(myEditor);
                            myEditor = null;
                        }
                    });
                }
            }
        } else {
            final EditorFactory editorFactory = EditorFactory.getInstance();
            myEditor = DiffUtil.createEditor(document, getProject(), false, content.getContentType());
            addDisposable(new Disposable() {

                public void dispose() {
                    editorFactory.releaseEditor(myEditor);
                    myEditor = null;
                }
            });
            ContentDocumentListener.install(myContent, this);
        }
    }
    fireContentChanged();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Disposable(com.intellij.openapi.Disposable) UIBasedFileType(com.intellij.openapi.fileTypes.UIBasedFileType) EditorFactory(com.intellij.openapi.editor.EditorFactory) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditorProvider(com.intellij.openapi.fileEditor.FileEditorProvider) Document(com.intellij.openapi.editor.Document) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl)

Example 3 with UIBasedFileType

use of com.intellij.openapi.fileTypes.UIBasedFileType in project intellij-community by JetBrains.

the class BinaryContent method getFile.

@Override
@Nullable
public VirtualFile getFile() {
    if (myFileType instanceof UIBasedFileType) {
        final VirtualFile file = findVirtualFile();
        if (file != null) {
            final LightVirtualFile lightFile = new LightVirtualFile(file, new String(myBytes), 1);
            lightFile.setOriginalFile(file);
            return lightFile;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) UIBasedFileType(com.intellij.openapi.fileTypes.UIBasedFileType) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with UIBasedFileType

use of com.intellij.openapi.fileTypes.UIBasedFileType 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

UIBasedFileType (com.intellij.openapi.fileTypes.UIBasedFileType)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Nullable (org.jetbrains.annotations.Nullable)2 DiffElement (com.intellij.ide.diff.DiffElement)1 ArchiveFileType (com.intellij.ide.highlighter.ArchiveFileType)1 Disposable (com.intellij.openapi.Disposable)1 DiffContent (com.intellij.openapi.diff.DiffContent)1 DiffTool (com.intellij.openapi.diff.DiffTool)1 Document (com.intellij.openapi.editor.Document)1 EditorFactory (com.intellij.openapi.editor.EditorFactory)1 DocumentImpl (com.intellij.openapi.editor.impl.DocumentImpl)1 FileEditorProvider (com.intellij.openapi.fileEditor.FileEditorProvider)1 TextEditor (com.intellij.openapi.fileEditor.TextEditor)1 FileType (com.intellij.openapi.fileTypes.FileType)1 Project (com.intellij.openapi.project.Project)1 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)1 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)1 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1