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);
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations