use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter in project egit by eclipse.
the class BlameInformationControl method createDiffLinkAndText.
private void createDiffLinkAndText(final RevCommit parent, final Diff diff) throws IOException {
String parentId = parent.toObjectId().abbreviate(7).name();
String parentMessage = parent.getShortMessage();
EditList interestingDiff = getInterestingDiff(diff.getEditList());
final Integer parentLine;
if (!interestingDiff.isEmpty())
parentLine = Integer.valueOf(interestingDiff.get(0).getBeginA());
else
parentLine = null;
Composite header = new Composite(diffComposite, SWT.NONE);
header.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());
Label diffHeaderLabel = new Label(header, SWT.NONE);
diffHeaderLabel.setText(NLS.bind(UIText.BlameInformationControl_DiffHeaderLabel, parentId, parentMessage));
showAnnotationsLink = new Link(header, SWT.NONE);
showAnnotationsLink.setText(UIText.BlameInformationControl_ShowAnnotationsLink);
showAnnotationsLinkSelectionAdapter = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
blameParent(parent, diff, parentLine);
}
};
showAnnotationsLink.addSelectionListener(showAnnotationsLinkSelectionAdapter);
DiffViewer diffText = new DiffViewer(diffComposite, null, SWT.NONE);
diffText.configure(new DiffViewer.Configuration(EditorsUI.getPreferenceStore()));
diffText.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
DiffDocument document = new DiffDocument();
try (DiffRegionFormatter diffFormatter = new DiffRegionFormatter(document)) {
diffFormatter.setContext(1);
diffFormatter.setRepository(revision.getRepository());
diffFormatter.format(interestingDiff, diff.getOldText(), diff.getNewText());
try (ObjectReader reader = revision.getRepository().newObjectReader()) {
DiffEntry diffEntry = CompareCoreUtils.getChangeDiffEntry(revision.getRepository(), revision.getSourcePath(), revision.getCommit(), parent, reader);
if (diffEntry != null) {
FileDiff fileDiff = new FileDiff(revision.getCommit(), diffEntry);
document.setDefault(revision.getRepository(), fileDiff);
}
}
document.connect(diffFormatter);
}
diffText.setDocument(document);
}
use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter in project egit by eclipse.
the class DiffRegionFormatterTest method testRanges.
@Test
public void testRanges() throws Exception {
IDocument document = new Document();
DiffRegion[] regions;
try (DiffRegionFormatter formatter = new DiffRegionFormatter(document)) {
formatter.setRepository(repository);
formatter.format(commit.getTree(), commit.getParent(0).getTree());
assertTrue(document.getLength() > 0);
regions = formatter.getRegions();
}
assertNotNull(regions);
assertTrue(regions.length > 0);
for (DiffRegion region : regions) {
assertNotNull(region);
assertTrue(region.getOffset() >= 0);
assertTrue(region.getLength() >= 0);
assertTrue(region.getOffset() < document.getLength());
}
}
use of org.eclipse.egit.ui.internal.commit.DiffRegionFormatter in project egit by eclipse.
the class GitHistoryPage method formatDiffs.
private void formatDiffs(final List<FileDiff> diffs) {
Job.getJobManager().cancel(JobFamilies.HISTORY_DIFF);
if (diffs.isEmpty()) {
if (UIUtils.isUsable(diffViewer)) {
IDocument document = new Document();
diffViewer.setDocument(document);
resizeCommentAndDiffScrolledComposite();
}
return;
}
final Repository repository = fileViewer.getRepository();
Job formatJob = new Job(UIText.GitHistoryPage_FormatDiffJobName) {
@Override
protected IStatus run(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
int maxLines = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.HISTORY_MAX_DIFF_LINES);
final DiffDocument document = new DiffDocument();
try (DiffRegionFormatter formatter = new DiffRegionFormatter(document, document.getLength(), maxLines)) {
SubMonitor progress = SubMonitor.convert(monitor, diffs.size());
for (FileDiff diff : diffs) {
if (progress.isCanceled() || diff.getCommit().getParentCount() > 1 || document.getNumberOfLines() > maxLines) {
break;
}
progress.subTask(diff.getPath());
try {
formatter.write(repository, diff);
} catch (IOException ignore) {
// Ignored
}
progress.worked(1);
}
if (progress.isCanceled()) {
return Status.CANCEL_STATUS;
}
document.connect(formatter);
}
UIJob uiJob = new UIJob(UIText.GitHistoryPage_FormatDiffJobName) {
@Override
public IStatus runInUIThread(IProgressMonitor uiMonitor) {
if (uiMonitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
if (UIUtils.isUsable(diffViewer)) {
diffViewer.setDocument(document);
resizeCommentAndDiffScrolledComposite();
}
return Status.OK_STATUS;
}
@Override
public boolean belongsTo(Object family) {
return JobFamilies.HISTORY_DIFF.equals(family);
}
};
uiJob.setRule(pageSchedulingRule);
GitHistoryPage.this.schedule(uiJob);
return Status.OK_STATUS;
}
@Override
public boolean belongsTo(Object family) {
return JobFamilies.HISTORY_DIFF.equals(family);
}
};
formatJob.setRule(pageSchedulingRule);
schedule(formatJob);
}
Aggregations