Merge "Add button for inline comments that allows quoting them"

This commit is contained in:
Edwin Kempin 2015-12-09 08:10:44 +00:00 committed by Gerrit Code Review
commit e49eba66bd
4 changed files with 39 additions and 14 deletions

View File

@ -76,7 +76,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
class ReplyBox extends Composite { public class ReplyBox extends Composite {
interface Binder extends UiBinder<HTMLPanel, ReplyBox> {} interface Binder extends UiBinder<HTMLPanel, ReplyBox> {}
private static final Binder uiBinder = GWT.create(Binder.class); private static final Binder uiBinder = GWT.create(Binder.class);
@ -228,7 +228,7 @@ class ReplyBox extends Composite {
void replyTo(MessageInfo msg) { void replyTo(MessageInfo msg) {
if (msg.message() != null) { if (msg.message() != null) {
String t = message.getText(); String t = message.getText();
String m = quote(msg); String m = quote(removePatchSetHeaderLine(msg.message()));
if (t == null || t.isEmpty()) { if (t == null || t.isEmpty()) {
t = m; t = m;
} else if (t.endsWith("\n\n")) { } else if (t.endsWith("\n\n")) {
@ -238,20 +238,25 @@ class ReplyBox extends Composite {
} else { } else {
t += "\n\n" + m; t += "\n\n" + m;
} }
message.setText(t + "\n\n"); message.setText(t);
} }
} }
private static String quote(MessageInfo msg) { private static String removePatchSetHeaderLine(String msg) {
String m = msg.message().trim(); msg = msg.trim();
if (m.startsWith("Patch Set ")) { if (msg.startsWith("Patch Set ")) {
int i = m.indexOf('\n'); int i = msg.indexOf('\n');
if (i > 0) { if (i > 0) {
m = m.substring(i + 1).trim(); msg = msg.substring(i + 1).trim();
} }
} }
return msg;
}
public static String quote(String msg) {
msg = msg.trim();
StringBuilder quotedMsg = new StringBuilder(); StringBuilder quotedMsg = new StringBuilder();
for (String line : m.split("\\n")) { for (String line : msg.split("\\n")) {
line = line.trim(); line = line.trim();
while (line.length() > 67) { while (line.length() > 67) {
int i = line.lastIndexOf(' ', 67); int i = line.lastIndexOf(' ', 67);
@ -267,7 +272,8 @@ class ReplyBox extends Composite {
} }
quotedMsg.append(" > ").append(line).append("\n"); quotedMsg.append(" > ").append(line).append("\n");
} }
return quotedMsg.toString().substring(0, quotedMsg.length() - 1); // remove last '\n' quotedMsg.append("\n");
return quotedMsg.toString();
} }
private void hide() { private void hide() {

View File

@ -192,7 +192,7 @@ class DraftBox extends CommentBox {
setRangeHighlight(edit); setRangeHighlight(edit);
if (edit) { if (edit) {
String msg = comment.message() != null String msg = comment.message() != null
? comment.message().trim() ? comment.message()
: ""; : "";
editArea.setValue(msg); editArea.setValue(msg);
cancel.setVisible(!isNew()); cancel.setVisible(!isNew());

View File

@ -18,6 +18,7 @@ import com.google.gerrit.client.AvatarImage;
import com.google.gerrit.client.Dispatcher; import com.google.gerrit.client.Dispatcher;
import com.google.gerrit.client.FormatUtil; import com.google.gerrit.client.FormatUtil;
import com.google.gerrit.client.Gerrit; import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.change.ReplyBox;
import com.google.gerrit.client.changes.CommentApi; import com.google.gerrit.client.changes.CommentApi;
import com.google.gerrit.client.changes.CommentInfo; import com.google.gerrit.client.changes.CommentInfo;
import com.google.gerrit.client.changes.Util; import com.google.gerrit.client.changes.Util;
@ -143,17 +144,21 @@ class PublishedBox extends CommentBox {
replyBox.setEdit(true); replyBox.setEdit(true);
} }
void addReplyBox() { void addReplyBox(boolean quote) {
CommentInfo commentReply = CommentInfo.createReply(comment);
if (quote) {
commentReply.message(ReplyBox.quote(comment.message()));
}
getCommentManager().addDraftBox( getCommentManager().addDraftBox(
getCm().side(), getCm().side(),
CommentInfo.createReply(comment)).setEdit(true); commentReply).setEdit(true);
} }
void doReply() { void doReply() {
if (!Gerrit.isSignedIn()) { if (!Gerrit.isSignedIn()) {
Gerrit.doSignIn(getCommentManager().getSideBySide().getToken()); Gerrit.doSignIn(getCommentManager().getSideBySide().getToken());
} else if (replyBox == null) { } else if (replyBox == null) {
addReplyBox(); addReplyBox(false);
} else { } else {
openReplyBox(); openReplyBox();
} }
@ -165,6 +170,15 @@ class PublishedBox extends CommentBox {
doReply(); doReply();
} }
@UiHandler("quote")
void onQuote(ClickEvent e) {
e.stopPropagation();
if (!Gerrit.isSignedIn()) {
Gerrit.doSignIn(getCommentManager().getSideBySide().getToken());
}
addReplyBox(true);
}
@UiHandler("done") @UiHandler("done")
void onReplyDone(ClickEvent e) { void onReplyDone(ClickEvent e) {
e.stopPropagation(); e.stopPropagation();

View File

@ -61,6 +61,11 @@ limitations under the License.
<ui:attribute name='title'/> <ui:attribute name='title'/>
<div><ui:msg>Reply</ui:msg></div> <div><ui:msg>Reply</ui:msg></div>
</g:Button> </g:Button>
<g:Button ui:field='quote' styleName=''
title='Reply to this comment with quoting it'>
<ui:attribute name='title'/>
<div><ui:msg>Quote</ui:msg></div>
</g:Button>
<g:Button ui:field='done' styleName='' <g:Button ui:field='done' styleName=''
title='Reply "Done" to this comment'> title='Reply "Done" to this comment'>
<ui:attribute name='title'/> <ui:attribute name='title'/>