Allow to submit topic edit with enter key on editor dialog

When editing the topic name, if the user wants to submit the edit
without entering a message, they have to either mouse click on the
submit button or press tab until the focus is on the submit button
and then press enter.

Add a key handler that allows the topic edit to be submitted by the
user pressing enter when focus is on topic name edit box.

Change-Id: Ia1daf18bf67be311a5e7a55de7467941adfb0498
This commit is contained in:
David Pursehouse
2013-01-21 14:50:24 +09:00
parent 6a80fb67ac
commit 92a2ece905

View File

@@ -31,6 +31,9 @@ import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Grid;
@@ -170,7 +173,8 @@ public class ChangeInfoBlock extends Composite {
return fp;
}
private class AlterTopicDialog extends CommentedActionDialog<ChangeDetail> {
private class AlterTopicDialog extends CommentedActionDialog<ChangeDetail>
implements KeyPressHandler {
TextBox newTopic;
Change change;
@@ -180,6 +184,7 @@ public class ChangeInfoBlock extends Composite {
change = chg;
newTopic = new TextBox();
newTopic.addKeyPressHandler(this);
setFocusOn(newTopic);
panel.insert(newTopic, 0);
panel.insert(new InlineLabel(Util.C.alterTopicLabel()), 0);
@@ -191,8 +196,7 @@ public class ChangeInfoBlock extends Composite {
newTopic.setText(change.getTopic());
}
@Override
public void onSend() {
private void doTopicEdit() {
String topic = newTopic.getText();
ChangeApi.topic(change.getId().get(), topic, getMessageText(),
new GerritCallback<String>() {
@@ -209,5 +213,18 @@ public class ChangeInfoBlock extends Composite {
super.onFailure(caught);
}});
}
@Override
public void onSend() {
doTopicEdit();
}
@Override
public void onKeyPress(KeyPressEvent event) {
if (event.getSource() == newTopic
&& event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
doTopicEdit();
}
}
}
}