diff --git a/src/main/java/featurecat/lizzie/gui/CommentPane.java b/src/main/java/featurecat/lizzie/gui/CommentPane.java index a36619b2..6d6e66ec 100644 --- a/src/main/java/featurecat/lizzie/gui/CommentPane.java +++ b/src/main/java/featurecat/lizzie/gui/CommentPane.java @@ -49,6 +49,13 @@ public void mouseClicked(MouseEvent e) { Lizzie.frame.getFocus(); Lizzie.frame.checkRightClick(e); } + + @Override + public void mousePressed(MouseEvent e) { + if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { + Lizzie.frame.editComment(); + } + } }); scrollPane = new JScrollPane(); scrollPane.setBorder(BorderFactory.createEmptyBorder()); diff --git a/src/main/java/featurecat/lizzie/gui/Input.java b/src/main/java/featurecat/lizzie/gui/Input.java index 57f24362..0c48bd04 100644 --- a/src/main/java/featurecat/lizzie/gui/Input.java +++ b/src/main/java/featurecat/lizzie/gui/Input.java @@ -434,7 +434,9 @@ public void keyPressed(KeyEvent e) { break; case VK_C: - if (controlIsPressed(e)) { + if (controlIsPressed(e) && e.isShiftDown()) { + Lizzie.frame.copyCommentToClipboard(); + } else if (controlIsPressed(e)) { Lizzie.frame.copySgf(); } else { Lizzie.config.toggleCoordinates(); diff --git a/src/main/java/featurecat/lizzie/gui/LizzieFrame.java b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java index 4a9909d5..e03ae23f 100644 --- a/src/main/java/featurecat/lizzie/gui/LizzieFrame.java +++ b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java @@ -193,6 +193,11 @@ protected void paintComponent(Graphics g) { setVisible(true); + // avoid IME issue + // https://github.com/featurecat/lizzie/pull/880#issuecomment-800804632 + // https://github.com/yzyray/lizzie_adv/commit/e5e8be01b4e072615250e4c4cc8462938b7c0332 + mainPanel.enableInputMethods(false); + Input input = new Input(); mainPanel.addMouseListener(input); @@ -1179,6 +1184,8 @@ public void onDoubleClicked(int x, int y) { Lizzie.board.goToMoveNumberBeyondBranch(moveNumber); } } + } else if (Lizzie.config.showComment && commentRect.contains(x, y)) { + editComment(); } } diff --git a/src/main/java/featurecat/lizzie/gui/LizzieMain.java b/src/main/java/featurecat/lizzie/gui/LizzieMain.java index 026c2dac..a3fbc499 100644 --- a/src/main/java/featurecat/lizzie/gui/LizzieMain.java +++ b/src/main/java/featurecat/lizzie/gui/LizzieMain.java @@ -242,6 +242,11 @@ protected void paintComponent(Graphics g) { setVisible(true); + // avoid IME issue + // https://github.com/featurecat/lizzie/pull/880#issuecomment-800804632 + // https://github.com/yzyray/lizzie_adv/commit/e5e8be01b4e072615250e4c4cc8462938b7c0332 + enableInputMethods(false); + input = new Input(); // addMouseListener(input); addKeyListener(input); diff --git a/src/main/java/featurecat/lizzie/gui/MainFrame.java b/src/main/java/featurecat/lizzie/gui/MainFrame.java index a3172160..45058e35 100644 --- a/src/main/java/featurecat/lizzie/gui/MainFrame.java +++ b/src/main/java/featurecat/lizzie/gui/MainFrame.java @@ -13,6 +13,10 @@ import java.awt.FontFormatException; import java.awt.HeadlessException; import java.awt.LayoutManager; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; import java.io.File; @@ -24,6 +28,8 @@ import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; import javax.swing.SwingUtilities; import javax.swing.filechooser.FileNameExtensionFilter; import org.json.JSONObject; @@ -210,6 +216,37 @@ 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; + try { + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + Transferable transferableString = new StringSelection(comment); + clipboard.setContents(transferableString, null); + } catch (Exception e) { + e.printStackTrace(); + } + } + public void setPlayers(String whitePlayer, String blackPlayer) { playerTitle = String.format("(%s [W] vs %s [B])", whitePlayer, blackPlayer); updateTitle(); diff --git a/src/main/java/featurecat/lizzie/gui/Menu.java b/src/main/java/featurecat/lizzie/gui/Menu.java index 43a40036..dca13dd7 100644 --- a/src/main/java/featurecat/lizzie/gui/Menu.java +++ b/src/main/java/featurecat/lizzie/gui/Menu.java @@ -1185,6 +1185,29 @@ public void actionPerformed(ActionEvent e) { } }); gameMenu.add(pass); + + gameMenu.addSeparator(); + + final JMenuItem editComment = new JMenuItem("Edit comment"); + editComment.addActionListener( + new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Lizzie.frame.editComment(); + } + }); + gameMenu.add(editComment); + + final JMenuItem copyComment = new JMenuItem("Copy comment(Ctrl+Shift+C)"); + copyComment.addActionListener( + new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Lizzie.frame.copyCommentToClipboard(); + } + }); + gameMenu.add(copyComment); + gameMenu.addSeparator(); final JMenuItem clearBoard = new JMenuItem(resourceBundle.getString("Menu.game.clearBoard"));