Merge "Add button for inline comments that allows quoting them"
This commit is contained in:
		| @@ -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<HTMLPanel, ReplyBox> {} | ||||
|   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() { | ||||
|   | ||||
| @@ -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()); | ||||
|   | ||||
| @@ -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(); | ||||
|   | ||||
| @@ -61,6 +61,11 @@ limitations under the License. | ||||
|           <ui:attribute name='title'/> | ||||
|           <div><ui:msg>Reply</ui:msg></div> | ||||
|         </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='' | ||||
|             title='Reply "Done" to this comment'> | ||||
|           <ui:attribute name='title'/> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Edwin Kempin
					Edwin Kempin