SideBySide2: Hide empty pane for added and deleted files

Add new user preference and increase schema version.

Change-Id: I156e9af944ff16d8f85946b40a7998e8c3861d5c
This commit is contained in:
David Ostrovsky 2014-05-01 21:55:00 +02:00 committed by Shawn Pearce
parent e35392e5f4
commit a64d689c6b
12 changed files with 119 additions and 4 deletions

View File

@ -1031,6 +1031,11 @@ Controls whether tabs are highlighted.
+
Controls whether line numbers are shown.
- `Empty Pane`:
+
Controls whether empty panes are shown or not. The Left pane is empty when a
file was added; the right pane is empty when a file was deleted.
- `Left Side`:
+
Controls whether the left side is shown. This preference is not

View File

@ -40,6 +40,7 @@ public class DiffPreferences extends JavaScriptObject {
p.manualReview(in.isManualReview());
p.renderEntireFile(in.isRenderEntireFile());
p.theme(in.getTheme());
p.hideEmptyPane(in.isHideEmptyPane());
return p;
}
@ -59,6 +60,7 @@ public class DiffPreferences extends JavaScriptObject {
p.setManualReview(manualReview());
p.setRenderEntireFile(renderEntireFile());
p.setTheme(theme());
p.setHideEmptyPane(hideEmptyPane());
}
public final void ignoreWhitespace(Whitespace i) {
@ -84,6 +86,7 @@ public class DiffPreferences extends JavaScriptObject {
public final native void expandAllComments(boolean e) /*-{ this.expand_all_comments = e }-*/;
public final native void manualReview(boolean r) /*-{ this.manual_review = r }-*/;
public final native void renderEntireFile(boolean r) /*-{ this.render_entire_file = r }-*/;
public final native void hideEmptyPane(boolean s) /*-{ this.hide_empty_pane = s }-*/;
public final void showLineNumbers(boolean s) { hideLineNumbers(!s); }
public final Whitespace ignoreWhitespace() {
@ -111,6 +114,7 @@ public class DiffPreferences extends JavaScriptObject {
public final native boolean expandAllComments() /*-{ return this.expand_all_comments || false }-*/;
public final native boolean manualReview() /*-{ return this.manual_review || false }-*/;
public final native boolean renderEntireFile() /*-{ return this.render_entire_file || false }-*/;
public final native boolean hideEmptyPane() /*-{ return this.hide_empty_pane || false }-*/;
public final boolean showLineNumbers() { return !hideLineNumbers(); }
public final boolean autoReview() { return !manualReview(); }

View File

@ -14,7 +14,9 @@
package com.google.gerrit.client.diff;
import com.google.gerrit.client.account.DiffPreferences;
import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
import com.google.gerrit.reviewdb.client.Patch.ChangeType;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JsArray;
@ -52,6 +54,7 @@ class DiffTable extends Composite {
String showTabs();
String showLineNumbers();
String hideA();
String hideB();
String columnMargin();
String padding();
}
@ -77,6 +80,7 @@ class DiffTable extends Composite {
private boolean header;
private boolean headerVisible;
private boolean visibleA;
private ChangeType changeType;
DiffTable(SideBySide2 parent, PatchSet.Id base, PatchSet.Id revision,
String path) {
@ -115,6 +119,15 @@ class DiffTable extends Composite {
};
}
void setVisibleB(boolean show) {
if (show) {
removeStyleName(style.hideB());
parent.syncScroll(DisplaySide.A); // match A's viewport
} else {
addStyleName(style.hideB());
}
}
boolean isHeaderVisible() {
return headerVisible;
}
@ -139,7 +152,12 @@ class DiffTable extends Composite {
return h;
}
void set(JsArray<RevisionInfo> list, DiffInfo info) {
ChangeType getChangeType() {
return changeType;
}
void set(DiffPreferences prefs, JsArray<RevisionInfo> list, DiffInfo info) {
this.changeType = info.change_type();
patchSetSelectBoxA.setUpPatchSetNav(list, info.meta_a());
patchSetSelectBoxB.setUpPatchSetNav(list, info.meta_b());
@ -165,6 +183,15 @@ class DiffTable extends Composite {
header = false;
UIObject.setVisible(diffHeaderRow, false);
}
setHideEmptyPane(prefs.hideEmptyPane());
}
void setHideEmptyPane(boolean hide) {
if (changeType == ChangeType.ADDED) {
setVisibleA(!hide);
} else if (changeType == ChangeType.DELETED) {
setVisibleB(!hide);
}
}
void refresh() {

View File

@ -57,6 +57,11 @@ limitations under the License.
display: none;
}
.hideB .psNavB,
.hideB .b {
display: none;
}
.table {
width: 100%;
table-layout: fixed;
@ -65,6 +70,7 @@ limitations under the License.
.table td { padding: 0 }
.a, .b { width: 50% }
.hideA .psNavB, .hideA .b { width: 100% }
.hideB .psNavA, .hideB .a { width: 100% }
.overview {
width: 10px;

View File

@ -31,6 +31,7 @@ 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.gerrit.reviewdb.client.Patch.ChangeType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.RepeatingCommand;
@ -87,6 +88,7 @@ class PreferencesBox extends Composite {
@UiField ToggleButton showTabs;
@UiField ToggleButton lineNumbers;
@UiField ToggleButton leftSide;
@UiField ToggleButton emptyPane;
@UiField ToggleButton topMenu;
@UiField ToggleButton manualReview;
@UiField ToggleButton expandAllComments;
@ -151,6 +153,9 @@ class PreferencesBox extends Composite {
showTabs.setValue(prefs.showTabs());
lineNumbers.setValue(prefs.showLineNumbers());
leftSide.setValue(view.diffTable.isVisibleA());
emptyPane.setValue(!prefs.hideEmptyPane());
leftSide.setEnabled(!(prefs.hideEmptyPane()
&& view.diffTable.getChangeType() == ChangeType.ADDED));
topMenu.setValue(!prefs.hideTopMenu());
manualReview.setValue(prefs.manualReview());
expandAllComments.setValue(prefs.expandAllComments());
@ -295,6 +300,21 @@ class PreferencesBox extends Composite {
view.diffTable.setVisibleA(e.getValue());
}
@UiHandler("emptyPane")
void onHideEmptyPane(ValueChangeEvent<Boolean> e) {
prefs.hideEmptyPane(!e.getValue());
view.diffTable.setHideEmptyPane(prefs.hideEmptyPane());
if (prefs.hideEmptyPane()) {
if (view.diffTable.getChangeType() == ChangeType.ADDED) {
leftSide.setValue(false);
leftSide.setEnabled(false);
}
} else {
leftSide.setValue(view.diffTable.isVisibleA());
leftSide.setEnabled(true);
}
}
@UiHandler("topMenu")
void onTopMenu(ValueChangeEvent<Boolean> e) {
prefs.hideTopMenu(!e.getValue());

View File

@ -228,6 +228,13 @@ limitations under the License.
<g:downFace><ui:msg>Show</ui:msg></g:downFace>
</g:ToggleButton></td>
</tr>
<tr>
<th><ui:msg>Empty Pane</ui:msg></th>
<td><g:ToggleButton ui:field='emptyPane'>
<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>Left Side</ui:msg></th>
<td><g:ToggleButton ui:field='leftSide'>

View File

@ -202,7 +202,7 @@ public class SideBySide2 extends Screen {
info.revisions().copyKeysIntoChildren("name");
JsArray<RevisionInfo> list = info.revisions().values();
RevisionInfo.sortRevisionInfoByNumber(list);
diffTable.set(list, diff);
diffTable.set(prefs, list, diff);
header.setChangeInfo(info);
}}));
@ -884,7 +884,9 @@ public class SideBySide2 extends Screen {
}
void syncScroll(DisplaySide masterSide) {
scrollSynchronizer.syncScroll(masterSide);
if (scrollSynchronizer != null) {
scrollSynchronizer.syncScroll(masterSide);
}
}
private String getContentType(DiffInfo.FileMeta meta) {

View File

@ -91,6 +91,7 @@ public class AccountDiffPreference {
p.setShowTabs(true);
p.setContext(DEFAULT_CONTEXT);
p.setManualReview(false);
p.setHideEmptyPane(false);
return p;
}
@ -152,6 +153,9 @@ public class AccountDiffPreference {
@Column(id = 19, length = 20, notNull = false)
protected String theme;
@Column(id = 20)
protected boolean hideEmptyPane;
protected AccountDiffPreference() {
}
@ -178,6 +182,7 @@ public class AccountDiffPreference {
this.hideTopMenu = p.hideTopMenu;
this.hideLineNumbers = p.hideLineNumbers;
this.renderEntireFile = p.renderEntireFile;
this.hideEmptyPane = p.hideEmptyPane;
}
public Account.Id getAccountId() {
@ -330,4 +335,12 @@ public class AccountDiffPreference {
public void setTheme(Theme theme) {
this.theme = theme != null ? theme.name() : null;
}
public boolean isHideEmptyPane() {
return hideEmptyPane;
}
public void setHideEmptyPane(boolean hideEmptyPane) {
this.hideEmptyPane = hideEmptyPane;
}
}

View File

@ -72,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.hideEmptyPane = p.isHideEmptyPane() ? true : null;
info.theme = p.getTheme();
return info;
}
@ -92,6 +93,7 @@ public class GetDiffPreferences implements RestReadView<AccountResource> {
public Boolean hideTopMenu;
public Boolean hideLineNumbers;
public Boolean renderEntireFile;
public Boolean hideEmptyPane;
public int tabSize;
public Theme theme;
}

View File

@ -50,6 +50,7 @@ public class SetDiffPreferences implements RestModifyView<AccountResource, Input
Boolean renderEntireFile;
Integer tabSize;
Theme theme;
Boolean hideEmptyPane;
}
private final Provider<CurrentUser> self;
@ -136,6 +137,9 @@ public class SetDiffPreferences implements RestModifyView<AccountResource, Input
if (input.theme != null) {
p.setTheme(input.theme);
}
if (input.hideEmptyPane != null) {
p.setHideEmptyPane(input.hideEmptyPane);
}
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_96> C = Schema_96.class;
public static final Class<Schema_97> C = Schema_97.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_97 extends SchemaVersion {
@Inject
Schema_97(Provider<Schema_96> prior) {
super(prior);
}
}