use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion in project egit by eclipse.
the class DiffEditorPage method doSetSelection.
@Override
protected void doSetSelection(ISelection selection) {
if (!selection.isEmpty() && selection instanceof StructuredSelection) {
Object selected = ((StructuredSelection) selection).getFirstElement();
if (selected instanceof FileDiffRegion) {
FileDiffRegion newRange = (FileDiffRegion) selected;
if (!newRange.equals(currentFileDiffRange)) {
currentFileDiffRange = newRange;
selectAndReveal(newRange.getOffset(), 0);
}
return;
}
}
super.doSetSelection(selection);
}
use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion in project egit by eclipse.
the class DiffEditorPage method doSetInput.
@Override
protected void doSetInput(IEditorInput input) throws CoreException {
super.doSetInput(input);
if (input instanceof DiffEditorInput) {
setFolding();
FileDiffRegion region = getFileDiffRange(0);
currentFileDiffRange = region;
setOverviewAnnotations();
} else if (input instanceof CommitEditorInput) {
formatDiff();
currentFileDiffRange = null;
}
if (outlinePage != null) {
outlinePage.setInput(getDocumentProvider().getDocument(input));
if (currentFileDiffRange != null) {
outlinePage.setSelection(new StructuredSelection(currentFileDiffRange));
}
}
}
use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion in project egit by eclipse.
the class DiffDocument method connect.
/**
* Sets up the document to use information from the given
* {@link DiffRegionFormatter} for partitioning the document into
* partitions for file headlines, hunk headers, and added or removed lines.
* It is assumed that the given formatter has been used to generate content
* into the document.
*
* @param formatter
* to obtain information from
*/
public void connect(DiffRegionFormatter formatter) {
regions = formatter.getRegions();
fileRegions = formatter.getFileRegions();
if ((fileRegions == null || fileRegions.length == 0) && defaultRepository != null && defaultFileDiff != null) {
fileRegions = new FileDiffRegion[] { new FileDiffRegion(defaultRepository, defaultFileDiff, 0, getLength()) };
}
newPathPattern = Pattern.compile(// $NON-NLS-1$
Pattern.quote(formatter.getNewPrefix()) + "\\S+");
oldPathPattern = Pattern.compile(// $NON-NLS-1$
Pattern.quote(formatter.getOldPrefix()) + "\\S+");
maximumLineNumbers = formatter.getMaximumLineNumbers();
// Connect a new partitioner.
IDocumentPartitioner partitioner = new FastPartitioner(new DiffPartitionTokenScanner(), new String[] { IDocument.DEFAULT_CONTENT_TYPE, HEADLINE_CONTENT_TYPE, HUNK_CONTENT_TYPE, ADDED_CONTENT_TYPE, REMOVED_CONTENT_TYPE });
IDocumentPartitioner oldPartitioner = getDocumentPartitioner();
if (oldPartitioner != null) {
oldPartitioner.disconnect();
}
partitioner.connect(this);
setDocumentPartitioner(partitioner);
}
use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion in project egit by eclipse.
the class DiffDocument method findFileRegion.
FileDiffRegion findFileRegion(int offset) {
FileDiffRegion key = new FileDiffRegion(null, null, offset, 0);
int i = Arrays.binarySearch(fileRegions, key, (a, b) -> {
if (!TextUtilities.overlaps(a, b)) {
return a.getOffset() - b.getOffset();
}
return 0;
});
return i >= 0 ? fileRegions[i] : null;
}
use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion in project egit by eclipse.
the class DiffEditorOutlinePage method getSelectedFileDiffs.
private Collection<FileDiffRegion> getSelectedFileDiffs() {
ISelection currentSelection = getSelection();
List<FileDiffRegion> result = new ArrayList<>();
if (!currentSelection.isEmpty() && currentSelection instanceof StructuredSelection) {
for (Object selected : ((StructuredSelection) currentSelection).toList()) {
if (selected instanceof FileDiffRegion && !((FileDiffRegion) selected).getDiff().isSubmodule()) {
result.add((FileDiffRegion) selected);
}
}
}
return result;
}
Aggregations