SideBySide2: Honor some diff preferences
Honor the user's stored settings for: * ignore whitespace * show whitespace errors * intraline difference * tab size * syntax highlighting Initialize the preferences in the constructor. Later when preferences are editable on the fly some will force the screen to reload, while others might be applied on the fly. Change-Id: I31a039d834c9f38f1ca2678433bd76c7c42f8154
This commit is contained in:
@@ -17,6 +17,7 @@ package com.google.gerrit.client.diff;
|
|||||||
import com.google.gerrit.client.changes.ChangeApi;
|
import com.google.gerrit.client.changes.ChangeApi;
|
||||||
import com.google.gerrit.client.rpc.NativeMap;
|
import com.google.gerrit.client.rpc.NativeMap;
|
||||||
import com.google.gerrit.client.rpc.RestApi;
|
import com.google.gerrit.client.rpc.RestApi;
|
||||||
|
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
|
||||||
@@ -51,6 +52,20 @@ public class DiffApi {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DiffApi ignoreWhitespace(AccountDiffPreference.Whitespace w) {
|
||||||
|
switch (w) {
|
||||||
|
default:
|
||||||
|
case IGNORE_NONE:
|
||||||
|
return ignoreWhitespace(IgnoreWhitespace.NONE);
|
||||||
|
case IGNORE_SPACE_AT_EOL:
|
||||||
|
return ignoreWhitespace(IgnoreWhitespace.TRAILING);
|
||||||
|
case IGNORE_SPACE_CHANGE:
|
||||||
|
return ignoreWhitespace(IgnoreWhitespace.CHANGED);
|
||||||
|
case IGNORE_ALL_SPACE:
|
||||||
|
return ignoreWhitespace(IgnoreWhitespace.ALL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public DiffApi ignoreWhitespace(IgnoreWhitespace w) {
|
public DiffApi ignoreWhitespace(IgnoreWhitespace w) {
|
||||||
if (w != null && w != IgnoreWhitespace.NONE) {
|
if (w != null && w != IgnoreWhitespace.NONE) {
|
||||||
call.addParameter("ignore-whitespace", w);
|
call.addParameter("ignore-whitespace", w);
|
||||||
@@ -58,8 +73,10 @@ public class DiffApi {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiffApi intraline() {
|
public DiffApi intraline(boolean intraline) {
|
||||||
call.addParameterTrue("intraline");
|
if (intraline) {
|
||||||
|
call.addParameterTrue("intraline");
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ public class SideBySide2 extends Screen {
|
|||||||
private final PatchSet.Id base;
|
private final PatchSet.Id base;
|
||||||
private final PatchSet.Id revision;
|
private final PatchSet.Id revision;
|
||||||
private final String path;
|
private final String path;
|
||||||
|
private AccountDiffPreference pref;
|
||||||
|
|
||||||
private CodeMirror cmA;
|
private CodeMirror cmA;
|
||||||
private CodeMirror cmB;
|
private CodeMirror cmB;
|
||||||
@@ -147,6 +148,13 @@ public class SideBySide2 extends Screen {
|
|||||||
this.base = base;
|
this.base = base;
|
||||||
this.revision = revision;
|
this.revision = revision;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
|
||||||
|
pref = Gerrit.getAccountDiffPreference();
|
||||||
|
if (pref == null) {
|
||||||
|
pref = AccountDiffPreference.createDefault(null);
|
||||||
|
}
|
||||||
|
context = pref.getContext();
|
||||||
|
|
||||||
this.handlers = new ArrayList<HandlerRegistration>(6);
|
this.handlers = new ArrayList<HandlerRegistration>(6);
|
||||||
// TODO: Re-implement necessary GlobalKey bindings.
|
// TODO: Re-implement necessary GlobalKey bindings.
|
||||||
addDomHandler(GlobalKey.STOP_PROPAGATION, KeyPressEvent.getType());
|
addDomHandler(GlobalKey.STOP_PROPAGATION, KeyPressEvent.getType());
|
||||||
@@ -175,8 +183,8 @@ public class SideBySide2 extends Screen {
|
|||||||
DiffApi.diff(revision, path)
|
DiffApi.diff(revision, path)
|
||||||
.base(base)
|
.base(base)
|
||||||
.wholeFile()
|
.wholeFile()
|
||||||
.intraline()
|
.intraline(pref.isIntralineDifference())
|
||||||
.ignoreWhitespace(DiffApi.IgnoreWhitespace.NONE)
|
.ignoreWhitespace(pref.getIgnoreWhitespace())
|
||||||
.get(cmGroup.addFinal(new GerritCallback<DiffInfo>() {
|
.get(cmGroup.addFinal(new GerritCallback<DiffInfo>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(DiffInfo diffInfo) {
|
public void onSuccess(DiffInfo diffInfo) {
|
||||||
@@ -461,11 +469,11 @@ public class SideBySide2 extends Screen {
|
|||||||
Configuration cfg = Configuration.create()
|
Configuration cfg = Configuration.create()
|
||||||
.set("readOnly", true)
|
.set("readOnly", true)
|
||||||
.set("lineNumbers", true)
|
.set("lineNumbers", true)
|
||||||
.set("tabSize", 2)
|
.set("tabSize", pref.getTabSize())
|
||||||
.set("mode", getContentType(meta))
|
.set("mode", getContentType(meta))
|
||||||
.set("lineWrapping", true)
|
.set("lineWrapping", true)
|
||||||
.set("styleSelectedText", true)
|
.set("styleSelectedText", true)
|
||||||
.set("showTrailingSpace", true)
|
.set("showTrailingSpace", pref.isShowWhitespaceErrors())
|
||||||
.set("keyMap", "vim_ro")
|
.set("keyMap", "vim_ro")
|
||||||
.set("value", contents)
|
.set("value", contents)
|
||||||
/**
|
/**
|
||||||
@@ -481,10 +489,6 @@ public class SideBySide2 extends Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void render(DiffInfo diff) {
|
private void render(DiffInfo diff) {
|
||||||
AccountDiffPreference pref = Gerrit.getAccountDiffPreference();
|
|
||||||
context = pref != null
|
|
||||||
? pref.getContext()
|
|
||||||
: AccountDiffPreference.DEFAULT_CONTEXT;
|
|
||||||
JsArray<Region> regions = diff.content();
|
JsArray<Region> regions = diff.content();
|
||||||
String diffColor = diff.meta_a() == null || diff.meta_b() == null
|
String diffColor = diff.meta_a() == null || diff.meta_b() == null
|
||||||
? DiffTable.style.intralineBg()
|
? DiffTable.style.intralineBg()
|
||||||
@@ -1241,8 +1245,10 @@ public class SideBySide2 extends Screen {
|
|||||||
ele.getStyle().setHeight(height, Unit.PX);
|
ele.getStyle().setHeight(height, Unit.PX);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getContentType(DiffInfo.FileMeta meta) {
|
private String getContentType(DiffInfo.FileMeta meta) {
|
||||||
return meta != null && meta.content_type() != null
|
return pref.isSyntaxHighlighting()
|
||||||
|
&& meta != null
|
||||||
|
&& meta.content_type() != null
|
||||||
? ModeInjector.getContentType(meta.content_type())
|
? ModeInjector.getContentType(meta.content_type())
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user