InlineEdit: Don't offer edit icon on binary files

Currently there is no way to retrieve patch type info in side by side
screen.  Extend GET changes/<id>/revisions/<rev>/files/<path>/diff
to return binary flag. Suppress change edit icon on patch set select
panel when binary file is opened.

Bug: Issue 3162
Change-Id: I92daf8fde462a0c9977821a60fb19538e4bfae45
This commit is contained in:
David Ostrovsky
2015-02-13 01:16:37 +01:00
parent 6a78963c0c
commit cdbef230c0
9 changed files with 22 additions and 8 deletions

View File

@@ -3636,6 +3636,7 @@ link:#diff-content[DiffContent] entities.
|`web_links` |optional|
Links to the file diff in external sites as a list of
link:rest-api-changes.html#diff-web-link-info[DiffWebLinkInfo] entries.
|`binary` |not set if `false`|Whether the file is binary.
|==========================
[[diff-intraline-info]]

View File

@@ -56,6 +56,7 @@ public class PatchScript {
protected boolean intralineDifference;
protected boolean intralineFailure;
protected boolean intralineTimeout;
protected boolean binary;
public PatchScript(final Change.Key ck, final ChangeType ct, final String on,
final String nn, final FileMode om, final FileMode nm,
@@ -64,7 +65,7 @@ public class PatchScript {
final List<Edit> e, final DisplayMethod ma, final DisplayMethod mb,
final String mta, final String mtb, final CommentDetail cd,
final List<Patch> hist, final boolean hf, final boolean id,
final boolean idf, final boolean idt) {
final boolean idf, final boolean idt, boolean bin) {
changeId = ck;
changeType = ct;
oldName = on;
@@ -86,6 +87,7 @@ public class PatchScript {
intralineDifference = id;
intralineFailure = idf;
intralineTimeout = idt;
binary = bin;
}
protected PatchScript() {
@@ -194,4 +196,8 @@ public class PatchScript {
}
return new EditList(edits, ctx, a.size(), b.size()).getHunks();
}
public boolean isBinary() {
return binary;
}
}

View File

@@ -32,6 +32,8 @@ public class DiffInfo {
public List<ContentEntry> content;
// Links to the file diff in external sites
public List<DiffWebLinkInfo> webLinks;
// Binary file
public Boolean binary;
public static enum IntraLineStatus {
OK,

View File

@@ -35,6 +35,7 @@ public class DiffInfo extends JavaScriptObject {
public final native JsArrayString diff_header() /*-{ return this.diff_header; }-*/;
public final native JsArray<Region> content() /*-{ return this.content; }-*/;
public final native JsArray<DiffWebLinkInfo> web_links() /*-{ return this.web_links; }-*/;
public final native boolean binary() /*-{ return this.binary || false; }-*/;
public final List<WebLinkInfo> side_by_side_web_links() {
return filterWebLinks(DiffView.SIDE_BY_SIDE);

View File

@@ -150,12 +150,12 @@ class DiffTable extends Composite {
}
void set(DiffPreferences prefs, JsArray<RevisionInfo> list, DiffInfo info,
boolean editExists, int currentPatchSet, boolean open) {
boolean editExists, int currentPatchSet, boolean open, boolean binary) {
this.changeType = info.change_type();
patchSetSelectBoxA.setUpPatchSetNav(list, info.meta_a(), editExists,
currentPatchSet, open);
currentPatchSet, open, binary);
patchSetSelectBoxB.setUpPatchSetNav(list, info.meta_b(), editExists,
currentPatchSet, open);
currentPatchSet, open, binary);
JsArrayString hdr = info.diff_header();
if (hdr != null) {

View File

@@ -82,7 +82,7 @@ class PatchSetSelectBox extends Composite {
}
void setUpPatchSetNav(JsArray<RevisionInfo> list, DiffInfo.FileMeta meta,
boolean editExists, int currentPatchSet, boolean open) {
boolean editExists, int currentPatchSet, boolean open, boolean binary) {
InlineHyperlink baseLink = null;
InlineHyperlink selectedLink = null;
if (sideA) {
@@ -110,7 +110,7 @@ class PatchSetSelectBox extends Composite {
if (!Patch.COMMIT_MSG.equals(path)) {
linkPanel.add(createDownloadLink());
}
if (open && idActive != null && Gerrit.isSignedIn()) {
if (!binary && open && idActive != null && Gerrit.isSignedIn()) {
if ((editExists && idActive.get() == 0)
|| (!editExists && idActive.get() == currentPatchSet)) {
linkPanel.add(createEditIcon());

View File

@@ -246,7 +246,7 @@ public class SideBySide extends Screen {
JsArray<RevisionInfo> list = info.revisions().values();
RevisionInfo.sortRevisionInfoByNumber(list);
diffTable.set(prefs, list, diff, edit != null, currentPatchSet,
changeStatus.isOpen());
changeStatus.isOpen(), diff.binary());
header.setChangeInfo(info);
}

View File

@@ -189,6 +189,9 @@ public class GetDiff implements RestReadView<FileResource> {
result.webLinks = links.isEmpty() ? null : links.toList();
if (!webLinksOnly) {
if (ps.isBinary()) {
result.binary = true;
}
if (ps.getDisplayMethodA() != DisplayMethod.NONE) {
result.metaA = new FileMeta();
result.metaA.name = MoreObjects.firstNonNull(ps.getOldName(),

View File

@@ -213,7 +213,8 @@ class PatchScriptBuilder {
content.getHeaderLines(), diffPrefs, a.dst, b.dst, edits,
a.displayMethod, b.displayMethod, a.mimeType.toString(),
b.mimeType.toString(), comments, history, hugeFile,
intralineDifferenceIsPossible, intralineFailure, intralineTimeout);
intralineDifferenceIsPossible, intralineFailure, intralineTimeout,
content.getPatchType() == Patch.PatchType.BINARY);
}
private static boolean isModify(PatchListEntry content) {