Add settings screen for global edit preferences

Users expect to find all preferences under the Settings menu. Account
preferences and diff preferences are already there, so add the edit
preferences too.

Similar to the diff preferences the edit preferences are rendered with
the same style as the edit preferences popup. This makes it easy for
users to see that these are actually the same settings, just accessed
through different paths.

Change-Id: I4f2c41d77a0ad43777a904155623cbe31bff284a
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2015-10-13 10:55:41 +02:00
parent 8a389c3830
commit 753169d872
8 changed files with 126 additions and 37 deletions

View File

@@ -26,6 +26,7 @@ public class PageLinks {
public static final String SETTINGS = "/settings/"; public static final String SETTINGS = "/settings/";
public static final String SETTINGS_PREFERENCES = "/settings/preferences"; public static final String SETTINGS_PREFERENCES = "/settings/preferences";
public static final String SETTINGS_DIFF_PREFERENCES = "/settings/diff-preferences"; public static final String SETTINGS_DIFF_PREFERENCES = "/settings/diff-preferences";
public static final String SETTINGS_EDIT_PREFERENCES = "/settings/edit-preferences";
public static final String SETTINGS_SSHKEYS = "/settings/ssh-keys"; public static final String SETTINGS_SSHKEYS = "/settings/ssh-keys";
public static final String SETTINGS_GPGKEYS = "/settings/gpg-keys"; public static final String SETTINGS_GPGKEYS = "/settings/gpg-keys";
public static final String SETTINGS_HTTP_PASSWORD = "/settings/http-password"; public static final String SETTINGS_HTTP_PASSWORD = "/settings/http-password";

View File

@@ -29,6 +29,7 @@ import static com.google.gerrit.common.PageLinks.SETTINGS;
import static com.google.gerrit.common.PageLinks.SETTINGS_AGREEMENTS; import static com.google.gerrit.common.PageLinks.SETTINGS_AGREEMENTS;
import static com.google.gerrit.common.PageLinks.SETTINGS_CONTACT; import static com.google.gerrit.common.PageLinks.SETTINGS_CONTACT;
import static com.google.gerrit.common.PageLinks.SETTINGS_DIFF_PREFERENCES; import static com.google.gerrit.common.PageLinks.SETTINGS_DIFF_PREFERENCES;
import static com.google.gerrit.common.PageLinks.SETTINGS_EDIT_PREFERENCES;
import static com.google.gerrit.common.PageLinks.SETTINGS_EXTENSION; import static com.google.gerrit.common.PageLinks.SETTINGS_EXTENSION;
import static com.google.gerrit.common.PageLinks.SETTINGS_GPGKEYS; import static com.google.gerrit.common.PageLinks.SETTINGS_GPGKEYS;
import static com.google.gerrit.common.PageLinks.SETTINGS_HTTP_PASSWORD; import static com.google.gerrit.common.PageLinks.SETTINGS_HTTP_PASSWORD;
@@ -43,6 +44,7 @@ import static com.google.gerrit.common.PageLinks.toChangeQuery;
import com.google.gerrit.client.account.MyAgreementsScreen; import com.google.gerrit.client.account.MyAgreementsScreen;
import com.google.gerrit.client.account.MyContactInformationScreen; import com.google.gerrit.client.account.MyContactInformationScreen;
import com.google.gerrit.client.account.MyDiffPreferencesScreen; import com.google.gerrit.client.account.MyDiffPreferencesScreen;
import com.google.gerrit.client.account.MyEditPreferencesScreen;
import com.google.gerrit.client.account.MyGpgKeysScreen; import com.google.gerrit.client.account.MyGpgKeysScreen;
import com.google.gerrit.client.account.MyGroupsScreen; import com.google.gerrit.client.account.MyGroupsScreen;
import com.google.gerrit.client.account.MyIdentitiesScreen; import com.google.gerrit.client.account.MyIdentitiesScreen;
@@ -533,6 +535,10 @@ public class Dispatcher {
return new MyDiffPreferencesScreen(); return new MyDiffPreferencesScreen();
} }
if (matchExact(SETTINGS_EDIT_PREFERENCES, token)) {
return new MyEditPreferencesScreen();
}
if (matchExact(SETTINGS_PROJECTS, token)) { if (matchExact(SETTINGS_PROJECTS, token)) {
return new MyWatchedProjectsScreen(); return new MyWatchedProjectsScreen();
} }

View File

