Make 'u' go up to the last change listing

Rather than hard code 'u' from a change page to your dashboard, make
it return to the last major listing of changes you were viewing.
This makes it a whole lot easier to navigate through all changes
that you have starred, or have drafts on, or that are in a particular
query result.

Change-Id: I04c5569125633b4e68eb2a93d2bd313a1b632209
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java
index ec6b9ed..7bee0af 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java
@@ -16,6 +16,7 @@
 
 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.rpc.GerritCallback;
 import com.google.gerrit.client.ui.LinkMenuBar;
 import com.google.gerrit.client.ui.LinkMenuItem;
@@ -81,6 +82,8 @@
   private static final Dispatcher dispatcher = new Dispatcher();
   private static ViewSite<Screen> body;
 
+  private static String lastChangeListToken;
+
   static {
     SYSTEM_SVC = GWT.create(SystemInfoService.class);
     JsonUtil.bind(SYSTEM_SVC, "rpc/SystemInfoService");
@@ -91,6 +94,16 @@
     Window.Location.reload();
   }
 
+  public static void displayLastChangeList() {
+    if (lastChangeListToken != null) {
+      display(lastChangeListToken);
+    } else if (isSignedIn()) {
+      display(PageLinks.MINE);
+    } else {
+      display(PageLinks.toChangeQuery("status:open"));
+    }
+  }
+
   /**
    * Load the screen at the given location, displaying when ready.
    * <p>
@@ -365,6 +378,11 @@
             dispatchHistoryHooks(token);
           }
         }
+
+        if (view instanceof ChangeListScreen) {
+          lastChangeListToken = token;
+        }
+
         super.onShowView(view);
         view.onShowView();
       }
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/AccountDashboardScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/AccountDashboardScreen.java
index e122ce4..f5f3245 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/AccountDashboardScreen.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/AccountDashboardScreen.java
@@ -25,7 +25,7 @@
 import com.google.gerrit.reviewdb.Account;
 
 
-public class AccountDashboardScreen extends Screen {
+public class AccountDashboardScreen extends Screen implements ChangeListScreen {
   private final Account.Id ownerId;
   private ChangeTable table;
   private ChangeTable.Section byOwner;
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeConstants.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeConstants.java
index 9a08932..42bb28b 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeConstants.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeConstants.java
@@ -46,7 +46,7 @@
   String changeTableStar();
   String changeTablePagePrev();
   String changeTablePageNext();
-  String upToDashboard();
+  String upToChangeList();
   String expandCollapseDependencies();
   String previousPatchSet();
   String nextPatchSet();
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeConstants.properties b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeConstants.properties
index 59d0bd5..996b462 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeConstants.properties
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeConstants.properties
@@ -26,7 +26,7 @@
 changeTableStar = Star (or unstar) change
 changeTablePagePrev = Previous page of changes
 changeTablePageNext = Next page of changes
-upToDashboard = Up to dashboard
+upToChangeList = Up to change list
 expandCollapseDependencies = Expands / Collapses dependencies section
 previousPatchSet = Previous patch set
 nextPatchSet = Next patch set
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeListScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeListScreen.java
new file mode 100644
index 0000000..8871ee0
--- /dev/null
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeListScreen.java
@@ -0,0 +1,18 @@
+// 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.changes;
+
+public interface ChangeListScreen {
+}
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeScreen.java
index 36d3681..83870c0 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeScreen.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeScreen.java
@@ -22,7 +22,6 @@
 import com.google.gerrit.client.ui.LinkMenuBar;
 import com.google.gerrit.client.ui.NeedsSignInKeyCommand;
 import com.google.gerrit.client.ui.Screen;
-import com.google.gerrit.common.PageLinks;
 import com.google.gerrit.common.data.AccountInfo;
 import com.google.gerrit.common.data.AccountInfoCache;
 import com.google.gerrit.common.data.ChangeDetail;
@@ -145,7 +144,7 @@
 
     keysNavigation = new KeyCommandSet(Gerrit.C.sectionNavigation());
     keysAction = new KeyCommandSet(Gerrit.C.sectionActions());
-    keysNavigation.add(new DashboardKeyCommand(0, 'u', Util.C.upToDashboard()));
+    keysNavigation.add(new UpToListKeyCommand(0, 'u', Util.C.upToChangeList()));
     keysNavigation.add(new ExpandCollapseDependencySectionKeyCommand(0, 'd', Util.C.expandCollapseDependencies()));
 
     if (Gerrit.isSignedIn()) {
@@ -346,18 +345,14 @@
     });
   }
 
-  public class DashboardKeyCommand extends KeyCommand {
-    public DashboardKeyCommand(int mask, char key, String help) {
+  public class UpToListKeyCommand extends KeyCommand {
+    public UpToListKeyCommand(int mask, char key, String help) {
       super(mask, key, help);
     }
 
     @Override
     public void onKeyPress(final KeyPressEvent event) {
-      if (Gerrit.isSignedIn()) {
-        Gerrit.display(PageLinks.MINE);
-      } else {
-        Gerrit.display(PageLinks.toChangeQuery("status:open"));
-      }
+      Gerrit.displayLastChangeList();
     }
   }
 
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/MineSingleListScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/MineSingleListScreen.java
deleted file mode 100644
index 9016b21..0000000
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/MineSingleListScreen.java
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (C) 2008 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.changes;
-
-import com.google.gerrit.client.rpc.ScreenLoadCallback;
-import com.google.gerrit.client.ui.AccountScreen;
-import com.google.gerrit.common.data.SingleListChangeInfo;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-
-
-public abstract class MineSingleListScreen extends AccountScreen {
-  private final String anchor;
-  private ChangeTable table;
-  private ChangeTable.Section drafts;
-
-  protected MineSingleListScreen(final String historyToken) {
-    anchor = historyToken;
-  }
-
-  @Override
-  protected void onInitUI() {
-    super.onInitUI();
-    table = new ChangeTable();
-    drafts = new ChangeTable.Section();
-
-    table.addSection(drafts);
-    table.setSavePointerId(anchor);
-
-    add(table);
-  }
-
-  @Override
-  public void registerKeys() {
-    super.registerKeys();
-    table.setRegisterKeys(true);
-  }
-
-  protected AsyncCallback<SingleListChangeInfo> loadCallback() {
-    return new ScreenLoadCallback<SingleListChangeInfo>(this) {
-      @Override
-      protected void preDisplay(final SingleListChangeInfo result) {
-        display(result);
-      }
-    };
-  }
-
-  private void display(final SingleListChangeInfo result) {
-    table.setAccountInfoCache(result.getAccounts());
-    drafts.display(result.getChanges());
-    table.finishDisplay();
-  }
-}
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/QueryScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/QueryScreen.java
index bcd2ed2..1192dd0 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/QueryScreen.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/QueryScreen.java
@@ -24,7 +24,8 @@
 import com.google.gwtorm.client.KeyUtil;
 
 
-public class QueryScreen extends PagedSingleListScreen {
+public class QueryScreen extends PagedSingleListScreen implements
+    ChangeListScreen {
   public static QueryScreen forQuery(String query) {
     return forQuery(query, PageLinks.TOP);
   }