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

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎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
privateCustomJCheckBoxMenuItemwrapLinesMenuItem;
131131
privateJMenucodeMenu;
132132
privateCustomMenuItemformatCodeMenuItem;
133+
privateCustomMenuItemtoggleCommentMenuItem;
133134
privateJMenumacroMenu;
134135
privateCustomMenuItembeginMacroMenuItem;
135136
privateCustomMenuItemendMacroMenuItem;
@@ -233,6 +234,7 @@ public void keyPressed(KeyEvent e) {
233234
wrapLinesMenuItem = newCustomJCheckBoxMenuItem(this, newWrapLinesAction(this), ActionInfo.DISPLAY_WRAP_LINES);
234235
codeMenu = newJMenu("Code");
235236
formatCodeMenuItem = newCustomMenuItem(this, newFormatCodeAction(this), ActionInfo.FORMAT_CODE);
237+
toggleCommentMenuItem = newCustomMenuItem(this, newToggleCommentAction(this), ActionInfo.TOGGLE_COMMENT);
236238
macroMenu = newJMenu("Macro");
237239
beginMacroMenuItem = newCustomMenuItem(this, newBeginMacroAction(), ActionInfo.MACRO_BEGIN);
238240
endMacroMenuItem = newCustomMenuItem(this, newEndMacroAction(), ActionInfo.MACRO_END);
@@ -245,7 +247,7 @@ public void keyPressed(KeyEvent e) {
245247
getActionMap().put(ActionInfo.JOIN_LINE.getActionMapKey(), newJoinLineAction());
246248
getActionMap().put(ActionInfo.GO_TO_MATCHING_BRACKET.getActionMapKey(), newGoToMatchingBracketAction());
247249
getActionMap().put(ActionInfo.FORMAT_CODE.getActionMapKey(), newFormatCodeAction(this));
248-
getActionMap().put(ActionInfo.TOGGLE_COMMENT.getActionMapKey(), newToggleCommentAction());
250+
getActionMap().put(ActionInfo.TOGGLE_COMMENT.getActionMapKey(), newToggleCommentAction(this));
249251
getActionMap().put(ActionInfo.DOCUMENT_START.getActionMapKey(), newDocumentStartAction(false));
250252
getActionMap().put(ActionInfo.DOCUMENT_SELECT_START.getActionMapKey(), newDocumentStartAction(true));
251253
getActionMap().put(ActionInfo.DOCUMENT_END.getActionMapKey(), newDocumentEndAction(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
publicclassToggleCommentActionextendsorg.fife.ui.rsyntaxtextarea.RSyntaxTextAreaEditorKit.ToggleCommentAction {
1515

16-
publicToggleCommentAction() {
16+
protectedMirthRSyntaxTextAreatextArea;
17+
18+
publicToggleCommentAction(MirthRSyntaxTextAreatextArea) {
1719
setProperties(MirthRSyntaxTextArea.getResourceBundle(), ActionInfo.TOGGLE_COMMENT.toString());
20+
21+
this.textArea = textArea;
22+
}
23+
24+
@Override
25+
publicbooleanisEnabled() {
26+
returntextArea.isEditable() && textArea.isEnabled();
1827
}
1928
}

0 commit comments

Comments
 (0)