Make ']' on last file to up to the change
This way when you are reviewing the last file, pressing ']' takes you up to the change rather than doing nothing at all. We also implement '[' to go up to the change when viewing the first file. Bug: issue 691 Change-Id: Ie93b39c5ebadea481a5f20b64109fff5b635626b Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -30,6 +30,7 @@ import com.google.gwtexpui.globalkey.client.KeyCommandSet;
|
||||
import com.google.gwtexpui.safehtml.client.SafeHtml;
|
||||
|
||||
class NavLinks extends Composite {
|
||||
private final Change.Id changeId;
|
||||
private final KeyCommandSet keys;
|
||||
private final Grid table;
|
||||
|
||||
@@ -40,6 +41,7 @@ class NavLinks extends Composite {
|
||||
private KeyCommand nextKey;
|
||||
|
||||
NavLinks(KeyCommandSet kcs, Change.Id forChange) {
|
||||
changeId = forChange;
|
||||
keys = kcs;
|
||||
table = new Grid(1, 3);
|
||||
initWidget(table);
|
||||
@@ -50,12 +52,22 @@ class NavLinks extends Composite {
|
||||
fmt.setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
|
||||
fmt.setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_RIGHT);
|
||||
|
||||
final ChangeLink up = new ChangeLink("", forChange);
|
||||
final ChangeLink up = new ChangeLink("", changeId);
|
||||
SafeHtml.set(up, SafeHtml.asis(Util.C.upToChangeIconLink()));
|
||||
table.setWidget(0, 1, up);
|
||||
}
|
||||
|
||||
void display(int patchIndex, PatchScreen.Type type, PatchTable fileList) {
|
||||
if (keys != null && prevKey != null) {
|
||||
keys.remove(prevKey);
|
||||
prevKey = null;
|
||||
}
|
||||
|
||||
if (keys != null && nextKey != null) {
|
||||
keys.remove(nextKey);
|
||||
nextKey = null;
|
||||
}
|
||||
|
||||
if (fileList != null) {
|
||||
prev = fileList.getPreviousPatchLink(patchIndex, type);
|
||||
next = fileList.getNextPatchLink(patchIndex, type);
|
||||
@@ -65,7 +77,7 @@ class NavLinks extends Composite {
|
||||
}
|
||||
|
||||
if (prev != null) {
|
||||
if (keys != null && prevKey == null) {
|
||||
if (keys != null) {
|
||||
prevKey = new KeyCommand(0, '[', PatchUtil.C.previousFileHelp()) {
|
||||
@Override
|
||||
public void onKeyPress(KeyPressEvent event) {
|
||||
@@ -76,15 +88,15 @@ class NavLinks extends Composite {
|
||||
}
|
||||
table.setWidget(0, 0, prev);
|
||||
} else {
|
||||
if (keys != null && prevKey != null) {
|
||||
keys.remove(prevKey);
|
||||
prevKey = null;
|
||||
if (keys != null) {
|
||||
prevKey = new UpToChangeCommand(changeId, 0, '[');
|
||||
keys.add(prevKey);
|
||||
}
|
||||
table.clearCell(0, 0);
|
||||
}
|
||||
|
||||
if (next != null) {
|
||||
if (keys != null && nextKey == null) {
|
||||
if (keys != null) {
|
||||
nextKey = new KeyCommand(0, ']', PatchUtil.C.nextFileHelp()) {
|
||||
@Override
|
||||
public void onKeyPress(KeyPressEvent event) {
|
||||
@@ -95,9 +107,9 @@ class NavLinks extends Composite {
|
||||
}
|
||||
table.setWidget(0, 2, next);
|
||||
} else {
|
||||
if (keys != null && nextKey != null) {
|
||||
keys.remove(nextKey);
|
||||
nextKey = null;
|
||||
if (keys != null) {
|
||||
nextKey = new UpToChangeCommand(changeId, 0, ']');
|
||||
keys.add(nextKey);
|
||||
}
|
||||
table.clearCell(0, 2);
|
||||
}
|
||||
|
||||
@@ -17,15 +17,12 @@ package com.google.gerrit.client.patches;
|
||||
import com.google.gerrit.client.Dispatcher;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.RpcStatus;
|
||||
import com.google.gerrit.client.changes.ChangeScreen;
|
||||
import com.google.gerrit.client.changes.CommitMessageBlock;
|
||||
import com.google.gerrit.client.changes.PatchTable;
|
||||
import com.google.gerrit.client.changes.Util;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
||||
import com.google.gerrit.client.ui.InlineHyperlink;
|
||||
import com.google.gerrit.client.ui.Screen;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.common.data.PatchScript;
|
||||
import com.google.gerrit.common.data.PatchSetDetail;
|
||||
import com.google.gerrit.prettify.client.ClientSideFormatter;
|
||||
@@ -246,8 +243,9 @@ public abstract class PatchScreen extends Screen implements
|
||||
protected void onInitUI() {
|
||||
super.onInitUI();
|
||||
|
||||
final Change.Id ck = patchKey.getParentKey().getParentKey();
|
||||
keysNavigation = new KeyCommandSet(Gerrit.C.sectionNavigation());
|
||||
keysNavigation.add(new UpToChangeCommand(0, 'u', PatchUtil.C.upToChange()));
|
||||
keysNavigation.add(new UpToChangeCommand(ck, 0, 'u'));
|
||||
keysNavigation.add(new FileListCmd(0, 'f', PatchUtil.C.fileList()));
|
||||
|
||||
historyTable = new HistoryTable(this);
|
||||
@@ -467,18 +465,6 @@ public abstract class PatchScreen extends Screen implements
|
||||
diffSideB = patchSetId;
|
||||
}
|
||||
|
||||
public class UpToChangeCommand extends KeyCommand {
|
||||
public UpToChangeCommand(int mask, int key, String help) {
|
||||
super(mask, key, help);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyPress(final KeyPressEvent event) {
|
||||
final Change.Id ck = patchKey.getParentKey().getParentKey();
|
||||
Gerrit.display(PageLinks.toChange(ck), new ChangeScreen(ck));
|
||||
}
|
||||
}
|
||||
|
||||
public class FileListCmd extends KeyCommand {
|
||||
public FileListCmd(int mask, int key, String help) {
|
||||
super(mask, key, help);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2010 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.patches;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.changes.ChangeScreen;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||
import com.google.gwtexpui.globalkey.client.KeyCommand;
|
||||
|
||||
class UpToChangeCommand extends KeyCommand {
|
||||
private final Change.Id changeId;
|
||||
|
||||
UpToChangeCommand(Change.Id changeId, int mask, int key) {
|
||||
super(mask, key, PatchUtil.C.upToChange());
|
||||
this.changeId = changeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyPress(final KeyPressEvent event) {
|
||||
Gerrit.display(PageLinks.toChange(changeId), new ChangeScreen(changeId));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user