From 84a66d82d36d554c1844acff11d1a62f10c174ed Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Sat, 18 Jan 2014 21:38:32 +0100 Subject: [PATCH] SideBySide2: Add preference for a subset of supported CM3 themes Add support for CM3 themes. CM3 has built in support for themes. Unfortunately we can not use all of them out of the box, because we set statically background colors on diff styles. However we can use light themes. Especially "eclipse" theme looks very sexy for Java developers that use this IDE and are acquainted with its look and feel. Integrate all supported themes in Buck tool chain, so that we are prepared to extend the support for dark themes. To do that we must dynamically assign background colors for different diff styles per theme. Change-Id: Ic97c237d789dc4daeff6b8bb4f7606da83f5d532 --- .../client/account/DiffPreferences.java | 14 ++++++ .../gerrit/client/diff/PreferencesBox.java | 43 +++++++++++++++++++ .../gerrit/client/diff/PreferencesBox.ui.xml | 4 ++ .../gerrit/client/diff/SideBySide2.java | 1 + .../client/AccountDiffPreference.java | 19 ++++++++ .../server/account/GetDiffPreferences.java | 3 ++ .../server/account/SetDiffPreferences.java | 5 +++ .../gerrit/server/schema/SchemaVersion.java | 2 +- .../gerrit/server/schema/Schema_93.java | 25 +++++++++++ lib/codemirror/cm3.defs | 27 ++++++++++++ 10 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_93.java 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 5600a24a71..5c66f3c47c 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 @@ -15,6 +15,7 @@ package com.google.gerrit.client.account; import com.google.gerrit.reviewdb.client.AccountDiffPreference; +import com.google.gerrit.reviewdb.client.AccountDiffPreference.Theme; import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace; import com.google.gwt.core.client.JavaScriptObject; @@ -38,6 +39,7 @@ public class DiffPreferences extends JavaScriptObject { p.expandAllComments(in.isExpandAllComments()); p.manualReview(in.isManualReview()); p.renderEntireFile(in.isRenderEntireFile()); + p.theme(in.getTheme()); return p; } @@ -56,6 +58,7 @@ public class DiffPreferences extends JavaScriptObject { p.setExpandAllComments(expandAllComments()); p.setManualReview(manualReview()); p.setRenderEntireFile(renderEntireFile()); + p.setTheme(theme()); } public final void ignoreWhitespace(Whitespace i) { @@ -63,6 +66,11 @@ public class DiffPreferences extends JavaScriptObject { } private final native void setIgnoreWhitespaceRaw(String i) /*-{ this.ignore_whitespace = i }-*/; + public final void theme(Theme i) { + setThemeRaw(i != null ? i.toString() : Theme.DEFAULT.toString()); + } + private final native void setThemeRaw(String i) /*-{ this.theme = i }-*/; + public final native void tabSize(int t) /*-{ this.tab_size = t }-*/; public final native void lineLength(int c) /*-{ this.line_length = c }-*/; public final native void context(int c) /*-{ this.context = c }-*/; @@ -84,6 +92,12 @@ public class DiffPreferences extends JavaScriptObject { } private final native String ignoreWhitespaceRaw() /*-{ return this.ignore_whitespace }-*/; + public final Theme theme() { + String s = themeRaw(); + return s != null ? Theme.valueOf(s) : Theme.DEFAULT; + } + private final native String themeRaw() /*-{ return this.theme }-*/; + public final int tabSize() {return get("tab_size", 8); } public final int context() {return get("context", 10); } public final int lineLength() {return get("line_length", 100); } 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 6fb0681e4a..b4ac7f2670 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 @@ -29,6 +29,7 @@ import com.google.gerrit.client.patches.PatchUtil; import com.google.gerrit.client.rpc.GerritCallback; import com.google.gerrit.client.ui.NpIntTextBox; import com.google.gerrit.reviewdb.client.AccountDiffPreference; +import com.google.gerrit.reviewdb.client.AccountDiffPreference.Theme; import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ChangeEvent; @@ -81,6 +82,7 @@ class PreferencesBox extends Composite { @UiField ToggleButton manualReview; @UiField ToggleButton expandAllComments; @UiField ToggleButton renderEntireFile; + @UiField ListBox theme; @UiField Button apply; @UiField Button save; @@ -89,6 +91,7 @@ class PreferencesBox extends Composite { initWidget(uiBinder.createAndBindUi(this)); initIgnoreWhitespace(); + initTheme(); } @Override @@ -130,6 +133,7 @@ class PreferencesBox extends Composite { manualReview.setValue(prefs.manualReview()); expandAllComments.setValue(prefs.expandAllComments()); renderEntireFile.setValue(prefs.renderEntireFile()); + setTheme(prefs.theme()); switch (view.getIntraLineStatus()) { case OFF: @@ -295,6 +299,19 @@ class PreferencesBox extends Composite { view.updateRenderEntireFile(); } + @UiHandler("theme") + void onTheme(ChangeEvent e) { + prefs.theme(Theme.valueOf(theme.getValue(theme.getSelectedIndex()))); + view.operation(new Runnable() { + @Override + public void run() { + String t = prefs.theme().name().toLowerCase(); + view.getCmFromSide(DisplaySide.A).setOption("theme", t); + view.getCmFromSide(DisplaySide.B).setOption("theme", t); + } + }); + } + @UiHandler("apply") void onApply(ClickEvent e) { close(); @@ -355,4 +372,30 @@ class PreferencesBox extends Composite { PatchUtil.C.whitespaceIGNORE_ALL_SPACE(), IGNORE_ALL_SPACE.name()); } + + private void setTheme(Theme v) { + String name = v != null ? v.name() : Theme.DEFAULT.name(); + for (int i = 0; i < theme.getItemCount(); i++) { + if (theme.getValue(i).equals(name)) { + theme.setSelectedIndex(i); + return; + } + } + theme.setSelectedIndex(0); + } + + private void initTheme() { + theme.addItem( + Theme.DEFAULT.name().toLowerCase(), + Theme.DEFAULT.name()); + theme.addItem( + Theme.ECLIPSE.name().toLowerCase(), + Theme.ECLIPSE.name()); + theme.addItem( + Theme.ELEGANT.name().toLowerCase(), + Theme.ELEGANT.name()); + theme.addItem( + Theme.NEAT.name().toLowerCase(), + Theme.NEAT.name()); + } } 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 fd9c5a2acf..d940590967 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 @@ -161,6 +161,10 @@ limitations under the License.
+ + + + diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/SideBySide2.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/SideBySide2.java index 1f8c27165a..b69c57d0fc 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/SideBySide2.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/SideBySide2.java @@ -545,6 +545,7 @@ public class SideBySide2 extends Screen { .set("styleSelectedText", true) .set("showTrailingSpace", prefs.showWhitespaceErrors()) .set("keyMap", "vim_ro") + .set("theme", prefs.theme().name().toLowerCase()) .set("value", meta != null ? contents : "") .set("viewportMargin", prefs.renderEntireFile() ? POSITIVE_INFINITY : 10)); } diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/AccountDiffPreference.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/AccountDiffPreference.java index 4c74b5fae0..7d73574095 100644 --- a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/AccountDiffPreference.java +++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/AccountDiffPreference.java @@ -55,9 +55,17 @@ public class AccountDiffPreference { } } + public static enum Theme { + DEFAULT, + ECLIPSE, + ELEGANT, + NEAT, + } + public static AccountDiffPreference createDefault(Account.Id accountId) { AccountDiffPreference p = new AccountDiffPreference(accountId); p.setIgnoreWhitespace(Whitespace.IGNORE_NONE); + p.setTheme(Theme.DEFAULT); p.setTabSize(8); p.setLineLength(100); p.setSyntaxHighlighting(true); @@ -125,6 +133,9 @@ public class AccountDiffPreference { @Column(id = 18) protected boolean renderEntireFile; + @Column(id = 19, length = 20, notNull = false) + protected String theme; + protected AccountDiffPreference() { } @@ -295,4 +306,12 @@ public class AccountDiffPreference { public void setRenderEntireFile(boolean render) { renderEntireFile = render; } + + public Theme getTheme() { + return theme != null ? Theme.valueOf(theme) : null; + } + + public void setTheme(Theme theme) { + this.theme = theme != null ? theme.name() : null; + } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/GetDiffPreferences.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/GetDiffPreferences.java index 94189287e3..ccb0418234 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/GetDiffPreferences.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/GetDiffPreferences.java @@ -18,6 +18,7 @@ import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.RestReadView; import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.AccountDiffPreference; +import com.google.gerrit.reviewdb.client.AccountDiffPreference.Theme; import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace; import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.CurrentUser; @@ -71,6 +72,7 @@ public class GetDiffPreferences implements RestReadView { info.syntaxHighlighting = p.isSyntaxHighlighting() ? true : null; info.tabSize = p.getTabSize(); info.renderEntireFile = p.isRenderEntireFile() ? true : null; + info.theme = p.getTheme(); return info; } @@ -91,5 +93,6 @@ public class GetDiffPreferences implements RestReadView { public Boolean hideLineNumbers; public Boolean renderEntireFile; public int tabSize; + public Theme theme; } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/SetDiffPreferences.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/SetDiffPreferences.java index d773303c36..146f2417d9 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/SetDiffPreferences.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/SetDiffPreferences.java @@ -18,6 +18,7 @@ import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.RestModifyView; import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.AccountDiffPreference; +import com.google.gerrit.reviewdb.client.AccountDiffPreference.Theme; import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace; import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.CurrentUser; @@ -48,6 +49,7 @@ public class SetDiffPreferences implements RestModifyView self; @@ -131,6 +133,9 @@ public class SetDiffPreferences implements RestModifyView C = Schema_92.class; + public static final Class C = Schema_93.class; public static class Module extends AbstractModule { @Override diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_93.java b/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_93.java new file mode 100644 index 0000000000..3132aa4e4f --- /dev/null +++ b/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_93.java @@ -0,0 +1,25 @@ +// Copyright (C) 2014 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.server.schema; + +import com.google.inject.Inject; +import com.google.inject.Provider; + +public class Schema_93 extends SchemaVersion { + @Inject + Schema_93(Provider prior) { + super(prior); + } +} diff --git a/lib/codemirror/cm3.defs b/lib/codemirror/cm3.defs index 8de280a711..3b8390ccdf 100644 --- a/lib/codemirror/cm3.defs +++ b/lib/codemirror/cm3.defs @@ -1,6 +1,33 @@ CM3_CSS = [ 'lib/codemirror.css', 'addon/dialog/dialog.css', + 'theme/3024-day.css', + 'theme/3024-night.css', + 'theme/ambiance-mobile.css', + 'theme/ambiance.css', + 'theme/base16-dark.css', + 'theme/base16-light.css', + 'theme/blackboard.css', + 'theme/cobalt.css', + 'theme/eclipse.css', + 'theme/elegant.css', + 'theme/erlang-dark.css', + 'theme/lesser-dark.css', + 'theme/mbo.css', + 'theme/midnight.css', + 'theme/monokai.css', + 'theme/neat.css', + 'theme/night.css', + 'theme/paraiso-dark.css', + 'theme/paraiso-light.css', + 'theme/rubyblue.css', + 'theme/solarized.css', + 'theme/the-matrix.css', + 'theme/tomorrow-night-eighties.css', + 'theme/twilight.css', + 'theme/vibrant-ink.css', + 'theme/xq-dark.css', + 'theme/xq-light.css', ] CM3_JS = [
Theme
Ignore Whitespace