Search in sources :

Example 1 with DiffRequest

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

the class CompositeDiffPanel method setDiffRequest.

@Override
public void setDiffRequest(DiffRequest request) {
    final Map<String, DiffRequest> requestMap = myRequest.discloseRequest(request);
    HashMap<String, Pair<DiffViewer, Content>> mapCopy = new HashMap<>(myMap);
    myMap.clear();
    for (Map.Entry<String, DiffRequest> entry : requestMap.entrySet()) {
        final String key = entry.getKey();
        final DiffRequest diffRequest = entry.getValue();
        diffRequest.getGenericData().put(PlatformDataKeys.COMPOSITE_DIFF_VIEWER.getName(), this);
        final Pair<DiffViewer, Content> pair = mapCopy.get(key);
        DiffViewer viewer = pair != null ? pair.first : null;
        if (viewer != null && viewer.acceptsType(diffRequest.getType()) && viewer.canShowRequest(diffRequest)) {
            viewer.setDiffRequest(diffRequest);
            myMap.put(key, pair);
            mapCopy.remove(key);
        } else {
            final DiffViewer newViewer = myRequest.viewerForRequest(myWindow, myParentDisposable, key, diffRequest);
            if (newViewer == null)
                continue;
            final Content content = myUi.createContent(key, newViewer.getComponent(), key, null, newViewer.getPreferredFocusedComponent());
            content.setCloseable(false);
            content.setPinned(true);
            content.setDisposer(myParentDisposable);
            myUi.addContent(content);
            myMap.put(key, Pair.create(newViewer, content));
            if (pair != null)
                myUi.removeContent(pair.second, false);
        }
    }
    if (myMap.isEmpty()) {
        final ErrorDiffViewer errorDiffViewer = new ErrorDiffViewer(myWindow, request);
        final Content content = myUi.createContent(FICTIVE_KEY, errorDiffViewer.getComponent(), FICTIVE_KEY, null, errorDiffViewer.getPreferredFocusedComponent());
        content.setCloseable(false);
        content.setPinned(true);
        content.setDisposer(myParentDisposable);
        myUi.addContent(content);
        myMap.put(FICTIVE_KEY, Pair.<DiffViewer, Content>create(errorDiffViewer, content));
    }
    for (Pair<DiffViewer, Content> pair : mapCopy.values()) {
        myUi.removeContent(pair.second, false);
        if (pair.first instanceof Disposable)
            Disposer.dispose((Disposable) pair.first);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) HashMap(java.util.HashMap) DiffRequest(com.intellij.openapi.diff.DiffRequest) DiffViewer(com.intellij.openapi.diff.DiffViewer) Content(com.intellij.ui.content.Content) HashMap(java.util.HashMap) Map(java.util.Map) Pair(com.intellij.openapi.util.Pair)

Example 2 with DiffRequest

use of com.intellij.openapi.diff.DiffRequest 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 3 with DiffRequest

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

the class CompareFiles method getDiffData.

protected DiffRequest getDiffData(DataContext dataContext) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final DiffRequest diffRequest = DIFF_REQUEST.getData(dataContext);
    if (diffRequest != null) {
        return diffRequest;
    }
    final VirtualFile[] data = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
    if (data == null || data.length != 2) {
        return null;
    }
    return getDiffRequest(project, data);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) SimpleDiffRequest(com.intellij.openapi.diff.SimpleDiffRequest) DiffRequest(com.intellij.openapi.diff.DiffRequest)

Example 4 with DiffRequest

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

the class BaseDiffAction method update.

public void update(AnActionEvent e) {
    DiffRequest diffData = getDiffData(e.getDataContext());
    boolean enabled = diffData != null && (!diffData.isSafeToCallFromUpdate() || (diffData.getContents() != null && DiffManager.getInstance().getDiffTool().canShow(diffData)));
    Presentation presentation = e.getPresentation();
    presentation.setEnabled(enabled);
    if (enabled)
        presentation.setVisible(true);
    else
        disableAction(presentation);
}
Also used : DiffRequest(com.intellij.openapi.diff.DiffRequest)

Example 5 with DiffRequest

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

the class CompareFiles method isAvailable.

private static boolean isAvailable(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    DiffRequest diffRequest = e.getData(DIFF_REQUEST);
    if (diffRequest == null) {
        final VirtualFile[] virtualFiles = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
        if (virtualFiles == null || virtualFiles.length != 2) {
            return false;
        }
        diffRequest = getDiffRequest(project, virtualFiles);
    }
    if (diffRequest == null) {
        return false;
    }
    return !diffRequest.isSafeToCallFromUpdate() || DiffManager.getInstance().getDiffTool().canShow(diffRequest);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) SimpleDiffRequest(com.intellij.openapi.diff.SimpleDiffRequest) DiffRequest(com.intellij.openapi.diff.DiffRequest)

Aggregations

DiffRequest (com.intellij.openapi.diff.DiffRequest)5 SimpleDiffRequest (com.intellij.openapi.diff.SimpleDiffRequest)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Disposable (com.intellij.openapi.Disposable)1 DiffContent (com.intellij.openapi.diff.DiffContent)1 DiffViewer (com.intellij.openapi.diff.DiffViewer)1 Document (com.intellij.openapi.editor.Document)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 Pair (com.intellij.openapi.util.Pair)1 Content (com.intellij.ui.content.Content)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1