From 668fceb3c515634d0d2da2b0000f766265494e02 Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Wed, 2 Dec 2015 16:50:41 +0100 Subject: [PATCH] Add button for inline comments that allows quoting them Add a new 'Quote' button for inline comments that is displayed next to the 'Reply' button. On click the 'Quote' button prepolulates the reply with the quoted comment. Change-Id: I41349ffbead80458af68b24e69886d83b75323ed Signed-off-by: Edwin Kempin --- .../google/gerrit/client/change/ReplyBox.java | 26 ++++++++++++------- .../google/gerrit/client/diff/DraftBox.java | 2 +- .../gerrit/client/diff/PublishedBox.java | 20 +++++++++++--- .../gerrit/client/diff/PublishedBox.ui.xml | 5 ++++ 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/ReplyBox.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/ReplyBox.java index 133d3036e3..2366e59d6d 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/ReplyBox.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/ReplyBox.java @@ -76,7 +76,7 @@ import java.util.List; import java.util.Set; import java.util.TreeSet; -class ReplyBox extends Composite { +public class ReplyBox extends Composite { interface Binder extends UiBinder {} private static final Binder uiBinder = GWT.create(Binder.class); @@ -228,7 +228,7 @@ class ReplyBox extends Composite { void replyTo(MessageInfo msg) { if (msg.message() != null) { String t = message.getText(); - String m = quote(msg); + String m = quote(removePatchSetHeaderLine(msg.message())); if (t == null || t.isEmpty()) { t = m; } else if (t.endsWith("\n\n")) { @@ -238,20 +238,25 @@ class ReplyBox extends Composite { } else { t += "\n\n" + m; } - message.setText(t + "\n\n"); + message.setText(t); } } - private static String quote(MessageInfo msg) { - String m = msg.message().trim(); - if (m.startsWith("Patch Set ")) { - int i = m.indexOf('\n'); + private static String removePatchSetHeaderLine(String msg) { + msg = msg.trim(); + if (msg.startsWith("Patch Set ")) { + int i = msg.indexOf('\n'); 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(); - for (String line : m.split("\\n")) { + for (String line : msg.split("\\n")) { line = line.trim(); while (line.length() > 67) { int i = line.lastIndexOf(' ', 67); @@ -267,7 +272,8 @@ class ReplyBox extends Composite { } 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() { diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/DraftBox.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/DraftBox.java index 46c37edb9e..86d149ac43 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/DraftBox.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/DraftBox.java @@ -192,7 +192,7 @@ class DraftBox extends CommentBox { setRangeHighlight(edit); if (edit) { String msg = comment.message() != null - ? comment.message().trim() + ? comment.message() : ""; editArea.setValue(msg); cancel.setVisible(!isNew()); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/PublishedBox.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/PublishedBox.java index 48b4c3c68a..f5bcaa6dfd 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/PublishedBox.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/PublishedBox.java @@ -18,6 +18,7 @@ import com.google.gerrit.client.AvatarImage; import com.google.gerrit.client.Dispatcher; import com.google.gerrit.client.FormatUtil; 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.CommentInfo; import com.google.gerrit.client.changes.Util; @@ -143,17 +144,21 @@ class PublishedBox extends CommentBox { replyBox.setEdit(true); } - void addReplyBox() { + void addReplyBox(boolean quote) { + CommentInfo commentReply = CommentInfo.createReply(comment); + if (quote) { + commentReply.message(ReplyBox.quote(comment.message())); + } getCommentManager().addDraftBox( getCm().side(), - CommentInfo.createReply(comment)).setEdit(true); + commentReply).setEdit(true); } void doReply() { if (!Gerrit.isSignedIn()) { Gerrit.doSignIn(getCommentManager().getSideBySide().getToken()); } else if (replyBox == null) { - addReplyBox(); + addReplyBox(false); } else { openReplyBox(); } @@ -165,6 +170,15 @@ class PublishedBox extends CommentBox { doReply(); } + @UiHandler("quote") + void onQuote(ClickEvent e) { + e.stopPropagation(); + if (!Gerrit.isSignedIn()) { + Gerrit.doSignIn(getCommentManager().getSideBySide().getToken()); + } + addReplyBox(true); + } + @UiHandler("done") void onReplyDone(ClickEvent e) { e.stopPropagation(); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/PublishedBox.ui.xml b/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/PublishedBox.ui.xml index 46b76cad89..cbea847ab3 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/PublishedBox.ui.xml +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/diff/PublishedBox.ui.xml @@ -61,6 +61,11 @@ limitations under the License.
Reply
+ + +
Quote
+