Merge "Show images in side-by-side diffs"
This commit is contained in:
@@ -37,6 +37,7 @@ import com.google.gerrit.reviewdb.client.AccountDiffPreference;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.BlurEvent;
|
||||
import com.google.gwt.event.dom.client.BlurHandler;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
@@ -61,6 +62,7 @@ import com.google.gwtexpui.globalkey.client.GlobalKey;
|
||||
import com.google.gwtexpui.globalkey.client.KeyCommand;
|
||||
import com.google.gwtexpui.globalkey.client.KeyCommandSet;
|
||||
import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
|
||||
import com.google.gwtorm.client.KeyUtil;
|
||||
|
||||
import org.eclipse.jgit.diff.Edit;
|
||||
|
||||
@@ -312,6 +314,23 @@ public abstract class AbstractPatchContentTable extends NavigationTable<Object>
|
||||
return f;
|
||||
}
|
||||
|
||||
protected String getUrlA() {
|
||||
final String rawBase = GWT.getHostPageBaseURL() + "cat/";
|
||||
final String url;
|
||||
if (idSideA == null) {
|
||||
url = rawBase + KeyUtil.encode(patchKey.toString()) + "^1";
|
||||
} else {
|
||||
Patch.Key k = new Patch.Key(idSideA, patchKey.get());
|
||||
url = rawBase + KeyUtil.encode(k.toString()) + "^0";
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
protected String getUrlB() {
|
||||
final String rawBase = GWT.getHostPageBaseURL() + "cat/";
|
||||
return rawBase + KeyUtil.encode(patchKey.toString()) + "^0";
|
||||
}
|
||||
|
||||
protected abstract void render(PatchScript script, final PatchSetDetail detail);
|
||||
|
||||
protected abstract void onInsertComment(PatchLine pl);
|
||||
|
@@ -22,6 +22,7 @@ import static com.google.gerrit.client.patches.PatchLine.Type.REPLACE;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.common.data.CommentDetail;
|
||||
import com.google.gerrit.common.data.PatchScript;
|
||||
import com.google.gerrit.common.data.PatchScript.DisplayMethod;
|
||||
import com.google.gerrit.common.data.PatchScript.FileMode;
|
||||
import com.google.gerrit.common.data.PatchSetDetail;
|
||||
import com.google.gerrit.prettify.common.EditList;
|
||||
@@ -39,7 +40,6 @@ import com.google.gwt.user.client.ui.InlineLabel;
|
||||
import com.google.gwt.user.client.ui.UIObject;
|
||||
import com.google.gwtexpui.safehtml.client.SafeHtml;
|
||||
import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
|
||||
|
||||
import org.eclipse.jgit.diff.Edit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -192,6 +192,11 @@ public class SideBySideTable extends AbstractPatchContentTable {
|
||||
for (final String line : script.getPatchHeader()) {
|
||||
appendFileHeader(nc, line);
|
||||
}
|
||||
// If there is a safe picture involved, we show it
|
||||
if (script.getDisplayMethodA() == DisplayMethod.IMG
|
||||
|| script.getDisplayMethodB() == DisplayMethod.IMG) {
|
||||
appendImageLine(script, nc);
|
||||
}
|
||||
}
|
||||
if (!hasDifferences(script)) {
|
||||
appendNoDifferences(nc);
|
||||
@@ -211,6 +216,42 @@ public class SideBySideTable extends AbstractPatchContentTable {
|
||||
}
|
||||
}
|
||||
|
||||
private SafeHtml createImage(String url) {
|
||||
SafeHtmlBuilder m = new SafeHtmlBuilder();
|
||||
m.openElement("img");
|
||||
m.setAttribute("src", url);
|
||||
m.closeElement("img");
|
||||
return m.toSafeHtml();
|
||||
}
|
||||
|
||||
private void appendImageLine(final PatchScript script,
|
||||
final SafeHtmlBuilder m) {
|
||||
m.openTr();
|
||||
m.setAttribute("valign", "center");
|
||||
m.setAttribute("align", "center");
|
||||
|
||||
m.openTd();
|
||||
m.setStyleName(Gerrit.RESOURCES.css().iconCell());
|
||||
m.closeTd();
|
||||
|
||||
appendLineNumber(m, false);
|
||||
if (script.getDisplayMethodA() == DisplayMethod.IMG) {
|
||||
final String url = getUrlA();
|
||||
appendLineText(m, DELETE, createImage(url), false, true);
|
||||
} else {
|
||||
appendLineNone(m, DELETE);
|
||||
}
|
||||
if (script.getDisplayMethodB() == DisplayMethod.IMG) {
|
||||
final String url = getUrlB();
|
||||
appendLineText(m, INSERT, createImage(url), false, true);
|
||||
} else {
|
||||
appendLineNone(m, INSERT);
|
||||
}
|
||||
|
||||
appendLineNumber(m, true);
|
||||
m.closeTr();
|
||||
}
|
||||
|
||||
private void populateTableHeader(final PatchScript script,
|
||||
final PatchSetDetail detail) {
|
||||
initHeaders(script, detail);
|
||||
|
@@ -26,17 +26,14 @@ import com.google.gerrit.common.data.PatchSetDetail;
|
||||
import com.google.gerrit.prettify.common.EditList;
|
||||
import com.google.gerrit.prettify.common.EditList.Hunk;
|
||||
import com.google.gerrit.prettify.common.SparseHtmlFile;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.Element;
|
||||
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
|
||||
import com.google.gwt.user.client.ui.UIObject;
|
||||
import com.google.gwtexpui.safehtml.client.SafeHtml;
|
||||
import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
|
||||
import com.google.gwtorm.client.KeyUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -301,20 +298,12 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
|
||||
final SafeHtmlBuilder nc) {
|
||||
final boolean syntaxHighlighting =
|
||||
script.getDiffPrefs().isSyntaxHighlighting();
|
||||
final String rawBase = GWT.getHostPageBaseURL() + "cat/";
|
||||
|
||||
if (script.getDisplayMethodA() == DisplayMethod.IMG) {
|
||||
final String url;
|
||||
if (idSideA == null) {
|
||||
url = rawBase + KeyUtil.encode(patchKey.toString()) + "^1";
|
||||
} else {
|
||||
Patch.Key k = new Patch.Key(idSideA, patchKey.get());
|
||||
url = rawBase + KeyUtil.encode(k.toString()) + "^0";
|
||||
}
|
||||
final String url = getUrlA();
|
||||
appendImageLine(nc, url, syntaxHighlighting, false);
|
||||
}
|
||||
if (script.getDisplayMethodB() == DisplayMethod.IMG) {
|
||||
final String url = rawBase + KeyUtil.encode(patchKey.toString()) + "^0";
|
||||
final String url = getUrlB();
|
||||
appendImageLine(nc, url, syntaxHighlighting, true);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user