diff --git a/Ghidra/Features/Base/src/main/help/help/topics/CommentsPlugin/Comments.htm b/Ghidra/Features/Base/src/main/help/help/topics/CommentsPlugin/Comments.htm index f3ae0b291d..677169e803 100644 --- a/Ghidra/Features/Base/src/main/help/help/topics/CommentsPlugin/Comments.htm +++ b/Ghidra/Features/Base/src/main/help/help/topics/CommentsPlugin/Comments.htm @@ -92,16 +92,7 @@ -
- If the Enter accepts comment checkbox is selected, you can simply press - the Enter key to set the comment and close the dialog. When the checkbox is not - selected, the Enter key simply adds a new line to the current comment for a multiple - line comment.
-
-

- - + @@ -110,6 +101,30 @@
+ +
+

+ This dialog has the following keyboard shortcut behavior: +

+ + +
+
+ + +

Deleting Comments

diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/comments/CommentsDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/comments/CommentsDialog.java index d71b0fc6d1..91ba90a4e2 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/comments/CommentsDialog.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/comments/CommentsDialog.java @@ -20,7 +20,8 @@ import java.awt.event.*; import java.util.*; import javax.swing.*; -import javax.swing.event.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import javax.swing.text.Document; import javax.swing.text.JTextComponent; @@ -63,19 +64,13 @@ public class CommentsDialog extends DialogComponentProvider implements KeyListen private boolean enterMode = false; private JCheckBox enterBox = new GCheckBox("Enter accepts comment", enterMode); { - enterBox.addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - enterMode = enterBox.isSelected(); - plugin.updateOptions(); - } + enterBox.addChangeListener(e -> { + enterMode = enterBox.isSelected(); + plugin.updateOptions(); }); } private JPopupMenu popup = new JPopupMenu(); - /** - * Constructor - */ CommentsDialog(CommentsPlugin plugin) { super("Set Comments"); setHelpLocation(new HelpLocation(plugin.getName(), "Comments")); @@ -269,16 +264,13 @@ public class CommentsDialog extends DialogComponentProvider implements KeyListen Arrays.sort(annotations); GComboBox annotationsComboBox = new GComboBox<>(annotations); JButton addAnnotationButton = new JButton("Add Annotation"); - addAnnotationButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextArea currentTextArea = getSelectedTextArea(); - AnnotationAdapterWrapper aaw = - (AnnotationAdapterWrapper) annotationsComboBox.getSelectedItem(); - currentTextArea.insert(aaw.getPrototypeString(), - currentTextArea.getCaretPosition()); - currentTextArea.setCaretPosition(currentTextArea.getCaretPosition() - 1); - } + addAnnotationButton.addActionListener(e -> { + JTextArea currentTextArea = getSelectedTextArea(); + AnnotationAdapterWrapper aaw = + (AnnotationAdapterWrapper) annotationsComboBox.getSelectedItem(); + currentTextArea.insert(aaw.getPrototypeString(), + currentTextArea.getCaretPosition()); + currentTextArea.setCaretPosition(currentTextArea.getCaretPosition() - 1); }); JPanel annoPanel = new JPanel(); annoPanel.add(addAnnotationButton); @@ -360,30 +352,22 @@ public class CommentsDialog extends DialogComponentProvider implements KeyListen tab.addTab(" Plate Comment ", new JScrollPane(plateField)); tab.addTab(" Repeatable Comment ", new JScrollPane(repeatableField)); - tab.addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent ev) { - chooseFocus(); - } - }); + tab.addChangeListener(ev -> chooseFocus()); - ActionListener addAnnotationAction = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextArea currentTextArea = getSelectedTextArea(); - for (int i = 0; i < annotations.length; i++) { - if (annotations[i].toString().equals(e.getActionCommand())) { - currentTextArea.insert(annotations[i].getPrototypeString(), - currentTextArea.getCaretPosition()); - currentTextArea.setCaretPosition(currentTextArea.getCaretPosition() - 1); - } + ActionListener addAnnotationAction = e -> { + JTextArea currentTextArea = getSelectedTextArea(); + for (AnnotationAdapterWrapper annotation : annotations) { + if (annotation.toString().equals(e.getActionCommand())) { + currentTextArea.insert(annotation.getPrototypeString(), + currentTextArea.getCaretPosition()); + currentTextArea.setCaretPosition(currentTextArea.getCaretPosition() - 1); } } }; JMenu insertMenu = new JMenu("Insert"); - for (int i = 0; i < annotations.length; i++) { - JMenuItem menuItem = new JMenuItem(annotations[i].toString()); + for (AnnotationAdapterWrapper annotation : annotations) { + JMenuItem menuItem = new JMenuItem(annotation.toString()); menuItem.addActionListener(addAnnotationAction); insertMenu.add(menuItem); } @@ -466,14 +450,26 @@ public class CommentsDialog extends DialogComponentProvider implements KeyListen @Override public void keyPressed(KeyEvent e) { JTextArea textArea = (JTextArea) e.getSource(); + if (e.getKeyCode() != KeyEvent.VK_ENTER) { + return; + } - if (e.getKeyCode() == KeyEvent.VK_ENTER) { - if (e.isShiftDown() && enterMode) { - textArea.append("\n"); - } - else if (e.isShiftDown() != enterMode) { - okCallback(); - } + int modifiers = e.getModifiersEx(); + if ((modifiers & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) { + textArea.replaceSelection("\n"); + e.consume(); + return; + } + + if ((modifiers & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK) { + okCallback(); // Control-Enter allows closes the dialog + e.consume(); + return; + } + + if (enterMode) { + e.consume(); + okCallback(); } }