3535import java .awt .Dimension ;
3636import java .awt .Font ;
3737import java .awt .event .ActionEvent ;
38+ import java .awt .event .KeyEvent ;
3839import java .awt .event .MouseAdapter ;
3940import java .awt .event .MouseEvent ;
4041import java .io .BufferedReader ;
6162import javax .swing .JRadioButtonMenuItem ;
6263import javax .swing .JScrollPane ;
6364import javax .swing .JViewport ;
65+ import javax .swing .KeyStroke ;
6466import javax .swing .SwingUtilities ;
6567import javax .swing .ToolTipManager ;
6668import javax .swing .UIManager ;
7880import org .fife .ui .rsyntaxtextarea .SyntaxScheme ;
7981import org .fife .ui .rsyntaxtextarea .Theme ;
8082import org .fife .ui .rsyntaxtextarea .parser .TaskTagParser ;
83+ import org .fife .ui .rtextarea .ClipboardHistory ;
8184import org .fife .ui .rtextarea .Gutter ;
8285import org .fife .ui .rtextarea .GutterIconInfo ;
8386import org .fife .ui .rtextarea .RTextArea ;
87+ import org .fife .ui .rtextarea .RTextAreaEditorKit ;
88+ import org .fife .ui .rtextarea .RTextAreaEditorKit .CutAction ;
8489import org .fife .ui .rtextarea .RTextScrollPane ;
8590import org .fife .ui .rtextarea .RecordableTextAction ;
8691import org .fife .ui .rtextarea .SearchContext ;
@@ -226,47 +231,69 @@ public void mousePressed(final MouseEvent me) {
226231 });
227232 }
228233
234+ protected boolean isLocked () {
235+ return !(isEditable () && isEnabled ());
236+ }
237+
238+ @ Override
239+ protected JPopupMenu createPopupMenu () {
240+ super .createPopupMenu ();
241+ JPopupMenu popup = new JPopupMenu ();
242+ TextEditor .addPopupMenuSeparator (popup , "Undo/Redo:" );
243+ popup .add (getMenuItem ("Undo" , EditorPaneActions .rtaUndoAction , true ));
244+ popup .add (getMenuItem ("Redo" , EditorPaneActions .rtaRedoAction , true ));
245+ TextEditor .addPopupMenuSeparator (popup , "Code Editing:" );
246+ popup .add (getMenuItem ("Copy" , EditorPaneActions .copyAction , false ));
247+ popup .add (getMenuItem ("Cut" , EditorPaneActions .cutAction , true ));
248+ popup .add (getMenuItem ("Paste" , EditorPaneActions .pasteAction , true ));
249+ popup .add (getMenuItem ("Delete Line" , EditorPaneActions .rtaDeleteLineAction , true ));
250+ popup .add (getMenuItem ("Delete Rest of Line" , EditorPaneActions .rtaDeleteRestOfLineAction , true ));
251+ TextEditor .addPopupMenuSeparator (popup , "Code Selection:" );
252+ popup .add (getMenuItem ("Select All" , EditorPaneActions .selectAllAction , false ));
253+ popup .add (getMenuItem ("Select Line" , EditorPaneActions .selectLineAction , false ));
254+ popup .add (getMenuItem ("Select Paragraph" , EditorPaneActions .selectParagraphAction , false ));
255+ return popup ;
256+ }
257+
229258 @ Override
230259 protected void appendFoldingMenu (JPopupMenu popup ) {
231260 // We are overriding the entire foldingMenu completely so that we can include
232261 // our shortcuts in the menu items. These commands are not listed on the
233262 // menubar, so this is the only access point in the GUI for these
234263 // popup.addSeparator();
235- popup .add (getMenuItem ("Select Line" , EditorPaneActions .selectLineAction ));
236- popup .add (getMenuItem ("Select Paragraph" , EditorPaneActions .selectParagraphAction ));
237264 TextEditor .addPopupMenuSeparator (popup , "Code Folding:" );
238- popup .add (getMenuItem ("Collapse Fold" , EditorPaneActions .rstaCollapseFoldAction ));
239- popup .add (getMenuItem ("Expand Fold" , EditorPaneActions .rstaExpandFoldAction ));
240- popup .add (getMenuItem ("Toggle Current Fold" , EditorPaneActions .rstaToggleCurrentFoldAction ));
265+ popup .add (getMenuItem ("Collapse Fold" , EditorPaneActions .rstaCollapseFoldAction , false ));
266+ popup .add (getMenuItem ("Expand Fold" , EditorPaneActions .rstaExpandFoldAction , false ));
267+ popup .add (getMenuItem ("Toggle Current Fold" , EditorPaneActions .rstaToggleCurrentFoldAction , false ));
241268 // popup.addSeparator();
242- popup .add (getMenuItem ("Collapse All Folds" , EditorPaneActions .rstaCollapseAllFoldsAction ));
243- popup .add (getMenuItem ("Expand All Folds" , EditorPaneActions .rstaExpandAllFoldsAction ));
269+ popup .add (getMenuItem ("Collapse All Folds" , EditorPaneActions .rstaCollapseAllFoldsAction , false ));
270+ popup .add (getMenuItem ("Expand All Folds" , EditorPaneActions .rstaExpandAllFoldsAction , false ));
244271 // popup.addSeparator();
245- popup .add (getMenuItem ("Collapse All Comments" , EditorPaneActions .rstaCollapseAllCommentFoldsAction ));
272+ popup .add (getMenuItem ("Collapse All Comments" , EditorPaneActions .rstaCollapseAllCommentFoldsAction , false ));
246273 }
247274
248275 private void adjustPopupMenu () {
249276 final JPopupMenu popup = super .getPopupMenu ();
250277 // See #appendFoldingMenu()
251278 TextEditor .addPopupMenuSeparator (popup , "Code Formatting:" );
252- popup .add (getMenuItem ("Indent Right" , EditorPaneActions .epaIncreaseIndentAction ));
253- popup .add (getMenuItem ("Indent Left" , EditorPaneActions .rstaDecreaseIndentAction ));
279+ popup .add (getMenuItem ("Indent Right" , EditorPaneActions .epaIncreaseIndentAction , true ));
280+ popup .add (getMenuItem ("Indent Left" , EditorPaneActions .rstaDecreaseIndentAction , true ));
254281 //popup.addSeparator();
255- popup .add (getMenuItem ("Move Up" , EditorPaneActions .rtaLineUpAction ));
256- popup .add (getMenuItem ("Move Down" , EditorPaneActions .rtaLineDownAction ));
257- popup .add (getMenuItem ("Join Lines" , EditorPaneActions .rtaJoinLinesAction ));
282+ popup .add (getMenuItem ("Move Up" , EditorPaneActions .rtaLineUpAction , true ));
283+ popup .add (getMenuItem ("Move Down" , EditorPaneActions .rtaLineDownAction , true ));
284+ popup .add (getMenuItem ("Join Lines" , EditorPaneActions .rtaJoinLinesAction , true ));
258285 JMenu menu = new JMenu ("Transform Case" );
259286 popup .add (menu );
260- menu .add (getMenuItem ("Invert Case" , EditorPaneActions .rtaInvertSelectionCaseAction ));
287+ menu .add (getMenuItem ("Invert Case" , EditorPaneActions .rtaInvertSelectionCaseAction , true ));
261288 menu .addSeparator ();
262- menu .add (getMenuItem ("Camel Case" , EditorPaneActions .epaCamelCaseAction ));
263- menu .add (getMenuItem ("Lower Case" , EditorPaneActions .rtaLowerSelectionCaseAction ));
264- menu .add (getMenuItem ("Lower Case ('_' Sep.)" , EditorPaneActions .epaLowerCaseUndAction ));
265- menu .add (getMenuItem ("Title Case" , EditorPaneActions .epaTitleCaseAction ));
266- menu .add (getMenuItem ("Upper Case" , EditorPaneActions .rtaUpperSelectionCaseAction ));
289+ menu .add (getMenuItem ("Camel Case" , EditorPaneActions .epaCamelCaseAction , true ));
290+ menu .add (getMenuItem ("Lower Case" , EditorPaneActions .rtaLowerSelectionCaseAction , true ));
291+ menu .add (getMenuItem ("Lower Case ('_' Sep.)" , EditorPaneActions .epaLowerCaseUndAction , true ));
292+ menu .add (getMenuItem ("Title Case" , EditorPaneActions .epaTitleCaseAction , true ));
293+ menu .add (getMenuItem ("Upper Case" , EditorPaneActions .rtaUpperSelectionCaseAction , true ));
267294 TextEditor .addPopupMenuSeparator (popup , "Ocurrences:" );
268- popup .add (getMenuItem ("Next Occurrence" , EditorPaneActions .rtaNextOccurrenceAction ));
269- popup .add (getMenuItem ("Previous Occurrence" , EditorPaneActions .rtaPrevOccurrenceAction ));
295+ popup .add (getMenuItem ("Next Occurrence" , EditorPaneActions .rtaNextOccurrenceAction , false ));
296+ popup .add (getMenuItem ("Previous Occurrence" , EditorPaneActions .rtaPrevOccurrenceAction , false ));
270297 TextEditor .addPopupMenuSeparator (popup , "Utilities:" );
271298 popup .add (new OpenLinkUnderCursor ().getMenuItem ());
272299 popup .add (new SearchWebOnSelectedText ().getMenuItem ());
@@ -275,10 +302,19 @@ private void adjustPopupMenu() {
275302
276303 }
277304
278- private JMenuItem getMenuItem (final String label , final String actionID ) {
305+ private JMenuItem getMenuItem (final String label , final String actionID , final boolean editingAction ) {
279306 final Action action = getActionMap ().get (actionID );
280307 final JMenuItem jmi = new JMenuItem (action );
281308 jmi .setAccelerator (getPaneActions ().getAccelerator (actionID ));
309+ jmi .addActionListener (e -> {
310+ if (editingAction && isLocked ()) {
311+ UIManager .getLookAndFeel ().provideErrorFeedback (this );
312+ } else try {
313+ action .actionPerformed (e );
314+ } catch (final Exception | Error ignored ) {
315+ UIManager .getLookAndFeel ().provideErrorFeedback (this );
316+ }
317+ });
282318 jmi .setText (label );
283319 return jmi ;
284320 }
0 commit comments