Cache the PublishCommentScreen so the cover message isn't lost

If the user jumps to a patch screen, then tries to come back to
the publish comment screen we should save their current message
and the approval options selected, so they don't need to reenter
this information again.

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-01-16 09:45:20 -08:00
parent d99757d5d6
commit 0b2852ee0b
2 changed files with 52 additions and 15 deletions

View File

@@ -118,6 +118,10 @@ public class Gerrit implements EntryPoint {
body.add(currentScreen);
}
public static void uncache(final Screen view) {
priorScreens.remove(view.getScreenCacheToken());
}
/** @return the currently signed in user's account data; null if no account */
public static Account getUserAccount() {
return myAccount;

View File

@@ -52,7 +52,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
public class PublishCommentScreen extends AccountScreen {
public class PublishCommentScreen extends AccountScreen implements
ClickListener {
private final PatchSet.Id patchSetId;
private Collection<RadioButton> approvalButtons;
private ChangeDescriptionBlock descBlock;
@@ -60,6 +61,8 @@ public class PublishCommentScreen extends AccountScreen {
private TextArea message;
private Panel draftsPanel;
private Button send;
private Button cancel;
private boolean displayedOnce;
public PublishCommentScreen(final PatchSet.Id psi) {
super(Util.M.publishComments(psi.getParentKey().get(), psi.get()));
@@ -67,6 +70,11 @@ public class PublishCommentScreen extends AccountScreen {
patchSetId = psi;
}
@Override
public Object getScreenCacheToken() {
return new ScreenCacheToken(patchSetId);
}
@Override
public void onLoad() {
if (message == null) {
@@ -91,19 +99,11 @@ public class PublishCommentScreen extends AccountScreen {
body.add(buttonRow);
send = new Button(Util.C.buttonPublishCommentsSend());
send.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
onSend();
}
});
send.addClickListener(this);
buttonRow.add(send);
final Button cancel = new Button(Util.C.buttonPublishCommentsCancel());
cancel.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
goChange();
}
});
cancel.addClickListener(this);
buttonRow.add(cancel);
}
@@ -120,6 +120,15 @@ public class PublishCommentScreen extends AccountScreen {
});
}
public void onClick(final Widget sender) {
if (send == sender) {
onSend();
} else if (cancel == sender) {
Gerrit.uncache(this);
goChange();
}
}
private void initMessage(final Panel body) {
body.add(new SmallHeading(Util.C.headingCoverMessage()));
@@ -183,10 +192,10 @@ public class PublishCommentScreen extends AccountScreen {
private void display(final PatchSetPublishDetail r) {
descBlock.display(r.getChange(), r.getPatchSetInfo(), r.getAccounts());
approvalPanel.clear();
approvalButtons.clear();
if (r.getChange().getStatus().isOpen()) {
initApprovals(r, approvalPanel);
if (!displayedOnce) {
if (r.getChange().getStatus().isOpen()) {
initApprovals(r, approvalPanel);
}
}
draftsPanel.clear();
@@ -217,6 +226,8 @@ public class PublishCommentScreen extends AccountScreen {
panel.add(m);
}
}
displayedOnce = true;
}
private void onSend() {
@@ -250,4 +261,26 @@ public class PublishCommentScreen extends AccountScreen {
private static native ApprovalCategoryValue getValue(Element rbutton)
/*-{ return rbutton["__gerritValue"]; }-*/;
private static final class ScreenCacheToken {
private final PatchSet.Id patchSetId;
ScreenCacheToken(final PatchSet.Id psi) {
patchSetId = psi;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof ScreenCacheToken) {
final ScreenCacheToken c = (ScreenCacheToken) obj;
return patchSetId.equals(c.patchSetId);
}
return false;
}
@Override
public int hashCode() {
return patchSetId.hashCode();
}
}
}