Add top level menus for a new PatchScreen header
Modify the PatchScreen so that the header contents is selectable using the top level menus. Allow the header to display either nothing, the commit message, the preferences, the Patch Sets, or the File List. Make the top level menus disappear when not on the PatchScreen. Change-Id: I4dd0014989f4e59643ff1d0c06637db08dc95505
This commit is contained in:
@@ -17,9 +17,11 @@ package com.google.gerrit.client;
|
||||
import com.google.gerrit.client.auth.openid.OpenIdSignInDialog;
|
||||
import com.google.gerrit.client.auth.userpass.UserPassSignInDialog;
|
||||
import com.google.gerrit.client.changes.ChangeListScreen;
|
||||
import com.google.gerrit.client.patches.PatchScreen;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.ui.LinkMenuBar;
|
||||
import com.google.gerrit.client.ui.LinkMenuItem;
|
||||
import com.google.gerrit.client.ui.MorphingTabPanel;
|
||||
import com.google.gerrit.client.ui.Screen;
|
||||
import com.google.gerrit.common.ClientVersion;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
@@ -34,6 +36,7 @@ import com.google.gerrit.reviewdb.AuthType;
|
||||
import com.google.gwt.core.client.EntryPoint;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.dom.client.AnchorElement;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
||||
import com.google.gwt.http.client.URL;
|
||||
@@ -50,7 +53,6 @@ import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.InlineLabel;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.RootPanel;
|
||||
import com.google.gwt.user.client.ui.TabPanel;
|
||||
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
|
||||
import com.google.gwtexpui.clippy.client.CopyableLabel;
|
||||
import com.google.gwtexpui.user.client.UserAgent;
|
||||
@@ -76,14 +78,15 @@ public class Gerrit implements EntryPoint {
|
||||
private static Account myAccount;
|
||||
private static AccountDiffPreference myAccountDiffPref;
|
||||
|
||||
private static TabPanel menuLeft;
|
||||
private static MorphingTabPanel menuLeft;
|
||||
private static LinkMenuBar menuRight;
|
||||
private static LinkMenuBar diffBar;
|
||||
private static RootPanel siteHeader;
|
||||
private static RootPanel siteFooter;
|
||||
private static SearchPanel searchPanel;
|
||||
private static final Dispatcher dispatcher = new Dispatcher();
|
||||
private static ViewSite<Screen> body;
|
||||
|
||||
private static PatchScreen patchScreen;
|
||||
private static String lastChangeListToken;
|
||||
|
||||
static {
|
||||
@@ -144,6 +147,25 @@ public class Gerrit implements EntryPoint {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update any top level menus which can vary based on the view which was
|
||||
* loaded.
|
||||
* @param view the loaded view.
|
||||
*/
|
||||
public static void updateMenus(Screen view) {
|
||||
if (view instanceof PatchScreen) {
|
||||
patchScreen = (PatchScreen) view;
|
||||
menuLeft.setVisible(diffBar, true);
|
||||
menuLeft.selectTab(menuLeft.getWidgetIndex(diffBar));
|
||||
} else {
|
||||
if (patchScreen != null && menuLeft.getSelectedWidget() == diffBar) {
|
||||
menuLeft.selectTab(isSignedIn() ? 1 : 0);
|
||||
}
|
||||
patchScreen = null;
|
||||
menuLeft.setVisible(diffBar, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the current history token after a screen change.
|
||||
* <p>
|
||||
@@ -356,7 +378,7 @@ public class Gerrit implements EntryPoint {
|
||||
gBody.setStyleName(RESOURCES.css().gerritBody());
|
||||
|
||||
final Grid menuLine = new Grid(1, 3);
|
||||
menuLeft = new TabPanel();
|
||||
menuLeft = new MorphingTabPanel();
|
||||
menuRight = new LinkMenuBar();
|
||||
searchPanel = new SearchPanel();
|
||||
menuLeft.setStyleName(RESOURCES.css().topmenuMenuLeft());
|
||||
@@ -466,6 +488,15 @@ public class Gerrit implements EntryPoint {
|
||||
menuLeft.selectTab(0);
|
||||
}
|
||||
|
||||
patchScreen = null;
|
||||
diffBar = new LinkMenuBar();
|
||||
menuLeft.addInvisible(diffBar, C.menuDiff());
|
||||
addDiffLink(diffBar, C.menuDiffMain(), PatchScreen.TopView.MAIN);
|
||||
addDiffLink(diffBar, C.menuDiffCommit(), PatchScreen.TopView.COMMIT);
|
||||
addDiffLink(diffBar, C.menuDiffPreferences(), PatchScreen.TopView.PREFERENCES);
|
||||
addDiffLink(diffBar, C.menuDiffPatchSets(), PatchScreen.TopView.PATCH_SETS);
|
||||
addDiffLink(diffBar, C.menuDiffFiles(), PatchScreen.TopView.FILES);
|
||||
|
||||
if (signedIn) {
|
||||
m = new LinkMenuBar();
|
||||
addLink(m, C.menuGroups(), PageLinks.ADMIN_GROUPS);
|
||||
@@ -561,6 +592,19 @@ public class Gerrit implements EntryPoint {
|
||||
m.addItem(new LinkMenuItem(text, historyToken));
|
||||
}
|
||||
|
||||
private static void addDiffLink(final LinkMenuBar m, final String text,
|
||||
final PatchScreen.TopView tv) {
|
||||
m.addItem(new LinkMenuItem(text, "") {
|
||||
@Override
|
||||
public void go() {
|
||||
if (patchScreen != null) {
|
||||
patchScreen.setTopView(tv);
|
||||
}
|
||||
AnchorElement.as(getElement()).blur();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void addDocLink(final LinkMenuBar m, final String text,
|
||||
final String href) {
|
||||
final Anchor atag = anchor(text, "Documentation/" + href);
|
||||
|
||||
@@ -61,6 +61,13 @@ public interface GerritConstants extends Constants {
|
||||
String menuMyWatchedChanges();
|
||||
String menuMyStarredChanges();
|
||||
|
||||
String menuDiff();
|
||||
String menuDiffMain();
|
||||
String menuDiffCommit();
|
||||
String menuDiffPreferences();
|
||||
String menuDiffPatchSets();
|
||||
String menuDiffFiles();
|
||||
|
||||
String menuAdmin();
|
||||
String menuPeople();
|
||||
String menuGroups();
|
||||
|
||||
@@ -44,6 +44,13 @@ menuMyDrafts = Drafts
|
||||
menuMyStarredChanges = Starred Changes
|
||||
menuMyWatchedChanges = Watched Changes
|
||||
|
||||
menuDiff = Differences
|
||||
menuDiffMain = Diff Only
|
||||
menuDiffCommit = Commit Message
|
||||
menuDiffPreferences = Preferences
|
||||
menuDiffPatchSets = Patch Sets
|
||||
menuDiffFiles = Files
|
||||
|
||||
menuAdmin = Admin
|
||||
menuPeople = People
|
||||
menuGroups = Groups
|
||||
|
||||
@@ -112,6 +112,13 @@ public abstract class PatchScreen extends Screen implements
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* What should be displayed in the top of the screen
|
||||
*/
|
||||
public static enum TopView {
|
||||
MAIN, COMMIT, PREFERENCES, PATCH_SETS, FILES
|
||||
}
|
||||
|
||||
protected final Patch.Key patchKey;
|
||||
protected PatchSetDetail patchSetDetail;
|
||||
protected PatchTable fileList;
|
||||
@@ -119,8 +126,8 @@ public abstract class PatchScreen extends Screen implements
|
||||
protected PatchSet.Id idSideB;
|
||||
protected PatchScriptSettingsPanel settingsPanel;
|
||||
|
||||
private DisclosurePanel historyPanel;
|
||||
private HistoryTable historyTable;
|
||||
private FlowPanel topPanel;
|
||||
private FlowPanel contentPanel;
|
||||
private Label noDifference;
|
||||
private AbstractPatchContentTable contentTable;
|
||||
@@ -251,26 +258,11 @@ public abstract class PatchScreen extends Screen implements
|
||||
keysNavigation.add(new FileListCmd(0, 'f', PatchUtil.C.fileList()));
|
||||
|
||||
historyTable = new HistoryTable(this);
|
||||
historyPanel = new DisclosurePanel(PatchUtil.C.patchHistoryTitle());
|
||||
historyPanel.setContent(historyTable);
|
||||
historyPanel.setVisible(false);
|
||||
// If the user selected a different patch set than the default for either
|
||||
// side, expand the history panel
|
||||
historyPanel.setOpen(diffSideA != null || diffSideB != null
|
||||
|| (historyOpen != null && historyOpen));
|
||||
historyPanel.addOpenHandler(cacheOpenState);
|
||||
historyPanel.addCloseHandler(cacheCloseState);
|
||||
|
||||
|
||||
VerticalPanel vp = new VerticalPanel();
|
||||
vp.add(historyPanel);
|
||||
vp.add(settingsPanel);
|
||||
commitMessageBlock = new CommitMessageBlock("6em");
|
||||
HorizontalPanel hp = new HorizontalPanel();
|
||||
hp.setWidth("100%");
|
||||
hp.add(vp);
|
||||
hp.add(commitMessageBlock);
|
||||
add(hp);
|
||||
|
||||
topPanel = new FlowPanel();
|
||||
add(topPanel);
|
||||
|
||||
noDifference = new Label(PatchUtil.C.noDifference());
|
||||
noDifference.setStyleName(Gerrit.RESOURCES.css().patchNoDifference());
|
||||
@@ -414,7 +406,6 @@ public abstract class PatchScreen extends Screen implements
|
||||
}
|
||||
|
||||
historyTable.display(script.getHistory());
|
||||
historyPanel.setVisible(true);
|
||||
|
||||
// True if there are differences between the two patch sets
|
||||
boolean hasEdits = !script.getEdits().isEmpty();
|
||||
@@ -489,6 +480,20 @@ public abstract class PatchScreen extends Screen implements
|
||||
diffSideB = patchSetId;
|
||||
}
|
||||
|
||||
public void setTopView(TopView tv) {
|
||||
topPanel.clear();
|
||||
switch(tv) {
|
||||
case COMMIT: topPanel.add(commitMessageBlock);
|
||||
break;
|
||||
case PREFERENCES: topPanel.add(settingsPanel);
|
||||
break;
|
||||
case PATCH_SETS: topPanel.add(historyTable);
|
||||
break;
|
||||
case FILES: topPanel.add(fileList);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public class FileListCmd extends KeyCommand {
|
||||
public FileListCmd(int mask, int key, String help) {
|
||||
super(mask, key, help);
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
// Copyright (C) 2011 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.ui;
|
||||
|
||||
import com.google.gwt.event.logical.shared.SelectionEvent;
|
||||
import com.google.gwt.event.logical.shared.SelectionHandler;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
import com.google.gwt.user.client.ui.TabBar;
|
||||
import com.google.gwt.user.client.ui.TabPanel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** A TabPanel which allows entries to be hidden. This class is not yet
|
||||
* designed to handle removes or any other add methods than the one
|
||||
* overridden here. It is also not designed to handle anything other
|
||||
* than text for the tab.
|
||||
*/
|
||||
public class MorphingTabPanel extends TabPanel {
|
||||
// Keep track of the order the widgets/texts should be in when not hidden.
|
||||
private List<Widget> widgets = new ArrayList<Widget>();
|
||||
private List<String> texts = new ArrayList<String>();
|
||||
|
||||
// currently visible widgets
|
||||
private List<Widget> visibles = new ArrayList<Widget>();
|
||||
|
||||
private int selection;
|
||||
|
||||
public MorphingTabPanel() {
|
||||
addSelectionHandler(new SelectionHandler<Integer>() {
|
||||
@Override
|
||||
public void onSelection(SelectionEvent<Integer> ev) {
|
||||
selection = ev.getSelectedItem();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int getSelectedIndex() {
|
||||
return selection;
|
||||
}
|
||||
|
||||
public Widget getSelectedWidget() {
|
||||
return getWidget(getSelectedIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
widgets.clear();
|
||||
texts.clear();
|
||||
visibles.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Widget w, String tabText) {
|
||||
addInvisible(w, tabText);
|
||||
visibles.add(w);
|
||||
super.add(w, tabText);
|
||||
}
|
||||
|
||||
public void addInvisible(Widget w, String tabText) {
|
||||
widgets.add(w);
|
||||
texts.add(tabText);
|
||||
}
|
||||
|
||||
public void setVisible(Widget w, boolean visible) {
|
||||
if (visible) {
|
||||
if (visibles.indexOf(w) == -1) {
|
||||
int origPos = widgets.indexOf(w);
|
||||
|
||||
/* Re-insert the widget right after the first visible widget found
|
||||
when scanning backwards from the current widget */
|
||||
for (int pos = origPos -1; pos >=0 ; pos--) {
|
||||
int visiblePos = visibles.indexOf(widgets.get(pos));
|
||||
if (visiblePos != -1) {
|
||||
visibles.add(visiblePos + 1, w);
|
||||
insert(w, texts.get(origPos), visiblePos + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int i = visibles.indexOf(w);
|
||||
if (i != -1) {
|
||||
visibles.remove(i);
|
||||
remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,6 +127,7 @@ public abstract class Screen extends View {
|
||||
if (windowTitle != null) {
|
||||
Gerrit.setWindowTitle(this, windowTitle);
|
||||
}
|
||||
Gerrit.updateMenus(this);
|
||||
registerKeys();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user