SideBySide2: Add Shift-a keybinding to show/hide left side

When a new file is added there is nothing to display on the left side.
Some reviewers may prefer to fill the screen with the right side while
reading the new code.  Add a setting to toggle the visibility of the
left side, and a keyboard binding of "Shift-a" to trigger this.

The preference is not currently saved to prevent reviewers from
missing deletions in modified files.

Change-Id: Ic6659de6bdfb8b564a2cbcb2cc8ccab871af9e6a
This commit is contained in:
Shawn Pearce
2014-04-27 11:42:49 -07:00
parent 90e6d70c58
commit ac683b2ec0
7 changed files with 55 additions and 1 deletions

View File

@@ -47,6 +47,7 @@ class DiffTable extends Composite {
String rangeHighlight();
String showTabs();
String showLineNumbers();
String hideA();
String columnMargin();
String padding();
}
@@ -68,6 +69,7 @@ class DiffTable extends Composite {
private SideBySide2 parent;
private boolean headerVisible;
private boolean visibleA;
DiffTable(SideBySide2 parent, PatchSet.Id base, PatchSet.Id revision,
String path) {
@@ -80,6 +82,29 @@ class DiffTable extends Composite {
initWidget(uiBinder.createAndBindUi(this));
this.parent = parent;
this.headerVisible = true;
this.visibleA = true;
}
boolean isVisibleA() {
return visibleA;
}
void setVisibleA(boolean show) {
visibleA = show;
if (show) {
removeStyleName(style.hideA());
} else {
addStyleName(style.hideA());
}
}
Runnable toggleA() {
return new Runnable() {
@Override
public void run() {
setVisibleA(!isVisibleA());
}
};
}
boolean isHeaderVisible() {

View File

@@ -52,6 +52,11 @@ limitations under the License.
padding-bottom: 1px;
}
.hideA .psNavA,
.hideA .a {
display: none;
}
.table {
width: 100%;
table-layout: fixed;
@@ -156,7 +161,7 @@ limitations under the License.
<g:HTMLPanel styleName='{style.difftable}'>
<table class='{style.table}'>
<tr ui:field='patchSetNavRow' class='{style.patchSetNav}'>
<td ui:field='patchSetNavCellA'>
<td ui:field='patchSetNavCellA' class='{style.psNavA}'>
<d:PatchSetSelectBox2 ui:field='patchSetSelectBoxA' />
</td>
<td ui:field='patchSetNavCellB'>

View File

@@ -86,6 +86,7 @@ class PreferencesBox extends Composite {
@UiField ToggleButton whitespaceErrors;
@UiField ToggleButton showTabs;
@UiField ToggleButton lineNumbers;
@UiField ToggleButton leftSide;
@UiField ToggleButton topMenu;
@UiField ToggleButton manualReview;
@UiField ToggleButton expandAllComments;
@@ -149,6 +150,7 @@ class PreferencesBox extends Composite {
whitespaceErrors.setValue(prefs.showWhitespaceErrors());
showTabs.setValue(prefs.showTabs());
lineNumbers.setValue(prefs.showLineNumbers());
leftSide.setValue(view.diffTable.isVisibleA());
topMenu.setValue(!prefs.hideTopMenu());
manualReview.setValue(prefs.manualReview());
expandAllComments.setValue(prefs.expandAllComments());
@@ -288,6 +290,11 @@ class PreferencesBox extends Composite {
view.setShowLineNumbers(prefs.showLineNumbers());
}
@UiHandler("leftSide")
void onLeftSide(ValueChangeEvent<Boolean> e) {
view.diffTable.setVisibleA(e.getValue());
}
@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>Left Side</ui:msg></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>
</g:ToggleButton></td>
</tr>
<tr>
<th><ui:msg>Top Menu</ui:msg></th>
<td><g:ToggleButton ui:field='topMenu'>

View File

@@ -324,6 +324,7 @@ public class SideBySide2 extends Screen {
.on("C", commentManager.insertNewDraft(cm))
.on("N", maybeNextVimSearch(cm))
.on("P", chunkManager.diffChunkNav(cm, Direction.PREV))
.on("Shift-A", diffTable.toggleA())
.on("Shift-M", header.reviewedAndNext())
.on("Shift-N", maybePrevVimSearch(cm))
.on("Shift-P", commentManager.commentNav(cm, Direction.PREV))
@@ -457,6 +458,13 @@ public class SideBySide2 extends Screen {
upToChange(true).run();
}
});
keysAction.add(new KeyCommand(
KeyCommand.M_SHIFT, 'a', PatchUtil.C.toggleSideA()) {
@Override
public void onKeyPress(KeyPressEvent event) {
diffTable.toggleA().run();
}
});
keysAction.add(new KeyCommand(0, ',', PatchUtil.C.showPreferences()) {
@Override
public void onKeyPress(KeyPressEvent event) {

View File

@@ -54,6 +54,7 @@ public interface PatchConstants extends Constants {
String fileList();
String expandComment();
String expandAllCommentsOnCurrentLine();
String toggleSideA();
String toggleIntraline();
String showPreferences();

View File

@@ -36,6 +36,7 @@ focusSideB = Focus right side
fileList = Browse files in patch set
expandComment = Expand or collapse comment
expandAllCommentsOnCurrentLine = Expand or collapse all comments on current line
toggleSideA = Toggle left side
toggleIntraline = Toggle intraline difference
showPreferences = Show diff preferences