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

View File

@@ -257,6 +257,8 @@ public class SideBySide2 extends Screen {
cmB.setOption("viewportMargin", 10); cmB.setOption("viewportMargin", 10);
cmB.setCursor(LineCharacter.create(0)); cmB.setCursor(LineCharacter.create(0));
cmB.focus(); cmB.focus();
prefetchNextFile();
} }
@Override @Override
@@ -1340,4 +1342,28 @@ public class SideBySide2 extends Screen {
CodeMirror getCmB() { CodeMirror getCmB() {
return cmB; 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) {
}
});
}
}
} }