SideBySide2: Simplify logic for showing/hiding header

The file header and Gerrit menus should show/hide together.
Consolidate the logic for this into one place and simplify the
conditional value to be consistent between them:

  true means show headers,
  false means hide headers.

Change-Id: Iae59a40369ef698279eee2c1faa2b147fbb622c8
This commit is contained in:
Shawn Pearce
2013-11-21 01:33:15 -08:00
committed by Michael Zhou
parent a4f6c6d325
commit 78e400cde3
3 changed files with 12 additions and 15 deletions

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.client.diff;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwt.core.client.GWT;
@@ -100,14 +101,12 @@ class DiffTable extends Composite {
this.host = host;
}
void updateFileCommentVisibility(boolean forceHide) {
UIObject.setVisible(patchSetNavRow, !forceHide);
if (forceHide || (fileCommentPanelA.getBoxCount() == 0 &&
fileCommentPanelB.getBoxCount() == 0)) {
UIObject.setVisible(fileCommentRow, false);
} else {
UIObject.setVisible(fileCommentRow, true);
}
void setHeaderVisible(boolean show) {
Gerrit.setHeaderVisible(show);
UIObject.setVisible(patchSetNavRow, show);
UIObject.setVisible(fileCommentRow, show
&& (fileCommentPanelA.getBoxCount() > 0
|| fileCommentPanelB.getBoxCount() > 0));
host.resizeCodeMirror();
}
@@ -117,7 +116,7 @@ class DiffTable extends Composite {
void createOrEditFileComment(DisplaySide side) {
getPanelFromSide(side).createOrEditFileComment();
updateFileCommentVisibility(false);
setHeaderVisible(true);
}
void addFileCommentBox(CommentBox box) {

View File

@@ -74,11 +74,11 @@ class FileCommentPanel extends Composite {
void addFileComment(CommentBox box) {
boxes.add(box);
body.add(box);
table.updateFileCommentVisibility(false);
table.setHeaderVisible(true);
}
void onRemoveDraftBox(DraftBox box) {
boxes.remove(box);
table.updateFileCommentVisibility(false);
table.setHeaderVisible(true);
}
}

View File

@@ -39,12 +39,10 @@ class ScrollSynchronizer {
private void updateScreenHeader(ScrollInfo si) {
if (si.getTop() == 0 && !Gerrit.isHeaderVisible()) {
Gerrit.setHeaderVisible(true);
diffTable.updateFileCommentVisibility(false);
diffTable.setHeaderVisible(true);
} else if (si.getTop() > 0.5 * si.getClientHeight()
&& Gerrit.isHeaderVisible()) {
Gerrit.setHeaderVisible(false);
diffTable.updateFileCommentVisibility(true);
diffTable.setHeaderVisible(false);
}
}