Merge "Prefetch diff for next file"

This commit is contained in:
Shawn Pearce
2013-09-01 03:44:23 +00:00
committed by Gerrit Code Review
2 changed files with 36 additions and 2 deletions

View File

@@ -64,6 +64,7 @@ class Header extends Composite {
private final String path;
private boolean hasPrev;
private boolean hasNext;
private String nextPath;
Header(KeyCommandSet keys, PatchSet.Id patchSetId, String path) {
initWidget(uiBinder.createAndBindUi(this));
@@ -107,10 +108,13 @@ class Header extends Composite {
break;
}
}
FileInfo nextInfo = index == files.length() - 1
? null
: files.get(index + 1);
setupNav(prev, '[', PatchUtil.C.previousFileHelp(),
index == 0 ? null : files.get(index - 1));
setupNav(next, ']', PatchUtil.C.nextFileHelp(),
index == files.length() - 1 ? null : files.get(index + 1));
setupNav(next, ']', PatchUtil.C.nextFileHelp(), nextInfo);
nextPath = nextInfo != null ? nextInfo.path() : null;
}
});
@@ -194,4 +198,8 @@ class Header extends Composite {
boolean hasNext() {
return hasNext;
}
String getNextPath() {
return nextPath;
}
}

View File

@@ -257,6 +257,8 @@ public class SideBySide2 extends Screen {
cmB.setOption("viewportMargin", 10);
cmB.setCursor(LineCharacter.create(0));
cmB.focus();
prefetchNextFile();
}
@Override
@@ -1340,4 +1342,28 @@ public class SideBySide2 extends Screen {
CodeMirror getCmB() {
return cmB;
}
private void prefetchNextFile() {
String nextPath = header.getNextPath();
if (nextPath != null) {
DiffApi.diff(revision, nextPath)
.base(base)
.wholeFile()
.intraline(pref.isIntralineDifference())
.ignoreWhitespace(pref.getIgnoreWhitespace())
.get(new AsyncCallback<DiffInfo>() {
@Override
public void onSuccess(DiffInfo info) {
new ModeInjector()
.add(getContentType(info.meta_a()))
.add(getContentType(info.meta_b()))
.inject(CallbackGroup.<Void> emptyCallback());
}
@Override
public void onFailure(Throwable caught) {
}
});
}
}
}