@@ -53,6 +53,7 @@ public interface AccountConstants extends Constants {
String tabAgreements(); String tabAgreements();
String tabContactInformation(); String tabContactInformation();
String tabDiffPreferences(); String tabDiffPreferences();
String tabEditPreferences();
String tabGpgKeys(); String tabGpgKeys();
String tabHttpAccess(); String tabHttpAccess();
String tabMyGroups(); String tabMyGroups();

View File

@@ -39,6 +39,7 @@ tabAccountSummary = Profile
tabAgreements = Agreements tabAgreements = Agreements
tabContactInformation = Contact Information tabContactInformation = Contact Information
tabDiffPreferences = Diff Preferences tabDiffPreferences = Diff Preferences
tabEditPreferences = Edit Preferences
tabGpgKeys = GPG Public Keys tabGpgKeys = GPG Public Keys
tabHttpAccess = HTTP Password tabHttpAccess = HTTP Password
tabMyGroups = Groups tabMyGroups = Groups

View File

@@ -0,0 +1,40 @@
// Copyright (C) 2015 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.client.account;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.editor.EditPreferencesBox;
import com.google.gwt.user.client.ui.FlowPanel;
public class MyEditPreferencesScreen extends SettingsScreen {
@Override
protected void onInitUI() {
super.onInitUI();
EditPreferencesBox pb = new EditPreferencesBox(null);
pb.set(EditPreferences.create(Gerrit.getEditPreferences()));
FlowPanel p = new FlowPanel();
p.setStyleName(pb.getStyle().dialog());
p.add(pb);
add(p);
}
@Override
protected void onLoad() {
super.onLoad();
display();
}
}

View File

@@ -38,6 +38,7 @@ public abstract class SettingsScreen extends MenuScreen {
linkByGerrit(Util.C.tabAccountSummary(), PageLinks.SETTINGS); linkByGerrit(Util.C.tabAccountSummary(), PageLinks.SETTINGS);
linkByGerrit(Util.C.tabPreferences(), PageLinks.SETTINGS_PREFERENCES); linkByGerrit(Util.C.tabPreferences(), PageLinks.SETTINGS_PREFERENCES);
linkByGerrit(Util.C.tabDiffPreferences(), PageLinks.SETTINGS_DIFF_PREFERENCES); linkByGerrit(Util.C.tabDiffPreferences(), PageLinks.SETTINGS_DIFF_PREFERENCES);
linkByGerrit(Util.C.tabEditPreferences(), PageLinks.SETTINGS_EDIT_PREFERENCES);
linkByGerrit(Util.C.tabWatchedProjects(), PageLinks.SETTINGS_PROJECTS); linkByGerrit(Util.C.tabWatchedProjects(), PageLinks.SETTINGS_PROJECTS);
linkByGerrit(Util.C.tabContactInformation(), PageLinks.SETTINGS_CONTACT); linkByGerrit(Util.C.tabContactInformation(), PageLinks.SETTINGS_CONTACT);
if (Gerrit.info().hasSshd()) { if (Gerrit.info().hasSshd()) {

View File

@@ -23,6 +23,8 @@ import com.google.gerrit.client.ui.NpIntTextBox;
import com.google.gerrit.extensions.client.KeyMapType; import com.google.gerrit.extensions.client.KeyMapType;
import com.google.gerrit.extensions.client.Theme; import com.google.gerrit.extensions.client.Theme;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style.Visibility;
import com.google.gwt.event.dom.client.ChangeEvent; import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.logical.shared.ValueChangeEvent; import com.google.gwt.event.logical.shared.ValueChangeEvent;
@@ -37,15 +39,16 @@ import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.PopupPanel; import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.ToggleButton; import com.google.gwt.user.client.ui.ToggleButton;
import com.google.gwt.user.client.ui.UIObject;
import net.codemirror.theme.ThemeLoader; import net.codemirror.theme.ThemeLoader;
/** Displays current edit preferences. */ /** Displays current edit preferences. */
class EditPreferencesBox extends Composite { public class EditPreferencesBox extends Composite {
interface Binder extends UiBinder<HTMLPanel, EditPreferencesBox> {} interface Binder extends UiBinder<HTMLPanel, EditPreferencesBox> {}
private static final Binder uiBinder = GWT.create(Binder.class); private static final Binder uiBinder = GWT.create(Binder.class);
interface Style extends CssResource { public interface Style extends CssResource {
String dialog(); String dialog();
} }
@@ -53,6 +56,7 @@ class EditPreferencesBox extends Composite {
private EditPreferences prefs; private EditPreferences prefs;
@UiField Style style; @UiField Style style;
@UiField Element header;
@UiField Anchor close; @UiField Anchor close;
@UiField NpIntTextBox tabWidth; @UiField NpIntTextBox tabWidth;
@UiField NpIntTextBox lineLength; @UiField NpIntTextBox lineLength;
@@ -69,14 +73,23 @@ class EditPreferencesBox extends Composite {
@UiField Button apply; @UiField Button apply;
@UiField Button save; @UiField Button save;
EditPreferencesBox(EditScreen view) { public EditPreferencesBox(EditScreen view) {
this.view = view; this.view = view;
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
initTheme(); initTheme();
initKeyMapType(); initKeyMapType();
if (view == null) {
UIObject.setVisible(header, false);
apply.getElement().getStyle().setVisibility(Visibility.HIDDEN);
}
} }
void set(EditPreferences prefs) { public Style getStyle() {
return style;
}
public void set(EditPreferences prefs) {
this.prefs = prefs; this.prefs = prefs;
tabWidth.setIntValue(prefs.tabSize()); tabWidth.setIntValue(prefs.tabSize());
@@ -98,7 +111,9 @@ class EditPreferencesBox extends Composite {
String v = e.getValue(); String v = e.getValue();
if (v != null && v.length() > 0) { if (v != null && v.length() > 0) {
prefs.tabSize(Math.max(1, Integer.parseInt(v))); prefs.tabSize(Math.max(1, Integer.parseInt(v)));
view.getEditor().setOption("tabSize", v); if (view != null) {
view.getEditor().setOption("tabSize", v);
}
} }
} }
@@ -107,7 +122,9 @@ class EditPreferencesBox extends Composite {
String v = e.getValue(); String v = e.getValue();
if (v != null && v.length() > 0) { if (v != null && v.length() > 0) {
prefs.lineLength(Math.max(1, Integer.parseInt(v))); prefs.lineLength(Math.max(1, Integer.parseInt(v)));
view.setLineLength(prefs.lineLength()); if (view != null) {
view.setLineLength(prefs.lineLength());
}
} }
} }
@@ -118,69 +135,87 @@ class EditPreferencesBox extends Composite {
// A negative value hides the cursor entirely: // A negative value hides the cursor entirely:
// don't let user shoot himself in the foot. // don't let user shoot himself in the foot.
prefs.cursorBlinkRate(Math.max(0, Integer.parseInt(v))); prefs.cursorBlinkRate(Math.max(0, Integer.parseInt(v)));
view.getEditor().setOption("cursorBlinkRate", prefs.cursorBlinkRate()); if (view != null) {
view.getEditor().setOption("cursorBlinkRate", prefs.cursorBlinkRate());
}
} }
} }
@UiHandler("topMenu") @UiHandler("topMenu")
void onTopMenu(ValueChangeEvent<Boolean> e) { void onTopMenu(ValueChangeEvent<Boolean> e) {
prefs.hideTopMenu(!e.getValue()); prefs.hideTopMenu(!e.getValue());
Gerrit.setHeaderVisible(!prefs.hideTopMenu()); if (view != null) {
view.resizeCodeMirror(); Gerrit.setHeaderVisible(!prefs.hideTopMenu());
view.resizeCodeMirror();
}
} }
@UiHandler("showTabs") @UiHandler("showTabs")
void onShowTabs(ValueChangeEvent<Boolean> e) { void onShowTabs(ValueChangeEvent<Boolean> e) {
prefs.showTabs(e.getValue()); prefs.showTabs(e.getValue());
view.setShowTabs(prefs.showTabs()); if (view != null) {
view.setShowTabs(prefs.showTabs());
}
} }
@UiHandler("whitespaceErrors") @UiHandler("whitespaceErrors")
void onshowTrailingSpace(ValueChangeEvent<Boolean> e) { void onshowTrailingSpace(ValueChangeEvent<Boolean> e) {
prefs.showWhitespaceErrors(e.getValue()); prefs.showWhitespaceErrors(e.getValue());
view.setShowWhitespaceErrors(prefs.showWhitespaceErrors()); if (view != null) {
view.setShowWhitespaceErrors(prefs.showWhitespaceErrors());
}
} }
@UiHandler("lineNumbers") @UiHandler("lineNumbers")
void onLineNumbers(ValueChangeEvent<Boolean> e) { void onLineNumbers(ValueChangeEvent<Boolean> e) {
prefs.hideLineNumbers(e.getValue()); prefs.hideLineNumbers(e.getValue());
view.setShowLineNumbers(prefs.hideLineNumbers()); if (view != null) {
view.setShowLineNumbers(prefs.hideLineNumbers());
}
} }
@UiHandler("syntaxHighlighting") @UiHandler("syntaxHighlighting")
void onSyntaxHighlighting(ValueChangeEvent<Boolean> e) { void onSyntaxHighlighting(ValueChangeEvent<Boolean> e) {
prefs.syntaxHighlighting(e.getValue()); prefs.syntaxHighlighting(e.getValue());
view.setSyntaxHighlighting(prefs.syntaxHighlighting()); if (view != null) {
view.setSyntaxHighlighting(prefs.syntaxHighlighting());
}
} }
@UiHandler("matchBrackets") @UiHandler("matchBrackets")
void onMatchBrackets(ValueChangeEvent<Boolean> e) { void onMatchBrackets(ValueChangeEvent<Boolean> e) {
prefs.matchBrackets(e.getValue()); prefs.matchBrackets(e.getValue());
view.getEditor().setOption("matchBrackets", prefs.matchBrackets()); if (view != null) {
view.getEditor().setOption("matchBrackets", prefs.matchBrackets());
}
} }
@UiHandler("autoCloseBrackets") @UiHandler("autoCloseBrackets")
void onCloseBrackets(ValueChangeEvent<Boolean> e) { void onCloseBrackets(ValueChangeEvent<Boolean> e) {
prefs.autoCloseBrackets(e.getValue()); prefs.autoCloseBrackets(e.getValue());
view.getEditor().setOption("autoCloseBrackets", prefs.autoCloseBrackets()); if (view != null) {
view.getEditor().setOption("autoCloseBrackets", prefs.autoCloseBrackets());
}
} }
@UiHandler("theme") @UiHandler("theme")
void onTheme(@SuppressWarnings("unused") ChangeEvent e) { void onTheme(@SuppressWarnings("unused") ChangeEvent e) {
final Theme newTheme = Theme.valueOf(theme.getValue(theme.getSelectedIndex())); final Theme newTheme = Theme.valueOf(theme.getValue(theme.getSelectedIndex()));
prefs.theme(newTheme); prefs.theme(newTheme);
ThemeLoader.loadTheme(newTheme, new GerritCallback<Void>() { if (view != null) {
@Override ThemeLoader.loadTheme(newTheme, new GerritCallback<Void>() {
public void onSuccess(Void result) { @Override
view.getEditor().operation(new Runnable() { public void onSuccess(Void result) {
@Override view.getEditor().operation(new Runnable() {
public void run() { @Override
String t = newTheme.name().toLowerCase(); public void run() {
view.getEditor().setOption("theme", t); String t = newTheme.name().toLowerCase();
} view.getEditor().setOption("theme", t);
}); }
} });
}); }
});
}
} }
@UiHandler("keyMap") @UiHandler("keyMap")
@@ -188,7 +223,9 @@ class EditPreferencesBox extends Composite {
KeyMapType keyMapType = KeyMapType.valueOf( KeyMapType keyMapType = KeyMapType.valueOf(
keyMap.getValue(keyMap.getSelectedIndex())); keyMap.getValue(keyMap.getSelectedIndex()));
prefs.keyMapType(keyMapType); prefs.keyMapType(keyMapType);
view.getEditor().setOption("keyMap", keyMapType.name().toLowerCase()); if (view != null) {
view.getEditor().setOption("keyMap", keyMapType.name().toLowerCase());
}
} }
@UiHandler("apply") @UiHandler("apply")

View File

@@ -151,15 +151,17 @@ limitations under the License.
</ui:style> </ui:style>
<g:HTMLPanel styleName='{style.box}'> <g:HTMLPanel styleName='{style.box}'>
<table style='width: 100%'> <div ui:field='header'>
<tr> <table style='width: 100%'>
<td><ui:msg>Edit Preferences</ui:msg></td> <tr>
<td style='text-align: right'> <td><ui:msg>Edit Preferences</ui:msg></td>
<g:Anchor ui:field='close' href='javascript:;'><ui:msg>Close</ui:msg></g:Anchor> <td style='text-align: right'>
</td> <g:Anchor ui:field='close' href='javascript:;'><ui:msg>Close</ui:msg></g:Anchor>
</tr> </td>
</table> </tr>
<hr/> </table>
<hr/>
</div>
<table class='{style.table}'> <table class='{style.table}'>
<tr> <tr>
<th><ui:msg>Theme</ui:msg></th> <th><ui:msg>Theme</ui:msg></th>