55
55
import java .util .regex .Pattern ;
56
56
57
57
import javax .swing .Action ;
58
+ import javax .swing .ButtonGroup ;
58
59
import javax .swing .JMenu ;
59
60
import javax .swing .JMenuItem ;
60
61
import javax .swing .JOptionPane ;
61
62
import javax .swing .JPopupMenu ;
63
+ import javax .swing .JRadioButtonMenuItem ;
62
64
import javax .swing .JScrollPane ;
63
65
import javax .swing .JViewport ;
64
66
import javax .swing .KeyStroke ;
67
+ import javax .swing .SwingUtilities ;
65
68
import javax .swing .ToolTipManager ;
66
69
import javax .swing .UIManager ;
67
70
import javax .swing .event .DocumentEvent ;
@@ -137,6 +140,7 @@ public class EditorPane extends RSyntaxTextArea implements DocumentListener {
137
140
private boolean autoCompletionWithoutKey ;
138
141
private String supportStatus ;
139
142
private final ErrorParser errorHighlighter ;
143
+ private final JMenu noneLangSyntaxMenu ;
140
144
141
145
142
146
@ Parameter
@@ -210,6 +214,7 @@ public void hyperlinkUpdate(final HyperlinkEvent hle) {
210
214
getActionMap ().put (RTextAreaEditorKit .rtaPrevBookmarkAction , new NextBookMarkActionImpl (RTextAreaEditorKit .rtaPrevBookmarkAction , false ));
211
215
getActionMap ().put (RTextAreaEditorKit .rtaToggleBookmarkAction , new ToggleBookmarkAc
10000
tionImpl ());
212
216
217
+ noneLangSyntaxMenu = geSyntaxForNoneLang ();
213
218
adjustPopupMenu ();
214
219
215
220
ToolTipManager .sharedInstance ().registerComponent (this );
@@ -274,6 +279,8 @@ private void adjustPopupMenu() {
274
279
popup .add (menu );
275
280
menu .add (getMenuItem ("Open URL Under Cursor" , new OpenLinkUnderCursor ()));
276
281
menu .add (getMenuItem ("Search the Web for Selected Text" , new SearchWebOnSelectedText ()));
282
+ popup .addSeparator ();
283
+ popup .add (noneLangSyntaxMenu );
277
284
}
278
285
279
286
private JMenuItem getMenuItem (final String label , final RecordableTextAction a ) {
@@ -285,6 +292,36 @@ private JMenuItem getMenuItem(final String label, final RecordableTextAction a)
285
292
return item ;
286
293
}
287
294
295
+ private JMenu geSyntaxForNoneLang () {
296
+ final JMenu menu = new JMenu ("Non-executable Syntax" );
297
+ menu .setToolTipText ("Markup languages when scripting language is none" );
298
+ final ButtonGroup bg = new ButtonGroup ();
299
+ menu .add (getSyntaxItem (bg , "None" , SYNTAX_STYLE_NONE ));
300
+ bg .getElements ().nextElement ().setSelected (true ); //select none
301
+ menu .addSeparator ();
302
+ menu .add (getSyntaxItem (bg , "CSS" , SYNTAX_STYLE_CSS ));
303
+ menu .add (getSyntaxItem (bg , "HTML" , SYNTAX_STYLE_HTML ));
304
+ menu .add (getSyntaxItem (bg , "JSON" , SYNTAX_STYLE_JSON ));
305
+ //menu.add(getSyntaxItem(bg, "sh", SYNTAX_STYLE_UNIX_SHELL));
306
+ menu .add (getSyntaxItem (bg , "XML" , SYNTAX_STYLE_XML ));
307
+ return menu ;
308
+ }
309
+
310
+ private JMenuItem getSyntaxItem (final ButtonGroup bg , final String label , final String syntaxId ) {
311
+ final JRadioButtonMenuItem item = new JRadioButtonMenuItem (label );
312
+ bg .add (item );
313
+ item .addActionListener (e -> {
314
+ if (getCurrentLanguage () == null ) {
315
+ setSyntaxEditingStyle (syntaxId );
316
+ } else {
317
+ log .error ("[BUG] Unknown state: Non-executable syntaxes cannot be applied to valid languages" );
318
+ bg .getElements ().nextElement ().setSelected (true ); //select none
319
+ setSyntaxEditingStyle (SYNTAX_STYLE_NONE );
320
+ }
321
+ });
322
+ return item ;
323
+ }
324
+
288
325
@ Override
289
326
public void setTabSize (final int width ) {
290
327
if (getTabSize () != width ) super .setTabSize (width );
@@ -672,6 +709,7 @@ protected void setLanguage(final ScriptLanguage language,
672
709
setText (header += getText ());
673
710
}
674
711
712
+ noneLangSyntaxMenu .setEnabled (language == null );
675
713
if ("None" .equals (languageName ) ) {
676
714
supportStatus = "Active language: None" ;
677
715
return ; // no need to update console any further
0 commit comments