Search in sources :

Example 1 with DiffElement

use of com.intellij.ide.diff.DiffElement 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 DiffElement

use of com.intellij.ide.diff.DiffElement in project intellij-community by JetBrains.

the class DirDiffPanel method getNavigatableArray.

@Nullable
private Navigatable[] getNavigatableArray() {
    Project project = myModel.getProject();
    List<DirDiffElementImpl> elements = myModel.getSelectedElements();
    List<Navigatable> navigatables = new ArrayList<>();
    for (DirDiffElementImpl element : elements) {
        DiffElement source = element.getSource();
        DiffElement target = element.getTarget();
        Navigatable navigatable1 = source != null ? source.getNavigatable(project) : null;
        Navigatable navigatable2 = target != null ? target.getNavigatable(project) : null;
        if (navigatable1 != null)
            navigatables.add(navigatable1);
        if (navigatable2 != null)
            navigatables.add(navigatable2);
    }
    return toObjectArray(navigatables, Navigatable.class);
}
Also used : Project(com.intellij.openapi.project.Project) DiffElement(com.intellij.ide.diff.DiffElement) ArrayList(java.util.ArrayList) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DiffElement (com.intellij.ide.diff.DiffElement)2 Project (com.intellij.openapi.project.Project)2 UIBasedFileType (com.intellij.openapi.fileTypes.UIBasedFileType)1 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Navigatable (com.intellij.pom.Navigatable)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1