use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion in project egit by eclipse.
the class DiffEditorOutlinePage method createContextMenu.
private void createContextMenu(TreeViewer viewer) {
MenuManager contextMenu = new MenuManager();
contextMenu.setRemoveAllWhenShown(true);
contextMenu.addMenuListener(menuManager -> {
setFocus();
Collection<FileDiffRegion> selected = getSelectedFileDiffs();
if (selected.isEmpty()) {
return;
}
Collection<FileDiffRegion> haveNew = selected.stream().filter(diff -> !diff.getDiff().getChange().equals(DiffEntry.ChangeType.DELETE)).collect(Collectors.toList());
Collection<FileDiffRegion> haveOld = selected.stream().filter(diff -> !diff.getDiff().getChange().equals(DiffEntry.ChangeType.ADD)).collect(Collectors.toList());
Collection<FileDiffRegion> existing = haveNew.stream().filter(diff -> new Path(diff.getRepository().getWorkTree().getAbsolutePath()).append(diff.getDiff().getNewPath()).toFile().exists()).collect(Collectors.toList());
if (!existing.isEmpty()) {
menuManager.add(new Action(UIText.CommitFileDiffViewer_OpenWorkingTreeVersionInEditorMenuLabel) {
@Override
public void run() {
for (FileDiffRegion fileDiff : existing) {
File file = new Path(fileDiff.getRepository().getWorkTree().getAbsolutePath()).append(fileDiff.getDiff().getNewPath()).toFile();
DiffViewer.openFileInEditor(file, -1);
}
}
});
}
if (!haveNew.isEmpty()) {
menuManager.add(new Action(UIText.CommitFileDiffViewer_OpenInEditorMenuLabel) {
@Override
public void run() {
for (FileDiffRegion fileDiff : haveNew) {
DiffViewer.openInEditor(fileDiff.getRepository(), fileDiff.getDiff(), DiffEntry.Side.NEW, -1);
}
}
});
}
if (!haveOld.isEmpty()) {
menuManager.add(new Action(UIText.CommitFileDiffViewer_OpenPreviousInEditorMenuLabel) {
@Override
public void run() {
for (FileDiffRegion fileDiff : haveOld) {
DiffViewer.openInEditor(fileDiff.getRepository(), fileDiff.getDiff(), DiffEntry.Side.OLD, -1);
}
}
});
}
if (selected.size() == 1) {
menuManager.add(new Separator());
menuManager.add(new Action(UIText.CommitFileDiffViewer_CompareMenuLabel) {
@Override
public void run() {
FileDiffRegion fileDiff = selected.iterator().next();
DiffViewer.showTwoWayFileDiff(fileDiff.getRepository(), fileDiff.getDiff());
}
});
}
});
Menu menu = contextMenu.createContextMenu(viewer.getTree());
viewer.getTree().setMenu(menu);
}
use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion in project egit by eclipse.
the class DiffEditorPage method createSourceViewer.
// TextEditor specifics:
@Override
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
DiffViewer viewer = new DiffViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles) {
@Override
protected void setFont(Font font) {
// Don't do anything; AbstractTextEditor handles this.
}
};
getSourceViewerDecorationSupport(viewer);
ProjectionSupport projector = new ProjectionSupport(viewer, getAnnotationAccess(), getSharedColors());
projector.install();
viewer.getTextWidget().addCaretListener(event -> {
if (outlinePage != null) {
FileDiffRegion region = getFileDiffRange(event.caretOffset);
if (region != null && !region.equals(currentFileDiffRange)) {
currentFileDiffRange = region;
outlinePage.setSelection(new StructuredSelection(region));
} else {
currentFileDiffRange = region;
}
}
});
return viewer;
}
use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion in project egit by eclipse.
the class DiffEditorPage method setFolding.
// Diff specifics:
private void setFolding() {
ProjectionViewer viewer = (ProjectionViewer) getSourceViewer();
if (viewer == null) {
return;
}
IDocument document = viewer.getDocument();
if (document instanceof DiffDocument) {
FileDiffRegion[] regions = ((DiffDocument) document).getFileRegions();
if (regions == null || regions.length <= 1) {
viewer.disableProjection();
return;
}
viewer.enableProjection();
Map<Annotation, Position> newAnnotations = new HashMap<>();
for (FileDiffRegion region : regions) {
newAnnotations.put(new ProjectionAnnotation(), new Position(region.getOffset(), region.getLength()));
}
viewer.getProjectionAnnotationModel().modifyAnnotations(currentFoldingAnnotations, newAnnotations, null);
currentFoldingAnnotations = newAnnotations.keySet().toArray(new Annotation[newAnnotations.size()]);
} else {
viewer.disableProjection();
currentFoldingAnnotations = null;
}
}
Aggregations