Skip to content

Commit 98dde20

Browse files
sbraconniertonygermano
authored andcommitted
Add "toggle comment" action to right-click context menu
This lets the user perform the action to toggle comments on or off for the current line or the current selection in the code editor by selecting "Code->Toggle Comment" from the right-click context menu. Previously this action could only be performed by hotkey (ctrl+/ by default.) Signed-off-by: Tony Germano <tony@germano.name> Original-sign-off: 132de74 Issue: #87
1 parent 7910253 commit 98dde20

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

client/src/com/mirth/connect/client/ui/components/rsta/MirthRSyntaxTextArea.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public class MirthRSyntaxTextArea extends RSyntaxTextArea implements MirthTextIn
130130
private CustomJCheckBoxMenuItem wrapLinesMenuItem;
131131
private JMenu codeMenu;
132132
private CustomMenuItem formatCodeMenuItem;
133+
private CustomMenuItem toggleCommentMenuItem;
133134
private JMenu macroMenu;
134135
private CustomMenuItem beginMacroMenuItem;
135136
private CustomMenuItem endMacroMenuItem;
@@ -233,6 +234,7 @@ public void keyPressed(KeyEvent e) {
233234
wrapLinesMenuItem = new CustomJCheckBoxMenuItem(this, new WrapLinesAction(this), ActionInfo.DISPLAY_WRAP_LINES);
234235
codeMenu = new JMenu("Code");
235236
formatCodeMenuItem = new CustomMenuItem(this, new FormatCodeAction(this), ActionInfo.FORMAT_CODE);
237+
toggleCommentMenuItem = new CustomMenuItem(this, new ToggleCommentAction(this), ActionInfo.TOGGLE_COMMENT);
236238
macroMenu = new JMenu("Macro");
237239
beginMacroMenuItem = new CustomMenuItem(this, new BeginMacroAction(), ActionInfo.MACRO_BEGIN);
238240
endMacroMenuItem = new CustomMenuItem(this, new EndMacroAction(), ActionInfo.MACRO_END);
@@ -245,7 +247,7 @@ public void keyPressed(KeyEvent e) {
245247
getActionMap().put(ActionInfo.JOIN_LINE.getActionMapKey(), new JoinLineAction());
246248
getActionMap().put(ActionInfo.GO_TO_MATCHING_BRACKET.getActionMapKey(), new GoToMatchingBracketAction());
247249
getActionMap().put(ActionInfo.FORMAT_CODE.getActionMapKey(), new FormatCodeAction(this));
248-
getActionMap().put(ActionInfo.TOGGLE_COMMENT.getActionMapKey(), new ToggleCommentAction());
250+
getActionMap().put(ActionInfo.TOGGLE_COMMENT.getActionMapKey(), new ToggleCommentAction(this));
249251
getActionMap().put(ActionInfo.DOCUMENT_START.getActionMapKey(), new DocumentStartAction(false));
250252
getActionMap().put(ActionInfo.DOCUMENT_SELECT_START.getActionMapKey(), new DocumentStartAction(true));
251253
getActionMap().put(ActionInfo.DOCUMENT_END.getActionMapKey(), new DocumentEndAction(false));
@@ -496,6 +498,7 @@ protected JPopupMenu createPopupMenu() {
496498
menu.addSeparator();
497499

498500
codeMenu.add(formatCodeMenuItem);
501+
codeMenu.add(toggleCommentMenuItem);
499502
menu.add(codeMenu);
500503
menu.addSeparator();
501504

@@ -525,6 +528,7 @@ protected void configurePopupMenu(JPopupMenu popupMenu) {
525528
clearMarkedOccurrencesMenuItem.setEnabled(clearMarkedOccurrencesMenuItem.getAction().isEnabled() && canType && ((RSyntaxTextAreaHighlighter) getHighlighter()).getMarkAllHighlightCount() > 0);
526529
foldingMenu.setEnabled(getFoldManager().isCodeFoldingSupportedAndEnabled());
527530
formatCodeMenuItem.setEnabled(formatCodeMenuItem.getAction().isEnabled());
531+
toggleCommentMenuItem.setEnabled(toggleCommentMenuItem.getAction().isEnabled());
528532
beginMacroMenuItem.setEnabled(!isRecordingMacro());
529533
endMacroMenuItem.setEnabled(isRecordingMacro());
530534
playbackMacroMenuItem.setEnabled(!isRecordingMacro() && getCurrentMacro() != null);
@@ -545,6 +549,7 @@ protected void configurePopupMenu(JPopupMenu popupMenu) {
545549
collapseAllCommentFoldsMenuItem.updateAccelerator();
546550
expandAllFoldsMenuItem.updateAccelerator();
547551
formatCodeMenuItem.updateAccelerator();
552+
toggleCommentMenuItem.updateAccelerator();
548553
beginMacroMenuItem.updateAccelerator();
549554
endMacroMenuItem.updateAccelerator();
550555
playbackMacroMenuItem.updateAccelerator();

client/src/com/mirth/connect/client/ui/components/rsta/actions/ToggleCommentAction.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@
1313

1414
public class ToggleCommentAction extends org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaEditorKit.ToggleCommentAction {
1515

16-
public ToggleCommentAction() {
16+
protected MirthRSyntaxTextArea textArea;
17+
18+
public ToggleCommentAction(MirthRSyntaxTextArea textArea) {
1719
setProperties(MirthRSyntaxTextArea.getResourceBundle(), ActionInfo.TOGGLE_COMMENT.toString());
20+
21+
this.textArea = textArea;
22+
}
23+
24+
@Override
25+
public boolean isEnabled() {
26+
return textArea.isEditable() && textArea.isEnabled();
1827
}
1928
}

0 commit comments

Comments
 (0)