Add settings screen for global diff preferences

The account preferences are available under the Settings menu, but not
the diff preferences. The diff preferences are only accessible from
the diff screen by clicking on the gear icon. It's confusing to users
that they cannot find all preferences under the Settings menu. This is
why it makes sense to make the diff preferences available in the
Settings menu too.

There are a few diff settings which are only applicable when looking
at a concrete file diff and which are not stored on server side
(show/hide left side, language). These settings are not available when
the diff preferences are accessed from the Settings menu.

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

Change-Id: I35f45a4784592b9ce2fe35d86fd6974acc14f5c6
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2015-10-07 14:40:10 +02:00
parent bd567a0d3b
commit 7b6af4ff35
8 changed files with 237 additions and 118 deletions

View File

@@ -25,6 +25,7 @@ import com.google.gwtorm.client.KeyUtil;
public class PageLinks {
public static final String SETTINGS = "/settings/";
public static final String SETTINGS_PREFERENCES = "/settings/preferences";
public static final String SETTINGS_DIFF_PREFERENCES = "/settings/diff-preferences";
public static final String SETTINGS_SSHKEYS = "/settings/ssh-keys";
public static final String SETTINGS_GPGKEYS = "/settings/gpg-keys";
public static final String SETTINGS_HTTP_PASSWORD = "/settings/http-password";

View File

@@ -28,6 +28,7 @@ import static com.google.gerrit.common.PageLinks.REGISTER;
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_CONTACT;
import static com.google.gerrit.common.PageLinks.SETTINGS_DIFF_PREFERENCES;
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_HTTP_PASSWORD;
@@ -41,6 +42,7 @@ import static com.google.gerrit.common.PageLinks.toChangeQuery;
import com.google.gerrit.client.account.MyAgreementsScreen;
import com.google.gerrit.client.account.MyContactInformationScreen;
import com.google.gerrit.client.account.MyDiffPreferencesScreen;
import com.google.gerrit.client.account.MyGpgKeysScreen;
import com.google.gerrit.client.account.MyGroupsScreen;
import com.google.gerrit.client.account.MyIdentitiesScreen;
@@ -527,6 +529,10 @@ public class Dispatcher {
return new MyPreferencesScreen();
}
if (matchExact(SETTINGS_DIFF_PREFERENCES, token)) {
return new MyDiffPreferencesScreen();
}
if (matchExact(SETTINGS_PROJECTS, token)) {
return new MyWatchedProjectsScreen();
}

View File

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

View File

@@ -38,6 +38,7 @@ changeScreenNewUi = New Screen
tabAccountSummary = Profile
tabAgreements = Agreements
tabContactInformation = Contact Information
tabDiffPreferences = Diff Preferences
tabGpgKeys = GPG Public Keys
tabHttpAccess = HTTP Password
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.diff.PreferencesBox;
import com.google.gwt.user.client.ui.FlowPanel;
public class MyDiffPreferencesScreen extends SettingsScreen {
@Override
protected void onInitUI() {
super.onInitUI();
PreferencesBox pb = new PreferencesBox(null);
pb.set(DiffPreferences.create(Gerrit.getAccountDiffPreference()));
FlowPanel p = new FlowPanel();
p.setStyleName(pb.getStyle().dialog());
p.add(pb);
add(p);
}
@Override
protected void onLoad() {
super.onLoad();
display();
}
}

View File

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

View File

@@ -35,6 +35,8 @@ import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.Patch.ChangeType;
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.ClickEvent;
import com.google.gwt.event.dom.client.KeyDownEvent;
@@ -54,6 +56,7 @@ import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.ToggleButton;
import com.google.gwt.user.client.ui.UIObject;
import net.codemirror.mode.ModeInfo;
import net.codemirror.mode.ModeInjector;
@@ -62,11 +65,11 @@ import net.codemirror.theme.ThemeLoader;
import java.util.Objects;
/** Displays current diff preferences. */
class PreferencesBox extends Composite {
public class PreferencesBox extends Composite {
interface Binder extends UiBinder<HTMLPanel, PreferencesBox> {}
private static final Binder uiBinder = GWT.create(Binder.class);
interface Style extends CssResource {
public interface Style extends CssResource {
String dialog();
}
@@ -76,6 +79,7 @@ class PreferencesBox extends Composite {
private Timer updateContextTimer;
@UiField Style style;
@UiField Element header;
@UiField Anchor close;
@UiField ListBox ignoreWhitespace;
@UiField NpIntTextBox tabWidth;
@@ -87,6 +91,7 @@ class PreferencesBox extends Composite {
@UiField ToggleButton whitespaceErrors;
@UiField ToggleButton showTabs;
@UiField ToggleButton lineNumbers;
@UiField Element leftSideLabel;
@UiField ToggleButton leftSide;
@UiField ToggleButton emptyPane;
@UiField ToggleButton topMenu;
@@ -95,17 +100,24 @@ class PreferencesBox extends Composite {
@UiField ToggleButton expandAllComments;
@UiField ToggleButton renderEntireFile;
@UiField ListBox theme;
@UiField Element modeLabel;
@UiField ListBox mode;
@UiField Button apply;
@UiField Button save;
PreferencesBox(SideBySide view) {
public PreferencesBox(SideBySide view) {
this.view = view;
initWidget(uiBinder.createAndBindUi(this));
initIgnoreWhitespace();
initTheme();
if (view != null) {
initMode();
} else {
UIObject.setVisible(header, false);
apply.getElement().getStyle().setVisibility(Visibility.HIDDEN);
}
}
@Override
@@ -113,6 +125,8 @@ class PreferencesBox extends Composite {
super.onLoad();
save.setVisible(Gerrit.isSignedIn());
if (view != null) {
addDomHandler(new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
@@ -140,13 +154,18 @@ class PreferencesBox extends Composite {
}
};
}
}
void set(DiffPreferences prefs) {
public Style getStyle() {
return style;
}
public void set(DiffPreferences prefs) {
this.prefs = prefs;
setIgnoreWhitespace(prefs.ignoreWhitespace());
tabWidth.setIntValue(prefs.tabSize());
if (Patch.COMMIT_MSG.equals(view.getPath())) {
if (view != null && Patch.COMMIT_MSG.equals(view.getPath())) {
lineLength.setEnabled(false);
lineLength.setIntValue(72);
} else {
@@ -157,17 +176,22 @@ class PreferencesBox extends Composite {
whitespaceErrors.setValue(prefs.showWhitespaceErrors());
showTabs.setValue(prefs.showTabs());
lineNumbers.setValue(prefs.showLineNumbers());
leftSide.setValue(view.diffTable.isVisibleA());
emptyPane.setValue(!prefs.hideEmptyPane());
if (view != null) {
leftSide.setValue(view.diffTable.isVisibleA());
leftSide.setEnabled(!(prefs.hideEmptyPane()
&& view.diffTable.getChangeType() == ChangeType.ADDED));
} else {
UIObject.setVisible(leftSideLabel, false);
leftSide.setVisible(false);
}
topMenu.setValue(!prefs.hideTopMenu());
autoHideDiffTableHeader.setValue(!prefs.autoHideDiffTableHeader());
manualReview.setValue(prefs.manualReview());
expandAllComments.setValue(prefs.expandAllComments());
setTheme(prefs.theme());
if (view.canRenderEntireFile(prefs)) {
if (view == null || view.canRenderEntireFile(prefs)) {
renderEntireFile.setValue(prefs.renderEntireFile());
renderEntireFile.setEnabled(true);
} else {
@@ -175,11 +199,17 @@ class PreferencesBox extends Composite {
renderEntireFile.setEnabled(false);
}
if (view != null) {
mode.setEnabled(prefs.syntaxHighlighting());
if (prefs.syntaxHighlighting()) {
setMode(view.getCmFromSide(DisplaySide.B).getStringOption("mode"));
}
} else {
UIObject.setVisible(modeLabel, false);
mode.setVisible(false);
}
if (view != null) {
switch (view.getIntraLineStatus()) {
case OFF:
case OK:
@@ -192,6 +222,9 @@ class PreferencesBox extends Composite {
intralineDifference.setEnabled(false);
break;
}
} else {
intralineDifference.setValue(prefs.intralineDifference());
}
if (prefs.context() == WHOLE_FILE_CONTEXT) {
contextLastValue = DEFAULT_CONTEXT;
@@ -207,14 +240,18 @@ class PreferencesBox extends Composite {
void onIgnoreWhitespace(@SuppressWarnings("unused") ChangeEvent e) {
prefs.ignoreWhitespace(Whitespace.valueOf(
ignoreWhitespace.getValue(ignoreWhitespace.getSelectedIndex())));
if (view != null) {
view.reloadDiffInfo();
}
}
@UiHandler("intralineDifference")
void onIntralineDifference(ValueChangeEvent<Boolean> e) {
prefs.intralineDifference(e.getValue());
if (view != null) {
view.setShowIntraline(prefs.intralineDifference());
}
}
@UiHandler("context")
void onContextKey(KeyPressEvent e) {
@@ -239,8 +276,10 @@ class PreferencesBox extends Composite {
return;
}
prefs.context(c);
if (view != null) {
updateContextTimer.schedule(200);
}
}
@UiHandler("contextEntireFile")
void onContextEntireFile(ValueChangeEvent<Boolean> e) {
@@ -257,14 +296,17 @@ class PreferencesBox extends Composite {
context.setFocus(true);
context.setSelectionRange(0, context.getText().length());
}
if (view != null) {
updateContextTimer.schedule(200);
}
}
@UiHandler("tabWidth")
void onTabWidth(ValueChangeEvent<String> e) {
String v = e.getValue();
if (v != null && v.length() > 0) {
prefs.tabSize(Math.max(1, Integer.parseInt(v)));
if (view != null) {
view.operation(new Runnable() {
@Override
public void run() {
@@ -275,12 +317,14 @@ class PreferencesBox extends Composite {
});
}
}
}
@UiHandler("lineLength")
void onLineLength(ValueChangeEvent<String> e) {
String v = e.getValue();
if (v != null && v.length() > 0) {
prefs.lineLength(Math.max(1, Integer.parseInt(v)));
if (view != null) {
view.operation(new Runnable() {
@Override
public void run() {
@@ -289,23 +333,30 @@ class PreferencesBox extends Composite {
});
}
}
}
@UiHandler("expandAllComments")
void onExpandAllComments(ValueChangeEvent<Boolean> e) {
prefs.expandAllComments(e.getValue());
if (view != null) {
view.getCommentManager().setExpandAllComments(prefs.expandAllComments());
}
}
@UiHandler("showTabs")
void onShowTabs(ValueChangeEvent<Boolean> e) {
prefs.showTabs(e.getValue());
if (view != null) {
view.setShowTabs(prefs.showTabs());
}
}
@UiHandler("lineNumbers")
void onLineNumbers(ValueChangeEvent<Boolean> e) {
prefs.showLineNumbers(e.getValue());
if (view != null) {
view.setShowLineNumbers(prefs.showLineNumbers());
}
}
@UiHandler("leftSide")
void onLeftSide(ValueChangeEvent<Boolean> e) {
@@ -315,6 +366,7 @@ class PreferencesBox extends Composite {
@UiHandler("emptyPane")
void onHideEmptyPane(ValueChangeEvent<Boolean> e) {
prefs.hideEmptyPane(!e.getValue());
if (view != null) {
view.diffTable.setHideEmptyPane(prefs.hideEmptyPane());
if (prefs.hideEmptyPane()) {
if (view.diffTable.getChangeType() == ChangeType.ADDED) {
@@ -326,19 +378,24 @@ class PreferencesBox extends Composite {
leftSide.setEnabled(true);
}
}
}
@UiHandler("topMenu")
void onTopMenu(ValueChangeEvent<Boolean> e) {
prefs.hideTopMenu(!e.getValue());
if (view != null) {
Gerrit.setHeaderVisible(!prefs.hideTopMenu());
view.resizeCodeMirror();
}
}
@UiHandler("autoHideDiffTableHeader")
void onAutoHideDiffTableHeader(ValueChangeEvent<Boolean> e) {
prefs.autoHideDiffTableHeader(!e.getValue());
if (view != null) {
view.setAutoHideDiffHeader(!e.getValue());
}
}
@UiHandler("manualReview")
void onManualReview(ValueChangeEvent<Boolean> e) {
@@ -348,12 +405,14 @@ class PreferencesBox extends Composite {
@UiHandler("syntaxHighlighting")
void onSyntaxHighlighting(ValueChangeEvent<Boolean> e) {
prefs.syntaxHighlighting(e.getValue());
if (view != null) {
mode.setEnabled(prefs.syntaxHighlighting());
if (prefs.syntaxHighlighting()) {
setMode(view.getContentType());
}
view.setSyntaxHighlighting(prefs.syntaxHighlighting());
}
}
@UiHandler("mode")
void onMode(@SuppressWarnings("unused") ChangeEvent e) {
@@ -386,6 +445,7 @@ class PreferencesBox extends Composite {
@UiHandler("whitespaceErrors")
void onWhitespaceErrors(ValueChangeEvent<Boolean> e) {
prefs.showWhitespaceErrors(e.getValue());
if (view != null) {
view.operation(new Runnable() {
@Override
public void run() {
@@ -395,17 +455,21 @@ class PreferencesBox extends Composite {
}
});
}
}
@UiHandler("renderEntireFile")
void onRenderEntireFile(ValueChangeEvent<Boolean> e) {
prefs.renderEntireFile(e.getValue());
if (view != null) {
view.updateRenderEntireFile();
}
}
@UiHandler("theme")
void onTheme(@SuppressWarnings("unused") ChangeEvent e) {
final Theme newTheme = getSelectedTheme();
prefs.theme(newTheme);
if (view != null) {
ThemeLoader.loadTheme(newTheme, new GerritCallback<Void>() {
@Override
public void onSuccess(Void result) {
@@ -423,6 +487,7 @@ class PreferencesBox extends Composite {
}
});
}
}
private Theme getSelectedTheme() {
return Theme.valueOf(theme.getValue(theme.getSelectedIndex()));
@@ -446,8 +511,10 @@ class PreferencesBox extends Composite {
Gerrit.setAccountDiffPreference(p);
}
});
if (view != null) {
close();
}
}
@UiHandler("close")
void onClose(ClickEvent e) {

View File

@@ -155,6 +155,7 @@ limitations under the License.
</ui:style>
<g:HTMLPanel styleName='{style.box}'>
<div ui:field='header'>
<table style='width: 100%'>
<tr>
<td><ui:msg>Diff Preferences</ui:msg></td>
@@ -164,6 +165,7 @@ limitations under the License.
</tr>
</table>
<hr/>
</div>
<table class='{style.table}'>
<tr>
<th><ui:msg>Theme</ui:msg></th>
@@ -208,7 +210,7 @@ limitations under the License.
</g:ToggleButton></td>
</tr>
<tr>
<th><ui:msg>Language</ui:msg></th>
<th><div ui:field='modeLabel'><ui:msg>Language</ui:msg></div></th>
<td><g:ListBox ui:field='mode'/></td>
</tr>
<tr>
@@ -240,7 +242,7 @@ limitations under the License.
</g:ToggleButton></td>
</tr>
<tr>
<th><ui:msg>Left Side</ui:msg></th>
<th><div ui:field='leftSideLabel'><ui:msg>Left Side</ui:msg></div></th>
<td><g:ToggleButton ui:field='leftSide'>
<g:upFace><ui:msg>Hide</ui:msg></g:upFace>
<g:downFace><ui:msg>Show</ui:msg></g:downFace>