Skip to content

Commit

Permalink
Edit comment by double-click on comment area for featurecat#806
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiraoka committed Mar 9, 2021
1 parent b0263e2 commit 145e18d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/featurecat/lizzie/gui/CommentPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public CommentPane(LizzieMain owner) {
public void mouseClicked(MouseEvent e) {
Lizzie.frame.getFocus();
}

@Override
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
Lizzie.frame.editComment();
}
}
});
scrollPane = new JScrollPane();
scrollPane.setBorder(BorderFactory.createEmptyBorder());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/featurecat/lizzie/gui/LizzieFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,8 @@ public void onDoubleClicked(int x, int y) {
Lizzie.board.goToMoveNumberBeyondBranch(moveNumber);
}
}
} else if (Lizzie.config.showComment && commentRect.contains(x, y)) {
editComment();
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/featurecat/lizzie/gui/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.json.JSONObject;

Expand Down Expand Up @@ -159,6 +161,25 @@ public void addSuggestionAsBranch() {}

public abstract void pasteSgf();

public void editComment() {
String oldComment = Lizzie.board.getHistory().getData().comment;
// https://stackoverflow.com/questions/7765478/how-to-add-text-area-on-joptionpane
// https://stackoverflow.com/a/55678093
JTextArea textArea = new JTextArea(oldComment);
textArea.setColumns(40);
textArea.setRows(20);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setSize(textArea.getPreferredSize().width, textArea.getPreferredSize().height);
int ret =
JOptionPane.showConfirmDialog(
null, new JScrollPane(textArea), "Comment", JOptionPane.OK_CANCEL_OPTION);
if (ret == JOptionPane.OK_OPTION) {
Lizzie.board.getHistory().getData().comment = textArea.getText();
refresh();
}
}

public void copyCommentToClipboard() {
String comment = Lizzie.board.getHistory().getData().comment;
if (comment.isEmpty()) return;
Expand Down

0 comments on commit 145e18d

Please sign in to comment.