Skip to content

Commit 47d76f6

Browse files
committed
Fix the feature to edit a comment
1 parent ceeb7ce commit 47d76f6

3 files changed

Lines changed: 38 additions & 20 deletions

File tree

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/GitHubIssue.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
import org.netbeans.modules.bugtracking.spi.IssueProvider;
6565
import org.netbeans.modules.bugtracking.spi.IssueStatusProvider;
6666
import org.openide.util.NbBundle;
67+
import org.pegdown.Extensions;
68+
import org.pegdown.PegDownProcessor;
6769

6870
/**
6971
*
@@ -246,6 +248,28 @@ public Issue editIssue(CreateIssueParams params) {
246248
return editIssue;
247249
}
248250

251+
public Comment editComment(Comment comment, String editedBody) {
252+
if (editedBody != null) {
253+
String originalBody = comment.getBody();
254+
if (issue != null) {
255+
comment.setBody(editedBody);
256+
Comment editComment = GitHubIssueSupport.editComment(getRepository(), comment);
257+
if (editComment != null) {
258+
PegDownProcessor processor = new PegDownProcessor(Extensions.FENCED_CODE_BLOCKS);
259+
String body = editComment.getBody();
260+
String bodyHtml = processor.markdownToHtml(body);
261+
comment.setBodyHtml(String.format("<html>%s</html>", bodyHtml)); // NOI18N
262+
comment.setBody(body);
263+
comment.setUpdatedAt(editComment.getUpdatedAt());
264+
} else {
265+
comment.setBody(originalBody);
266+
}
267+
return editComment;
268+
}
269+
}
270+
return null;
271+
}
272+
249273
public boolean isCreatedUser() {
250274
if (issue == null) {
251275
return false;

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/GitHubIssueController.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@
6565
import org.openide.util.HelpCtx;
6666
import org.openide.util.NbBundle;
6767
import org.openide.util.RequestProcessor;
68-
import org.pegdown.Extensions;
69-
import org.pegdown.PegDownProcessor;
7068

7169
/**
7270
*
@@ -199,11 +197,11 @@ public void propertyChange(PropertyChangeEvent evt) {
199197
}
200198

201199
@NbBundle.Messages({
202-
"GitHubIssueController.edit.comment.title=Edit Comment"
200+
"GitHubIssueController.edit.comment.title=Edit Comment",
201+
"GitHubIssueController.edit.comment.fail=Can't edit this comment."
203202
})
204203
private void editComment() {
205204
final Comment comment = getPanel().getEditedComment();
206-
final String originalBody = comment.getBody();
207205
final String editedBody = CommentTabbedPanel.showDialog(Bundle.GitHubIssueController_edit_comment_title(), comment.getBody());
208206
if (editedBody != null) {
209207
final GitHubIssue issue = getPanel().getIssue();
@@ -213,23 +211,18 @@ private void editComment() {
213211

214212
@Override
215213
public void run() {
216-
comment.setBody(editedBody);
217-
Comment editComment = GitHubIssueSupport.editComment(issue.getRepository(), comment);
218-
if (editComment != null) {
219-
PegDownProcessor processor = new PegDownProcessor(Extensions.FENCED_CODE_BLOCKS);
220-
String body = editComment.getBody();
221-
String bodyHtml = processor.markdownToHtml(body);
222-
comment.setBodyHtml(String.format("<html>%s</html>", bodyHtml)); // NOI18N
223-
SwingUtilities.invokeLater(new Runnable() {
224-
225-
@Override
226-
public void run() {
227-
getPanel().loadComments();
228-
}
229-
});
230-
} else {
231-
comment.setBody(originalBody);
214+
Comment editedComment = issue.editComment(comment, editedBody);
215+
if (editedComment == null) {
216+
UiUtils.showErrorDialog(Bundle.GitHubIssueController_edit_comment_fail());
217+
return;
232218
}
219+
SwingUtilities.invokeLater(new Runnable() {
220+
221+
@Override
222+
public void run() {
223+
getPanel().loadComments();
224+
}
225+
});
233226
}
234227
});
235228
}

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/ui/GitHubIssuePanel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ public void update() {
260260

261261
public void loadComments() {
262262
commentsPanel.loadComments();
263+
fireChange();
263264
}
264265

265266
private void setAssigneeSelected(User assignee) {

0 commit comments

Comments
 (0)