Merge "SideBySide2: Add preference for a subset of supported CM3 themes"

This commit is contained in:
Shawn Pearce
2014-01-21 22:36:44 +00:00
committed by Gerrit Code Review
10 changed files with 142 additions and 1 deletions

View File

@@ -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); }

View File

@@ -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());
}
}

View File

@@ -161,6 +161,10 @@ limitations under the License.
</table>
<hr/>
<table class='{style.table}'>
<tr>
<th><ui:msg>Theme</ui:msg></th>
<td><g:ListBox ui:field='theme'/></td>
</tr>
<tr>
<th><ui:msg>Ignore Whitespace</ui:msg></th>
<td><g:ListBox ui:field='ignoreWhitespace'/></td>

View File

@@ -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));
}

View File

@@ -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;
}
}

View File

@@ -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<AccountResource> {
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<AccountResource> {
public Boolean hideLineNumbers;
public Boolean renderEntireFile;
public int tabSize;
public Theme theme;
}
}

View File

@@ -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<AccountResource, Input
Boolean hideLineNumbers;
Boolean renderEntireFile;
Integer tabSize;
Theme theme;
}
private final Provider<CurrentUser> self;
@@ -131,6 +133,9 @@ public class SetDiffPreferences implements RestModifyView<AccountResource, Input
if (input.tabSize != null) {
p.setTabSize(input.tabSize);
}
if (input.theme != null) {
p.setTheme(input.theme);
}
db.accountDiffPreferences().upsert(Collections.singleton(p));
db.commit();

View File

@@ -32,7 +32,7 @@ import java.util.List;
/** A version of the database schema. */
public abstract class SchemaVersion {
/** The current schema version. */
public static final Class<Schema_92> C = Schema_92.class;
public static final Class<Schema_93> C = Schema_93.class;
public static class Module extends AbstractModule {
@Override

View File

@@ -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<Schema_92> prior) {
super(prior);
}
}

View File

@@ -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 = [