SideBySide2: Add user preference to hide top menu

The top menu occupies a lot of space. I personally prefer the
version of SideBySide2 that hides the top menu when CM3 has scrolled
down some number of lines. Allow users to hide the top menu as a
preference, gaining back some screen space for code.

Change-Id: Ib30e8875fcc4b87662a5c12fa0bf3cc791d02c95
This commit is contained in:
Shawn Pearce
2013-12-04 14:29:30 -08:00
parent 57f8b1eba9
commit c344e89a2b
11 changed files with 82 additions and 5 deletions

View File

@@ -32,6 +32,7 @@ public class DiffPreferences extends JavaScriptObject {
p.showTabs(in.isShowTabs());
p.showWhitespaceErrors(in.isShowWhitespaceErrors());
p.syntaxHighlighting(in.isSyntaxHighlighting());
p.hideTopMenu(in.isHideTopMenu());
p.expandAllComments(in.isExpandAllComments());
return p;
}
@@ -45,6 +46,7 @@ public class DiffPreferences extends JavaScriptObject {
p.setShowTabs(showTabs());
p.setShowWhitespaceErrors(showWhitespaceErrors());
p.setSyntaxHighlighting(syntaxHighlighting());
p.setHideTopMenu(hideTopMenu());
p.setExpandAllComments(expandAllComments());
}
@@ -60,6 +62,7 @@ public class DiffPreferences extends JavaScriptObject {
public final native void showTabs(boolean s) /*-{ this.show_tabs = s }-*/;
public final native void showWhitespaceErrors(boolean s) /*-{ this.show_whitespace_errors = s }-*/;
public final native void syntaxHighlighting(boolean s) /*-{ this.syntax_highlighting = s }-*/;
public final native void hideTopMenu(boolean s) /*-{ this.hide_top_menu = s }-*/;
public final native void expandAllComments(boolean e) /*-{ this.expand_all_comments = e }-*/;
public final Whitespace ignoreWhitespace() {
@@ -75,6 +78,7 @@ public class DiffPreferences extends JavaScriptObject {
public final native boolean showTabs() /*-{ return this.show_tabs }-*/;
public final native boolean showWhitespaceErrors() /*-{ return this.show_whitespace_errors }-*/;
public final native boolean syntaxHighlighting() /*-{ return this.syntax_highlighting }-*/;
public final native boolean hideTopMenu() /*-{ return this.hide_top_menu }-*/;
public final native boolean expandAllComments() /*-{ return this.expand_all_comments }-*/;
protected DiffPreferences() {

View File

@@ -90,6 +90,7 @@ class DiffTable extends Composite {
static DiffTableStyle style;
private SideBySide2 host;
private boolean headerVisible;
DiffTable(SideBySide2 host, PatchSet.Id base, PatchSet.Id revision, String path) {
patchSetSelectBoxA = new PatchSetSelectBox2(
@@ -101,10 +102,16 @@ class DiffTable extends Composite {
fileCommentPanelB = new FileCommentPanel(host, this, path, DisplaySide.B);
initWidget(uiBinder.createAndBindUi(this));
this.host = host;
this.headerVisible = true;
}
boolean isHeaderVisible() {
return headerVisible;
}
void setHeaderVisible(boolean show) {
Gerrit.setHeaderVisible(show);
headerVisible = show;
Gerrit.setHeaderVisible(show && !host.getPrefs().hideTopMenu());
UIObject.setVisible(patchSetNavRow, show);
UIObject.setVisible(fileCommentRow, show
&& (fileCommentPanelA.getBoxCount() > 0

View File

@@ -72,6 +72,7 @@ class PreferencesBox extends Composite {
@UiField ToggleButton syntaxHighlighting;
@UiField ToggleButton whitespaceErrors;
@UiField ToggleButton showTabs;
@UiField ToggleButton topMenu;
@UiField ToggleButton expandAllComments;
@UiField Button apply;
@UiField Button save;
@@ -111,6 +112,7 @@ class PreferencesBox extends Composite {
syntaxHighlighting.setValue(prefs.syntaxHighlighting());
whitespaceErrors.setValue(prefs.showWhitespaceErrors());
showTabs.setValue(prefs.showTabs());
topMenu.setValue(!prefs.hideTopMenu());
expandAllComments.setValue(prefs.expandAllComments());
switch (view.getIntraLineStatus()) {
@@ -188,6 +190,14 @@ class PreferencesBox extends Composite {
view.setShowTabs(prefs.showTabs());
}
@UiHandler("topMenu")
void onTopMenu(ValueChangeEvent<Boolean> e) {
prefs.hideTopMenu(!e.getValue());
Gerrit.setHeaderVisible(view.diffTable.isHeaderVisible()
&& !prefs.hideTopMenu());
view.resizeCodeMirror();
}
@UiHandler("syntaxHighlighting")
void onSyntaxHighlighting(ValueChangeEvent<Boolean> e) {
prefs.syntaxHighlighting(e.getValue());

View File

@@ -193,6 +193,13 @@ limitations under the License.
<g:downFace><ui:msg>Show</ui:msg></g:downFace>
</g:ToggleButton></td>
</tr>
<tr>
<th><ui:msg>Top Menu</ui:msg></th>
<td><g:ToggleButton ui:field='topMenu'>
<g:upFace><ui:msg>Hide</ui:msg></g:upFace>
<g:downFace><ui:msg>Show</ui:msg></g:downFace>
</g:ToggleButton></td>
</tr>
<tr>
<th><ui:msg>Expand All Comments</ui:msg></th>
<td><g:ToggleButton ui:field='expandAllComments'>

View File

@@ -14,7 +14,6 @@
package com.google.gerrit.client.diff;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo;
import com.google.gwt.user.client.Timer;
@@ -38,10 +37,10 @@ class ScrollSynchronizer {
}
private void updateScreenHeader(ScrollInfo si) {
if (si.getTop() == 0 && !Gerrit.isHeaderVisible()) {
if (si.getTop() == 0 && !diffTable.isHeaderVisible()) {
diffTable.setHeaderVisible(true);
} else if (si.getTop() > 0.5 * si.getClientHeight()
&& Gerrit.isHeaderVisible()) {
&& diffTable.isHeaderVisible()) {
diffTable.setHeaderVisible(false);
}
}

View File

@@ -236,6 +236,9 @@ public class SideBySide2 extends Screen {
public void onShowView() {
super.onShowView();
Window.enableScrolling(false);
if (prefs.hideTopMenu()) {
Gerrit.setHeaderVisible(false);
}
final int height = getCodeMirrorHeight();
cmA.setHeight(height);
@@ -1519,6 +1522,10 @@ public class SideBySide2 extends Screen {
: null;
}
DiffPreferences getPrefs() {
return prefs;
}
CodeMirror getCmA() {
return cmA;
}

View File

@@ -116,6 +116,9 @@ public class AccountDiffPreference {
@Column(id = 15)
protected boolean showLineEndings;
@Column(id = 16)
protected boolean hideTopMenu;
protected AccountDiffPreference() {
}
@@ -139,6 +142,7 @@ public class AccountDiffPreference {
this.context = p.context;
this.retainHeader = p.retainHeader;
this.manualReview = p.manualReview;
this.hideTopMenu = p.hideTopMenu;
}
public Account.Id getAccountId() {
@@ -259,4 +263,12 @@ public class AccountDiffPreference {
public void setManualReview(boolean manual) {
manualReview = manual;
}
public void setHideTopMenu(boolean hide) {
hideTopMenu = hide;
}
public boolean isHideTopMenu() {
return hideTopMenu;
}
}

View File

@@ -66,6 +66,7 @@ public class GetDiffPreferences implements RestReadView<AccountResource> {
info.showWhitespaceErrors = p.isShowWhitespaceErrors() ? true : null;
info.skipDeleted = p.isSkipDeleted() ? true : null;
info.skipUncommented = p.isSkipUncommented() ? true : null;
info.hideTopMenu = p.isHideTopMenu() ? true : null;
info.syntaxHighlighting = p.isSyntaxHighlighting() ? true : null;
info.tabSize = p.getTabSize();
return info;
@@ -84,6 +85,7 @@ public class GetDiffPreferences implements RestReadView<AccountResource> {
Boolean skipDeleted;
Boolean skipUncommented;
Boolean syntaxHighlighting;
Boolean hideTopMenu;
int tabSize;
}
}

View File

@@ -44,6 +44,7 @@ public class SetDiffPreferences implements RestModifyView<AccountResource, Input
Boolean skipDeleted;
Boolean skipUncommented;
Boolean syntaxHighlighting;
Boolean hideTopMenu;
Integer tabSize;
}
@@ -116,6 +117,9 @@ public class SetDiffPreferences implements RestModifyView<AccountResource, Input
if (input.syntaxHighlighting != null) {
p.setSyntaxHighlighting(input.syntaxHighlighting);
}
if (input.hideTopMenu != null) {
p.setHideTopMenu(input.hideTopMenu);
}
if (input.tabSize != null) {
p.setTabSize(input.tabSize);
}

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_87> C = Schema_87.class;
public static final Class<Schema_88> C = Schema_88.class;
public static class Module extends AbstractModule {
@Override

View File

@@ -0,0 +1,25 @@
// Copyright (C) 2013 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_88 extends SchemaVersion {
@Inject
Schema_88(Provider<Schema_87> prior) {
super(prior);
}
}