-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathRText.java
More file actions
1623 lines (1322 loc) · 44.9 KB
/
Copy pathRText.java
File metadata and controls
1623 lines (1322 loc) · 44.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* 11/14/2003
*
* RText.java - A syntax highlighting programmer's text editor written in Java.
* Copyright (C) 2003 Robert Futrell
* https://bobbylight.github.io/RText/
* Licensed under a modified BSD license.
* See the included license file for details.
*/
package org.fife.rtext;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import javax.swing.*;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.ChangeEvent;
import javax.swing.text.Element;
import org.fife.help.HelpDialog;
import org.fife.rsta.ui.CollapsibleSectionPanel;
import org.fife.rtext.actions.ActionFactory;
import org.fife.ui.CustomizableToolBar;
import org.fife.ui.OptionsDialog;
import org.fife.ui.SplashScreen;
import org.fife.ui.StandardAction;
import org.fife.ui.app.*;
import org.fife.ui.app.icons.IconGroup;
import org.fife.ui.app.icons.RasterImageIconGroup;
import org.fife.ui.app.icons.SvgIconGroup;
import org.fife.ui.rsyntaxtextarea.*;
import org.fife.ui.rtextarea.RTextArea;
import org.fife.ui.dockablewindows.DockableWindow;
import org.fife.ui.dockablewindows.DockableWindowConstants;
import org.fife.ui.dockablewindows.DockableWindowPanel;
import org.fife.ui.rtextfilechooser.FileChooserOwner;
import org.fife.ui.rtextfilechooser.RTextFileChooser;
import org.fife.util.MacOSUtil;
import org.fife.util.TranslucencyUtil;
/**
* An instance of the RText text editor. <code>RText</code> is a programmer's
* text editor with the following features:
*
* <ul>
* <li>Syntax highlighting for 45+ languages.
* <li>Code folding.
* <li>Edit multiple documents simultaneously.
* <li>Auto-indent.
* <li>Find/Replace/Find in Files, with regular expression functionality.
* <li>Printing and Print Preview.
* <li>Online help.
* <li>Intelligent source browsing via Exuberant Ctags.
* <li>Macros.
* <li>Code templates.
* <li>Many other features.
* </ul>
*
* At the heart of this program is
* {@link org.fife.ui.rsyntaxtextarea.RSyntaxTextArea}, a fully-featured,
* syntax highlighting text component. That's where most of the meat is.
* All text areas are contained in a subclass of
* {@link org.fife.rtext.AbstractMainView}, which keeps the state of all of the
* text areas in synch (fonts used, colors, etc.). This class (RText) contains
* an instance of a subclass of {@link org.fife.rtext.AbstractMainView} (which
* contains all of the text areas) as well as the menu, source browser, and
* status bar.
*
* @author Robert Futrell
* @version 3.0.1
*/
public class RText extends AbstractPluggableGUIApplication<RTextPrefs>
implements ActionListener, CaretListener, PropertyChangeListener,
RTextActionInfo, FileChooserOwner {
// Constants specifying the current view style.
public static final int TABBED_VIEW = 0;
public static final int SPLIT_PANE_VIEW = 1;
public static final int MDI_VIEW = 2;
// Properties fired.
private static final String MAIN_VIEW_STYLE_PROPERTY = "RText.mainViewStyle";
private Map<String, IconGroup> iconGroupMap;
private RTextMenuBar menuBar;
private OptionsDialog optionsDialog;
private CollapsibleSectionPanel csp; // Contains the AbstractMainView
private AbstractMainView mainView; // Component showing all open documents.
private int mainViewStyle;
private RTextFileChooser chooser;
private RemoteFileChooser rfc;
private HelpDialog helpDialog;
private SpellingErrorWindow spellingWindow;
private SyntaxScheme colorScheme;
private String workingDirectory; // The directory for new empty files.
private String newFileName; // The name for new empty text files.
private boolean showHostName;
/**
* Whether <code>searchWindowOpacityListener</code> has been attempted to be
* created yet.
*/
private boolean windowListenersInited;
/**
* Listens for focus events of certain child windows (those that can
* be made translucent on focus lost).
*/
private ChildWindowListener searchWindowOpacityListener;
/**
* Whether the Find and Replace dialogs can have their opacity changed.
*/
private boolean searchWindowOpacityEnabled;
/**
* The opacity with which to render unfocused child windows that support
* opacity changes.
*/
private float searchWindowOpacity;
/**
* The rule used for making certain unfocused child windows translucent.
*/
private int searchWindowOpacityRule;
/**
* The (lazily created) name of localhost. Do not access this field
* directly; instead, use {@link #getHostName()}.
*/
private String hostName;
private RecentFileManager recentFileManager;
/**
* Used as a "hack" to re-load the Options dialog if the user opens it
* too early, before all plugins have added their options to it.
*/
private int lastPluginCount;
private static final String DEFAULT_ICON_GROUP_NAME = "IntelliJ Icons (Dark)";
/**
* System property that, if set, causes RText to print timing information
* while it is starting up.
*/
private static final String PROPERTY_PRINT_START_TIMES = "printStartTimes";
public static final String VERSION_STRING = "6.1.0";
/**
* Creates an instance of the <code>RText</code> editor.
*
* @param context The application context that started this instance.
* @param filesToOpen Array of <code>java.lang.String</code>s containing
* the files we want to open initially. This can be
* <code>null</code> if no files are to be opened.
* @param preferences The preferences with which to initialize this RText.
*/
public RText(RTextAppContext context, String[] filesToOpen, RTextPrefs preferences) {
super(context, "rtext", preferences);
init(filesToOpen);
}
// What to do when user does something.
@Override
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
switch (command) {
case "TileVertically" -> ((RTextMDIView)mainView).tileWindowsVertically();
case "TileHorizontally" -> ((RTextMDIView)mainView).tileWindowsHorizontally();
case "Cascade" -> ((RTextMDIView)mainView).cascadeWindows();
}
}
/**
* Adds a dockable window to this application.
*
* @param wind The window to add.
*/
public void addDockableWindow(DockableWindow wind) {
((DockableWindowPanel)mainContentPanel).addDockableWindow(wind);
}
/**
* Returns whether tabs are emulated with spaces (i.e. "soft" tabs).
* This simply calls <code>mainView.areTabsEmulated</code>.
*
* @return <code>true</code> if tabs are emulated with spaces;
* <code>false</code> if they aren't.
*/
public boolean areTabsEmulated() {
return mainView.areTabsEmulated();
}
/**
* Called when cursor in text editor changes position.
*
* @param e The caret event.
*/
@Override
public void caretUpdate(CaretEvent e) {
// NOTE: e may be "null"; we do this sometimes to force caret
// updates to update e.g. the current line highlight.
RTextEditorPane textArea = mainView.getCurrentTextArea();
int dot = textArea.getCaretPosition();//e.getDot();
// Update row/column information in status field.
Element map = textArea.getDocument().getDefaultRootElement();
int line = map.getElementIndex(dot);
int lineStartOffset = map.getElement(line).getStartOffset();
((StatusBar)getStatusBar()).setRowAndColumn(
line+1, dot-lineStartOffset+1);
}
/**
* Converts all instances of a number of spaces equal to a tab in all open
* documents into tabs.
*
* @see #convertOpenFilesTabsToSpaces
*/
private void convertOpenFilesSpacesToTabs() {
mainView.convertOpenFilesSpacesToTabs();
}
/**
* Converts all tabs in all open documents into an equivalent number of
* spaces.
*
* @see #convertOpenFilesSpacesToTabs
*/
private void convertOpenFilesTabsToSpaces() {
mainView.convertOpenFilesTabsToSpaces();
}
/**
* Returns the About dialog for this application.
*
* @return The About dialog.
*/
@Override
protected JDialog createAboutDialog() {
return new AboutDialog(this);
}
/**
* Creates the array of actions used by this RText.
*
* @param prefs The RText properties for this RText instance.
*/
@Override
protected void createActions(RTextPrefs prefs) {
ActionFactory.addActions(this, prefs);
loadActionShortcuts(getShortcutsFile());
}
/**
* Creates and returns the menu bar used in this application.
*
* @param prefs This GUI application's preferences.
* @return The menu bar.
*/
@Override
protected JMenuBar createMenuBar(RTextPrefs prefs) {
//splashScreen.updateStatus(msg.getString("CreatingMenuBar"), 75);
menuBar = new RTextMenuBar(this);
mainView.addPropertyChangeListener(menuBar);
menuBar.setWindowMenuVisible(prefs.mainView==MDI_VIEW);
return menuBar;
}
/**
* Creates a new instance of an RText window with properties identical
* to this one.
*
* @param filesToOpen The set of files to open. Can be {@code null}.
* @return The instance.
*/
public RText createNewInstance(String[] filesToOpen) {
RTextAppContext context = (RTextAppContext)getAppContext();
return new RText(context, filesToOpen, getActivePreferencesState());
}
/**
* Returns the splash screen to display while this GUI application is
* loading.
*
* @return The splash screen. If <code>null</code> is returned, no
* splash screen is displayed.
*/
@Override
protected SplashScreen createSplashScreen() {
String img = "org/fife/rtext/graphics/" + getString("Splash");
return new SplashScreen(img, getString("Initializing"));
}
/**
* Returns the status bar to be used by this application.
*
* @param prefs This GUI application's preferences.
* @return The status bar.
*/
@Override
protected org.fife.ui.StatusBar createStatusBar(RTextPrefs prefs) {
return new StatusBar(this, getString("Ready"),
!prefs.wordWrap, 1,1,
prefs.textMode==RTextEditorPane.OVERWRITE_MODE);
}
/**
* Creates and returns the toolbar to be used by this application.
*
* @param prefs This GUI application's preferences.
* @return The toolbar.
*/
@Override
protected CustomizableToolBar createToolBar(RTextPrefs prefs) {
return new ToolBar("rtext - Toolbar", this);
}
/**
* Overridden so we can syntax highlight the Java exception displayed.
*
* @param owner The dialog that threw the Exception.
* @param t The exception/throwable that occurred.
* @param desc A short description of the error. This can be
* <code>null</code>.
*/
@Override
public void displayException(Dialog owner, Throwable t, String desc) {
ExceptionDialog ed = new ExceptionDialog(owner, t);
if (desc!=null) {
ed.setDescription(desc);
}
ed.setLocationRelativeTo(owner);
ed.setTitle(getString("ErrorDialogTitle"));
ed.setVisible(true);
}
/**
* Overridden so we can syntax highlight the Java exception displayed.
*
* @param owner The child frame that threw the Exception.
* @param t The exception/throwable that occurred.
* @param desc A short description of the error. This can be
* <code>null</code>.
*/
@Override
public void displayException(Frame owner, Throwable t, String desc) {
ExceptionDialog ed = new ExceptionDialog(owner, t);
if (desc!=null) {
ed.setDescription(desc);
}
ed.setLocationRelativeTo(owner);
ed.setTitle(getString("ErrorDialogTitle"));
ed.setVisible(true);
}
/**
* Called when the user attempts to close the application, whether from
* an "Exit" menu item, closing the main application window, or any other
* means. The user is prompted to save any dirty documents, and this
* RText instance is closed.
*/
@Override
public void doExit() {
// Attempt to close all open documents.
boolean allDocumentsClosed = getMainView().closeAllDocuments();
// Assuming all documents closed okay (ie, the user
// didn't click "Cancel")...
if (allDocumentsClosed) {
// If there will be no more rtext's running, stop the JVM.
if (StoreKeeper.getInstanceCount()==1) {
savePreferences();
boolean saved = RTextEditorPane.saveTemplates();
if (!saved) {
String title = getString("ErrorDialogTitle");
String text = getString("TemplateSaveError");
JOptionPane.showMessageDialog(this, text, title,
JOptionPane.ERROR_MESSAGE);
}
// Save file chooser "Favorite Directories". It is
// important to check that the chooser exists here, as
// if it doesn't, there's no need to do this! If we
// don't, the saveFileChooseFavorites() method will
// create the file chooser itself just to save the
// favorites!
if (chooser!=null) {
RTextUtilities.saveFileChooserFavorites(this);
}
System.exit(0);
}
// If there will still be some RText instances running, just
// stop this instance.
else {
setVisible(false);
StoreKeeper.removeRTextInstance(this);
this.dispose();
}
}
}
/**
* Focuses the specified dockable window group. Does nothing if there
* are no dockable windows at the location specified.
*
* @param group The dockable window group to focus.
*/
public void focusDockableWindowGroup(int group) {
DockableWindowPanel dwp = (DockableWindowPanel)mainContentPanel;
if (!dwp.focusDockableWindowGroup(group)) { // Should never happen
UIManager.getLookAndFeel().provideErrorFeedback(this);
}
}
/**
* Returns the filename used for newly created, empty text files. This
* value is locale-specific.
*
* @return The new text file name.
*/
public String getNewFileName() {
return newFileName;
}
@Override
public OptionsDialog getOptionsDialog() {
int pluginCount = getPlugins().length;
// Check plugin count and re-create dialog if it has changed. This
// is because the user can be quick and open the Options dialog before
// all plugins have loaded. A real solution is to have some sort of
// options manager that plugins can add options panels to.
if (optionsDialog==null || pluginCount!=lastPluginCount) {
lastPluginCount = pluginCount;
optionsDialog = new org.fife.rtext.optionsdialog.
OptionsDialog(this);
}
return optionsDialog;
}
/**
* Returns the application's "collapsible section panel;" that is, the
* panel containing the main view and possible find/replace tool bars.
*
* @return The collapsible section panel.
* @see #getMainView()
*/
CollapsibleSectionPanel getCollapsibleSectionPanel() {
return csp;
}
/**
* Returns the file chooser being used by this RText instance.
*
* @return The file chooser.
* @see #getRemoteFileChooser()
*/
@Override
public RTextFileChooser getFileChooser() {
if (chooser==null) {
chooser = RTextUtilities.createFileChooser(this);
}
return chooser;
}
/**
* Returns the focused dockable window group.
*
* @return The focused window group, or <code>-1</code> if no dockable
* window group is focused.
* @see DockableWindowConstants
*/
public int getFocusedDockableWindowGroup() {
DockableWindowPanel dwp = (DockableWindowPanel)mainContentPanel;
return dwp.getFocusedDockableWindowGroup();
}
/**
* Returns the Help dialog for RText.
*
* @return The Help dialog.
*/
@Override
public HelpDialog getHelpDialog() {
// Create the help dialog if it hasn't already been.
if (helpDialog==null) {
String contentsPath = getInstallLocation() + "/doc/";
String helpPath = contentsPath + getLanguage() + "/";
// If localized help does not exist, default to English.
File test = new File(helpPath);
if (!test.isDirectory())
helpPath = contentsPath + "en/";
helpDialog = new HelpDialog(this,
contentsPath + "HelpDialogContents.xml",
helpPath);
helpDialog.setBackButtonIcon(getIconGroup().getIcon("back"));
helpDialog.setForwardButtonIcon(getIconGroup().getIcon("forward"));
}
helpDialog.setLocationRelativeTo(this);
return helpDialog;
}
/**
* Returns the name of the local host. This is lazily discovered.
*
* @return The name of the local host.
*/
private synchronized String getHostName() {
if (hostName==null) {
try {
hostName = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException uhe) { // Should never happen
hostName = "Unknown";
}
}
return hostName;
}
/**
* Returns the actual main view.
*
* @return The main view.
* @see #getMainViewStyle()
* @see #setMainViewStyle(int)
*/
public AbstractMainView getMainView() {
return mainView;
}
/**
* Returns the main view style.
*
* @return The main view style, one of {@link #TABBED_VIEW},
* {@link #SPLIT_PANE_VIEW} or {@link #MDI_VIEW}.
* @see #setMainViewStyle(int)
* @see #getMainView()
*/
public int getMainViewStyle() {
return mainViewStyle;
}
/**
* Returns the list of most recently opened files, least-recently opened
* first.
*
* @return The list of files. This may be empty but will never be
* <code>null</code>.
*/
java.util.List<FileLocation> getRecentFiles() {
return recentFileManager.getRecentFiles();
}
/**
* Returns the file chooser used to select remote files.
*
* @return The file chooser.
* @see #getFileChooser()
*/
public RemoteFileChooser getRemoteFileChooser() {
if (rfc==null) {
rfc = new RemoteFileChooser(this);
}
return rfc;
}
/**
* Returns the fully-qualified class name of the resource bundle for this
* application. This is used by {@link #getResourceBundle()} to locate
* the class.
*
* @return The fully-qualified class name of the resource bundle.
* @see #getResourceBundle()
*/
@Override
public String getResourceBundleClassName() {
return "org.fife.rtext.RText";
}
/**
* Returns the opacity with which to render unfocused child windows, if
* this option is enabled.
*
* @return The opacity.
* @see #setSearchWindowOpacity(float)
*/
public float getSearchWindowOpacity() {
return searchWindowOpacity;
}
/**
* Returns the rule used for making certain child windows translucent.
*
* @return The rule.
* @see #setSearchWindowOpacityRule(int)
* @see #getSearchWindowOpacity()
*/
public int getSearchWindowOpacityRule() {
return searchWindowOpacityRule;
}
/**
* Returns the file in which to load and save user-customized keyboard
* shortcuts.
*
* @return The shortcuts file.
*/
private static File getShortcutsFile() {
return new File(RTextUtilities.getPreferencesDirectory(),
"shortcuts.properties");
}
/**
* Returns whether the hostname should be shown in the title of the
* main RText window.
*
* @return Whether the hostname should be shown.
* @see #setShowHostName(boolean)
*/
public boolean getShowHostName() {
return showHostName;
}
/**
* Returns the syntax highlighting color scheme being used.
*
* @return The syntax highlighting color scheme.
* @see #setSyntaxScheme(SyntaxScheme)
*/
public SyntaxScheme getSyntaxScheme() {
return colorScheme;
}
/**
* Returns the tab size (in spaces) currently being used.
*
* @return The tab size (in spaces) currently being used.
* @see #setTabSize(int)
*/
private int getTabSize() {
return mainView.getTabSize();
}
/**
* Returns the title of this window, less any "header" information
* (e.g. without the leading "<code>rtext - </code>").
*
* @return The title of this window.
* @see #setTitle(String)
*/
@Override
public String getTitle() {
String title = super.getTitle();
int hyphen = title.indexOf("- ");
if (hyphen>-1) { // Should always be true
title = title.substring(hyphen+2);
}
return title;
}
/**
* Returns the version string for this application.
*
* @return The version string.
*/
@Override
public String getVersionString() {
return VERSION_STRING;
}
/**
* Returns the "working directory;" that is, the directory that new, empty
* files are created in.
*
* @return The working directory. There will be no trailing '/' or '\'.
* @see #setWorkingDirectory
*/
public String getWorkingDirectory() {
return workingDirectory;
}
/**
* Does the dirty work of actually installing a plugin. This method
* ensures the current text area retains focus even after a GUI plugin
* is added.
*
* @param plugin The plugin to install.
*/
@Override
protected void handleInstallPlugin(Plugin plugin) {
// Normally we don't have to check currentTextArea for null, but in
// this case, we do. Plugins are installed at startup, after the main
// window is displayed. If the user passes in a filename to open, but
// that file doesn't exist, RText will prompt with "File XXX does not
// exist, create it?", and in that time, currentTextArea will be null.
// Plugins, in the meantime, will try to load and find the null value.
RTextEditorPane textArea = getMainView().getCurrentTextArea();
if (textArea!=null) {
textArea.requestFocusInWindow();
}
}
/**
* Returns whether dockable windows are at the specified location.
*
* @param group A constant from {@link DockableWindowConstants}
* @return Whether dockable windows are at the specified location.
*/
public boolean hasDockableWindowGroup(int group) {
DockableWindowPanel dwp = (DockableWindowPanel)mainContentPanel;
return dwp.hasDockableWindowGroup(group);
}
/**
* Called at the end of RText constructors. Does common initialization
* for RText.
*
* @param filesToOpen Any files to open. This can be <code>null</code>.
*/
private void init(String[] filesToOpen) {
lastPluginCount = -1;
openFiles(filesToOpen);
}
/**
* Initializes the "recent files" manager.
*
* @param prefs The preferences for the application.
*/
private void initRecentFileManager(RTextPrefs prefs) {
String fileHistoryStr = prefs.fileHistoryString;
java.util.List<String> recentFiles = new ArrayList<>();
if (fileHistoryStr != null && fileHistoryStr.length() > 0) {
String[] initialContents = fileHistoryStr.split("<");
recentFiles.addAll(Arrays.asList(initialContents));
}
recentFileManager = new RecentFileManager(this, recentFiles);
}
/**
* Installs all properties in an RSTA <code>Theme</code> instance properly.
*
* @param theme The theme instance.
*/
private void installRstaTheme(Theme theme) {
if (mainView != null) {
mainView.setRstaTheme(theme);
}
setSyntaxScheme(theme.scheme);
}
/**
* Returns whether search window opacity is enabled.
*
* @return Whether search window opacity is enabled.
* @see #setSearchWindowOpacityEnabled(boolean)
*/
public boolean isSearchWindowOpacityEnabled() {
return searchWindowOpacityEnabled;
}
/**
* Returns whether the spelling window is visible.
*
* @return Whether the spelling window is visible.
* @see #setSpellingWindowVisible(boolean)
*/
public boolean isSpellingWindowVisible() {
return spellingWindow!=null && spellingWindow.isActive();
}
/**
* Loads and validates the icon groups available to RText.
*/
private void loadPossibleIconGroups() {
iconGroupMap = new HashMap<>();
String resourceRoot = "org/fife/rtext/graphics/";
IconGroup darkIconGroup = new SvgIconGroup(this, DEFAULT_ICON_GROUP_NAME,
resourceRoot + "intellij-icons-dark",
resourceRoot + "intellij-icons-light"); // Proper contrast
iconGroupMap.put(DEFAULT_ICON_GROUP_NAME, darkIconGroup);
SvgIconGroup lightIconGroup = new SvgIconGroup(this, "IntelliJ Icons (Light)",
resourceRoot + "intellij-icons-light",
null);
lightIconGroup.setRolloverPath(resourceRoot + "intellij-icons-white");
iconGroupMap.put("IntelliJ Icons (Light)", lightIconGroup);
iconGroupMap.put("Eclipse Icons", new RasterImageIconGroup("Eclipse Icons",
resourceRoot + "eclipse-icons",
null));
}
/**
* Opens the specified files.
*
* @param filesToOpen The files to open. This can be <code>null</code>.
* @see #openFile
*/
private void openFiles(String[] filesToOpen) {
int count = filesToOpen==null ? 0 : filesToOpen.length;
for (int i=0; i<count; i++) {
openFile(new File(filesToOpen[i]));
}
}
@Override
protected void possiblyInitializeMacOSProperties(AppContext<? extends AbstractGUIApplication<RTextPrefs>, RTextPrefs> context,
RTextPrefs prefs) {
MacOSUtil.setTransparentTitleBar(this, true);
MacOSUtil.setFullWindowContent(this, true);
}
@Override
protected void preDisplayInit(RTextPrefs prefs, SplashScreen splashScreen) {
long start = System.currentTimeMillis();
// Some stuff down the line may assume this directory exists!
File prefsDir = RTextUtilities.getPreferencesDirectory();
if (!prefsDir.isDirectory()) {
prefsDir.mkdirs();
}
// Install any plugins.
super.preDisplayInit(prefs, splashScreen);
splashScreen.updateStatus(getString("AddingFinalTouches"), 90);
// If the user clicks the "X" in the top-right of the window, do nothing.
// (We'll clean up in our window listener).
addWindowListener(new RTextWindowListener(this));
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
// Enable templates in text areas.
if (RTextUtilities.enableTemplates(this, true)) {
// If there are no templates, assume this is the user's first
// time in RText and add some "standard" templates.
CodeTemplateManager ctm = RTextEditorPane.getCodeTemplateManager();
if (ctm.getTemplates().length==0) {
RTextUtilities.addDefaultCodeTemplates();
}
}
setSearchWindowOpacityEnabled(prefs.searchWindowOpacityEnabled);
setSearchWindowOpacity(prefs.searchWindowOpacity);
setSearchWindowOpacityRule(prefs.searchWindowOpacityRule);
RTextUtilities.setDropShadowsEnabledInEditor(prefs.dropShadowsInEditor);
setWindowDraggableByMenuBarAndToolBar();
SwingUtilities.invokeLater(this::updateTextAreaIcons);
if (Boolean.getBoolean(PROPERTY_PRINT_START_TIMES)) {
System.err.println("preDisplayInit: " + (System.currentTimeMillis()-start));
}
}
@Override
protected void preMenuBarInit(RTextPrefs prefs, SplashScreen splashScreen) {
long start = System.currentTimeMillis();
initRecentFileManager(prefs);
// Make the split pane positions same as last time.
setSplitPaneDividerLocation(DockableWindowConstants.TOP,
prefs.dividerLocations[DockableWindowConstants.TOP],
prefs.dividerVisible[DockableWindowConstants.TOP]);
setSplitPaneDividerLocation(DockableWindowConstants.LEFT,
prefs.dividerLocations[DockableWindowConstants.LEFT],
prefs.dividerVisible[DockableWindowConstants.LEFT]);
setSplitPaneDividerLocation(DockableWindowConstants.BOTTOM,
prefs.dividerLocations[DockableWindowConstants.BOTTOM],
prefs.dividerVisible[DockableWindowConstants.BOTTOM]);
setSplitPaneDividerLocation(DockableWindowConstants.RIGHT,
prefs.dividerLocations[DockableWindowConstants.RIGHT],
prefs.dividerVisible[DockableWindowConstants.RIGHT]);
// Show any docked windows
setSpellingWindowVisible(prefs.viewSpellingList);
setShowHostName(prefs.showHostName);
mainView.setLineNumbersEnabled(prefs.lineNumbersVisible);
setToolBarVisible(prefs.toolbarVisible);
setStatusBarVisible(prefs.statusBarVisible);
if (Boolean.getBoolean(PROPERTY_PRINT_START_TIMES)) {
System.err.println("preMenuBarInit: " + (System.currentTimeMillis()-start));
}
}
@Override
protected void preStatusBarInit(RTextPrefs prefs,
SplashScreen splashScreen) {
long start = System.currentTimeMillis();