From 188b8237ea44ef7343eab535b9dfad543811c330 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Sat, 20 Jun 2015 13:57:35 +0200 Subject: [PATCH] SideBySide: Allow to activate match brackets Codemirror addon Now, that we migrated diff user preferences to Git backend, we can make activation of codemirror option: "highlight matched brackets" customizable. Change-Id: I37c1c1ee13ff872e3cbc349a7c9fee636312402e --- Documentation/rest-api-accounts.txt | 2 ++ .../acceptance/rest/account/DiffPreferencesIT.java | 3 +++ .../gerrit/extensions/client/DiffPreferencesInfo.java | 4 +++- .../google/gerrit/client/account/DiffPreferences.java | 6 +++++- .../com/google/gerrit/client/diff/PreferencesBox.java | 11 +++++++++++ .../google/gerrit/client/diff/PreferencesBox.ui.xml | 7 +++++++ 6 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Documentation/rest-api-accounts.txt b/Documentation/rest-api-accounts.txt index 329c4cd16b..ad19046745 100644 --- a/Documentation/rest-api-accounts.txt +++ b/Documentation/rest-api-accounts.txt @@ -1709,6 +1709,8 @@ Number of spaces that should be used to display one tab. |'hide_empty_pane' |not set if `false`| Whether empty panes should be hidden. The left pane is empty when a file was added; the right pane is empty when a file was deleted. +|`match_brackets` |not set if `false`| +Whether matching brackets should be highlighted. |=========================================== [[diff-preferences-input]] diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/account/DiffPreferencesIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/account/DiffPreferencesIT.java index 38687a4578..5b2e7bab83 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/account/DiffPreferencesIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/account/DiffPreferencesIT.java @@ -63,6 +63,7 @@ public class DiffPreferencesIT extends AbstractDaemonTest { assertThat(o.hideLineNumbers).isNull(); assertThat(o.renderEntireFile).isNull(); assertThat(o.hideEmptyPane).isNull(); + assertThat(o.matchBrackets).isNull(); assertThat(o.ignoreWhitespace).isEqualTo(d.ignoreWhitespace); assertThat(o.theme).isEqualTo(d.theme); } @@ -93,6 +94,7 @@ public class DiffPreferencesIT extends AbstractDaemonTest { i.hideLineNumbers ^= true; i.renderEntireFile ^= true; i.hideEmptyPane ^= true; + i.matchBrackets ^= true; RestResponse r = adminSession.put("/accounts/" + admin.email + "/preferences.diff", i); @@ -119,6 +121,7 @@ public class DiffPreferencesIT extends AbstractDaemonTest { assertThat(o.hideLineNumbers).isEqualTo(i.hideLineNumbers); assertThat(o.renderEntireFile).isEqualTo(i.renderEntireFile); assertThat(o.hideEmptyPane).isEqualTo(i.hideEmptyPane); + assertThat(o.matchBrackets).isEqualTo(i.matchBrackets); assertThat(o.ignoreWhitespace).isEqualTo(i.ignoreWhitespace); assertThat(o.theme).isEqualTo(i.theme); diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/client/DiffPreferencesInfo.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/client/DiffPreferencesInfo.java index b52a4393f3..703f7b3905 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/client/DiffPreferencesInfo.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/client/DiffPreferencesInfo.java @@ -55,6 +55,7 @@ public class DiffPreferencesInfo { public Boolean hideLineNumbers; public Boolean renderEntireFile; public Boolean hideEmptyPane; + public Boolean matchBrackets; public Theme theme; public Whitespace ignoreWhitespace; public Boolean retainHeader; @@ -84,6 +85,7 @@ public class DiffPreferencesInfo { i.hideLineNumbers = false; i.renderEntireFile = false; i.hideEmptyPane = false; + i.matchBrackets = false; return i; } -} \ No newline at end of file +} diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/DiffPreferences.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/DiffPreferences.java index 8db8d21a40..7d543d86bd 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/DiffPreferences.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/DiffPreferences.java @@ -46,6 +46,7 @@ public class DiffPreferences extends JavaScriptObject { p.retainHeader(in.retainHeader); p.skipUncommented(in.skipUncommented); p.skipDeleted(in.skipDeleted); + p.matchBrackets(in.matchBrackets); return p; } @@ -69,6 +70,7 @@ public class DiffPreferences extends JavaScriptObject { p.hideLineNumbers = hideLineNumbers(); p.renderEntireFile = renderEntireFile(); p.hideEmptyPane = hideEmptyPane(); + p.matchBrackets = matchBrackets(); p.theme = theme(); p.ignoreWhitespace = ignoreWhitespace(); } @@ -134,10 +136,11 @@ public class DiffPreferences extends JavaScriptObject { public final native void expandAllComments(boolean e) /*-{ this.expand_all_comments = e }-*/; public final native void manualReview(boolean r) /*-{ this.manual_review = r }-*/; public final native void renderEntireFile(boolean r) /*-{ this.render_entire_file = r }-*/; - public final native void hideEmptyPane(boolean s) /*-{ this.hide_empty_pane = s }-*/; public final native void retainHeader(boolean r) /*-{ this.retain_header = r }-*/; + public final native void hideEmptyPane(boolean s) /*-{ this.hide_empty_pane = s }-*/; public final native void skipUncommented(boolean s) /*-{ this.skip_uncommented = s }-*/; public final native void skipDeleted(boolean s) /*-{ this.skip_deleted = s }-*/; + public final native void matchBrackets(boolean m) /*-{ this.match_brackets = m }-*/; public final native boolean intralineDifference() /*-{ return this.intraline_difference || false }-*/; public final native boolean showLineEndings() /*-{ return this.show_line_endings || false }-*/; public final native boolean showTabs() /*-{ return this.show_tabs || false }-*/; @@ -153,6 +156,7 @@ public class DiffPreferences extends JavaScriptObject { public final native boolean retainHeader() /*-{ return this.retain_header || false }-*/; public final native boolean skipUncommented() /*-{ return this.skip_uncommented || false }-*/; public final native boolean skipDeleted() /*-{ return this.skip_deleted || false }-*/; + public final native boolean matchBrackets() /*-{ return this.match_brackets || false }-*/; private final native void setThemeRaw(String i) /*-{ this.theme = i }-*/; private final native void setIgnoreWhitespaceRaw(String i) /*-{ this.ignore_whitespace = i }-*/; diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/PreferencesBox.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/PreferencesBox.java index f2f468ec1a..91baf90d19 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/PreferencesBox.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/PreferencesBox.java @@ -101,6 +101,7 @@ public class PreferencesBox extends Composite { @UiField ToggleButton manualReview; @UiField ToggleButton expandAllComments; @UiField ToggleButton renderEntireFile; + @UiField ToggleButton matchBrackets; @UiField ListBox theme; @UiField Element modeLabel; @UiField ListBox mode; @@ -192,6 +193,7 @@ public class PreferencesBox extends Composite { autoHideDiffTableHeader.setValue(!prefs.autoHideDiffTableHeader()); manualReview.setValue(prefs.manualReview()); expandAllComments.setValue(prefs.expandAllComments()); + matchBrackets.setValue(prefs.matchBrackets()); setTheme(prefs.theme()); if (view == null || view.canRenderEntireFile(prefs)) { @@ -482,6 +484,15 @@ public class PreferencesBox extends Composite { } } + @UiHandler("matchBrackets") + void onMatchBrackets(ValueChangeEvent e) { + prefs.matchBrackets(e.getValue()); + view.getCmFromSide(DisplaySide.A).setOption("matchBrackets", + prefs.matchBrackets()); + view.getCmFromSide(DisplaySide.B).setOption("matchBrackets", + prefs.matchBrackets()); + } + @UiHandler("theme") void onTheme(@SuppressWarnings("unused") ChangeEvent e) { final Theme newTheme = getSelectedTheme(); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/PreferencesBox.ui.xml b/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/PreferencesBox.ui.xml index 057d20deec..a2202ab54b 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/PreferencesBox.ui.xml +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/PreferencesBox.ui.xml @@ -289,6 +289,13 @@ limitations under the License. Slow + + Match Brackets + + Off + On + +