Merge topic 'sbs2'
* changes: SideBySide2: Display diff header on mode changes and renames Include content on identical files with mode change
This commit is contained in:
@@ -18,7 +18,9 @@ import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.core.client.JsArray;
|
||||
import com.google.gwt.core.client.JsArrayString;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.resources.client.CssResource;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
@@ -28,6 +30,8 @@ import com.google.gwt.user.client.ui.HTMLPanel;
|
||||
import com.google.gwt.user.client.ui.UIObject;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
import net.codemirror.lib.CodeMirror;
|
||||
|
||||
/**
|
||||
* A table with one row and two columns to hold the two CodeMirrors displaying
|
||||
* the files to be diffed.
|
||||
@@ -58,6 +62,8 @@ class DiffTable extends Composite {
|
||||
@UiField Element patchSetNavRow;
|
||||
@UiField Element patchSetNavCellA;
|
||||
@UiField Element patchSetNavCellB;
|
||||
@UiField Element diffHeaderRow;
|
||||
@UiField Element diffHeaderText;
|
||||
@UiField FlowPanel widgets;
|
||||
@UiField static DiffTableStyle style;
|
||||
|
||||
@@ -68,6 +74,7 @@ class DiffTable extends Composite {
|
||||
PatchSetSelectBox2 patchSetSelectBoxB;
|
||||
|
||||
private SideBySide2 parent;
|
||||
private boolean header;
|
||||
private boolean headerVisible;
|
||||
private boolean visibleA;
|
||||
|
||||
@@ -114,6 +121,7 @@ class DiffTable extends Composite {
|
||||
void setHeaderVisible(boolean show) {
|
||||
headerVisible = show;
|
||||
UIObject.setVisible(patchSetNavRow, show);
|
||||
UIObject.setVisible(diffHeaderRow, show && header);
|
||||
if (show) {
|
||||
parent.header.removeStyleName(style.fullscreen());
|
||||
} else {
|
||||
@@ -123,12 +131,42 @@ class DiffTable extends Composite {
|
||||
}
|
||||
|
||||
int getHeaderHeight() {
|
||||
return patchSetSelectBoxA.getOffsetHeight();
|
||||
int h = patchSetSelectBoxA.getOffsetHeight();
|
||||
if (header) {
|
||||
h += diffHeaderRow.getOffsetHeight();
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
void setUpPatchSetNav(JsArray<RevisionInfo> list, DiffInfo info) {
|
||||
void set(JsArray<RevisionInfo> list, DiffInfo info) {
|
||||
patchSetSelectBoxA.setUpPatchSetNav(list, info.meta_a());
|
||||
patchSetSelectBoxB.setUpPatchSetNav(list, info.meta_b());
|
||||
|
||||
JsArrayString hdr = info.diff_header();
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (int i = 1; i < hdr.length(); i++) {
|
||||
String s = hdr.get(i);
|
||||
if (s.startsWith("diff --git ")
|
||||
|| s.startsWith("index ")
|
||||
|| s.startsWith("+++ ")
|
||||
|| s.startsWith("--- ")) {
|
||||
continue;
|
||||
}
|
||||
b.append(s).append('\n');
|
||||
}
|
||||
header = b.length() > 0;
|
||||
diffHeaderText.setInnerText(b.toString().trim());
|
||||
UIObject.setVisible(diffHeaderRow, header);
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
overview.refresh();
|
||||
if (header) {
|
||||
CodeMirror cm = parent.getCmFromSide(DisplaySide.A);
|
||||
diffHeaderText.getStyle().setMarginLeft(
|
||||
cm.getGutterElement().getOffsetWidth(),
|
||||
Unit.PX);
|
||||
}
|
||||
}
|
||||
|
||||
void add(Widget widget) {
|
||||
|
||||
@@ -157,6 +157,12 @@ limitations under the License.
|
||||
z-index: 2;
|
||||
cursor: text;
|
||||
}
|
||||
.diff_header {
|
||||
margin: 0 0 3px 0;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
color: #5252ad;
|
||||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel styleName='{style.difftable}'>
|
||||
<table class='{style.table}'>
|
||||
@@ -169,6 +175,12 @@ limitations under the License.
|
||||
</td>
|
||||
<td class='{style.overview}' />
|
||||
</tr>
|
||||
<tr ui:field='diffHeaderRow' class='{style.patchSetNav}'>
|
||||
<td colspan='2'><pre
|
||||
ui:field='diffHeaderText'
|
||||
class='{style.diff_header}' /></td>
|
||||
<td class='{style.overview}' />
|
||||
</tr>
|
||||
<tr>
|
||||
<td ui:field='cmA' class='{style.a}' />
|
||||
<td ui:field='cmB' class='{style.b}' />
|
||||
|
||||
@@ -201,7 +201,7 @@ public class SideBySide2 extends Screen {
|
||||
info.revisions().copyKeysIntoChildren("name");
|
||||
JsArray<RevisionInfo> list = info.revisions().values();
|
||||
RevisionInfo.sortRevisionInfoByNumber(list);
|
||||
diffTable.setUpPatchSetNav(list, diff);
|
||||
diffTable.set(list, diff);
|
||||
header.setChangeInfo(info);
|
||||
}}));
|
||||
|
||||
@@ -245,7 +245,7 @@ public class SideBySide2 extends Screen {
|
||||
}
|
||||
});
|
||||
setLineLength(prefs.lineLength());
|
||||
diffTable.overview.refresh();
|
||||
diffTable.refresh();
|
||||
|
||||
if (startLine == 0 && diff.meta_b() != null) {
|
||||
DiffChunkInfo d = chunkManager.getFirst();
|
||||
|
||||
@@ -450,7 +450,9 @@ class PatchScriptBuilder {
|
||||
|
||||
id = tw != null ? tw.getObjectId(0) : ObjectId.zeroId();
|
||||
mode = tw != null ? tw.getFileMode(0) : FileMode.MISSING;
|
||||
reuse = other != null && other.id.equals(id) && other.mode == mode;
|
||||
reuse = other != null
|
||||
&& other.id.equals(id)
|
||||
&& (other.mode == mode || isBothFile(other.mode, mode));
|
||||
|
||||
if (reuse) {
|
||||
srcContent = other.srcContent;
|
||||
@@ -514,4 +516,9 @@ class PatchScriptBuilder {
|
||||
return TreeWalk.forPath(reader, path, tree);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isBothFile(FileMode a, FileMode b) {
|
||||
return (a.getBits() & FileMode.TYPE_FILE) == FileMode.TYPE_FILE
|
||||
&& (b.getBits() & FileMode.TYPE_FILE) == FileMode.TYPE_FILE;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user