ChangeScreen2: Auto-focus to submit button

After scoring a change with a maximum value in a radio group focus to
the submit button if it is enabled.  This allows committers to submit
a change with just Return/Enter/Space after posting Code-Review+2.

Change-Id: Ide28d62c24cfe7fd7e044d8b3b74ac5d246b8739
This commit is contained in:
Shawn Pearce
2013-12-07 10:43:00 -08:00
parent d7f80ca621
commit ba41a83819
6 changed files with 34 additions and 8 deletions

View File

@@ -491,7 +491,7 @@ public class Dispatcher {
if (rest.isEmpty()) {
Gerrit.display(token, panel== null
? (isChangeScreen2()
? new ChangeScreen2(id, null, null, false)
? new ChangeScreen2(id, null, null, false, false)
: new ChangeScreen(id))
: new NotFoundScreen());
return;
@@ -528,7 +528,7 @@ public class Dispatcher {
base != null
? String.valueOf(base.get())
: null,
String.valueOf(ps.get()), false)
String.valueOf(ps.get()), false, false)
: new ChangeScreen(id));
} else if ("publish".equals(panel)) {
publish(ps);

View File

@@ -129,6 +129,7 @@ public class ChangeScreen2 extends Screen {
private Timestamp lastDisplayedUpdate;
private UpdateAvailableBar updateAvailable;
private boolean openReplyBox;
private boolean focusSubmit;
private boolean loaded;
@UiField HTMLPanel headerLine;
@@ -175,11 +176,14 @@ public class ChangeScreen2 extends Screen {
private PatchSetsAction patchSetsAction;
private DownloadAction downloadAction;
public ChangeScreen2(Change.Id changeId, String base, String revision, boolean openReplyBox) {
public ChangeScreen2(Change.Id changeId,
String base, String revision,
boolean openReplyBox, boolean focusSubmit) {
this.changeId = changeId;
this.base = normalize(base);
this.revision = normalize(revision);
this.openReplyBox = openReplyBox;
this.focusSubmit = focusSubmit;
add(uiBinder.createAndBindUi(this));
}
@@ -418,6 +422,8 @@ public class ChangeScreen2 extends Screen {
if (openReplyBox) {
onReply();
} else if (focusSubmit && actions.isSubmitEnabled()) {
actions.submit.setFocus(true);
} else {
String prior = Gerrit.getPriorView();
if (prior != null && prior.startsWith("/c/")) {

View File

@@ -112,7 +112,9 @@ class QuickApprove extends Button implements ClickHandler {
.post(input, new GerritCallback<ReviewInput>() {
@Override
public void onSuccess(ReviewInput result) {
Gerrit.display(PageLinks.toChange(changeId));
Gerrit.display(
PageLinks.toChange(changeId),
new ChangeScreen2(changeId, null, null, false, true));
}
});
}

View File

@@ -31,6 +31,7 @@ import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.client.ui.CommentLinkProcessor;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.data.LabelValue;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwt.core.client.GWT;
@@ -84,6 +85,7 @@ class ReplyBox extends Composite {
private final CommentLinkProcessor clp;
private final PatchSet.Id psId;
private final String revision;
private final NativeMap<LabelInfo> labels;
private ReviewInput in = ReviewInput.create();
private Runnable lgtm;
@@ -106,6 +108,7 @@ class ReplyBox extends Composite {
this.clp = clp;
this.psId = psId;
this.revision = revision;
this.labels = all;
initWidget(uiBinder.createAndBindUi(this));
List<String> names = new ArrayList<String>(permitted.keySet());
@@ -193,14 +196,28 @@ class ReplyBox extends Composite {
void onPost(ClickEvent e) {
in.message(message.getText().trim());
in.prePost();
boolean s = false;
for (String name : labels.keySet()) {
if (in.label(name) != 0) {
if (in.label(name) == labels.get(name).value_set().last()) {
s = true;
break;
}
}
}
final boolean submit = s;
ChangeApi.revision(psId.getParentKey().get(), revision)
.view("review")
.post(in, new GerritCallback<ReviewInput>() {
@Override
public void onSuccess(ReviewInput result) {
Gerrit.display(PageLinks.toChange(
psId.getParentKey(),
String.valueOf(psId.get())));
Change.Id changeId = psId.getParentKey();
String rev = String.valueOf(psId.get());
Gerrit.display(
PageLinks.toChange(changeId, rev),
new ChangeScreen2(changeId, null, rev, false, submit));
}
});
hide();

View File

@@ -36,6 +36,7 @@ public class ReviewInput extends JavaScriptObject {
public final native void message(String m) /*-{ if(m)this.message=m; }-*/;
public final native void label(String n, short v) /*-{ this.labels[n]=v; }-*/;
public final native short label(String n) /*-{ return this.labels[n]||0 }-*/;
public final native void comments(NativeMap<JsArray<CommentInfo>> m)
/*-{ this.comments=m }-*/;

View File

@@ -1291,7 +1291,7 @@ public class SideBySide2 extends Screen {
String rev = String.valueOf(revision.get());
Gerrit.display(
PageLinks.toChange(changeId, rev),
new ChangeScreen2(changeId, b, rev, openReplyBox));
new ChangeScreen2(changeId, b, rev, openReplyBox, false));
}
private Runnable openClosePublished(final CodeMirror cm) {