10000 Add option for 'Margin line' + fixes for persistent preferences · scijava/script-editor@9ff2358 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ff2358

Browse files
committed
Add option for 'Margin line' + fixes for persistent preferences
While at it: - improve a bit the startup states of Window-> Pane commands - Organize better Options menu and tweak tooltip messages
1 parent d8cf0af commit 9ff2358

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/main/java/org/scijava/ui/swing/script/EditorPane.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ public void convertSpacesToTabs() {
893893
public static final String TABS_EMULATED_PREFS = "script.editor.TabsEmulated";
894894
public static final String WHITESPACE_VISIBLE_PREFS = "script.editor.Whitespace";
895895
public static final String TABLINES_VISIBLE_PREFS = "script.editor.Tablines";
896+
public static final String MARGIN_VISIBLE_PREFS = "script.editor.Margin";
896897
public static final String THEME_PREFS = "script.editor.theme";
897898
public static final String AUTOCOMPLETE_PREFS = "script.editor.AC";
898899
public static final String AUTOCOMPLETE_KEYLESS_PREFS = "script.editor.ACNoKey";
@@ -927,6 +928,7 @@ public void loadPreferences() {
927928
setKeylessAutoCompletion(prefService.getBoolean(getClass(), AUTOCOMPLETE_KEYLESS_PREFS, true)); // true for backwards compatibility with IJ1 macro
928929
setFallbackAutoCompletion(prefService.getBoolean(getClass(), AUTOCOMPLETE_FALLBACK_PREFS, false));
929930
setMarkOccurrences(prefService.getBoolean(getClass(), MARK_OCCURRENCES_PREFS, false));
931+
setMarginLineEnabled(prefService.getBoolean(getClass(), MARGIN_VISIBLE_PREFS, false));
930932
applyTheme(themeName());
931933
}
932934
}
@@ -988,6 +990,8 @@ public void savePreferences(final String top_folders, final String theme) {
988990
prefService.put(getClass(), AUTOCOMPLETE_PREFS, isAutoCompletionEnabled());
989991
prefService.put(getClass(), AUTOCOMPLETE_KEYLESS_PREFS, isAutoCompletionKeyless());
990992
prefService.put(getClass(), AUTOCOMPLETE_FALLBACK_PREFS, isAutoCompletionFallbackEnabled());
993+
prefService.put(getClass(), MARGIN_VISIBLE_PREFS, isMarginLineEnabled());
994+
prefService.put(getClass(), MARK_OCCURRENCES_PREFS, getMarkOccurrences());
991995
if (null != top_folders) prefService.put(getClass(), FOLDERS_PREFS, top_folders);
992996
if (null != theme) prefService.put(getClass(), THEME_PREFS, theme);
993997
}

src/main/java/org/scijava/ui/swing/script/TextEditor.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public class TextEditor extends JFrame implements ActionListener,
231231
private FindAndReplaceDialog findDialog;
232232
private JCheckBoxMenuItem autoSave, wrapLines, tabsEmulated, autoImport,
233233
autocompletion, fallbackAutocompletion, keylessAutocompletion,
234-
markOccurences, paintTabs, whiteSpace;
234+
markOccurences, paintTabs, whiteSpace, marginLine;
235235
private ButtonGroup themeRadioGroup;
236236
private JTextArea errorScreen = new JTextArea();
237237

@@ -538,10 +538,15 @@ public TextEditor(final Context context) {
538538
tabsMenu = new JMenu("Window");
539539
tabsMenu.setMnemonic(KeyEvent.VK_W);
540540
addSeparator(tabsMenu, "Panes:");
541-
final JCheckBoxMenuItem jcmi1 = new JCheckBoxMenuItem("File Explorer", isLeftPaneExpanded(body));
541+
// Assume initial status from prefs or panel visibility
542+
final JCheckBoxMenuItem jcmi1 = new JCheckBoxMenuItem("File Explorer",
543+
prefService.getInt(getClass(), MAIN_DIV_LOCATION, body.getDividerLocation()) > 0
544+
|| isLeftPaneExpanded(body));
542545
jcmi1.addItemListener(e -> collapseSplitPane(0, !jcmi1.isSelected()));
543546
tabsMenu.add(jcmi1);
544-
final JCheckBoxMenuItem jcmi2 = new JCheckBoxMenuItem("Console", true); // Console not yet initialized
547+
// Console not initialized. Assume it is displayed if no prefs read
548+
final JCheckBoxMenuItem jcmi2 = new JCheckBoxMenuItem("Console",
549+
prefService.getInt(getClass(), TAB_DIV_LOCATION, 1) > 0);
545550
jcmi2.addItemListener(e -> collapseSplitPane(1, !jcmi2.isSelected()));
546551
tabsMenu.add(jcmi2);
547552
final JMenuItem mi = new JMenuItem("Reset Layout...");
@@ -640,9 +645,10 @@ public TextEditor(final Context context) {
640645
replaceTabsWithSpaces = addToMenu(options, "Replace Tabs With Spaces", 0, 0);
641646

642647
addSeparator(options, "View:");
643-
options.add(whiteSpace);
644-
options.add(paintTabs);
645648
options.add(markOccurences);
649+
options.add(paintTabs);
650+
options.add(marginLine);
651+
options.add(whiteSpace);
646652
options.add(wrapLines);
647653
options.add(applyThemeMenu());
648654

@@ -935,15 +941,18 @@ private void initializeDynamicMenuComponents() {
935941
// Options menu. These will be updated once EditorPane is created
936942
wrapLines = new JCheckBoxMenuItem("Wrap Lines", false);
937943
wrapLines.setMnemonic(KeyEvent.VK_W);
944+
marginLine = new JCheckBoxMenuItem("Show Margin Line", false);
945+
marginLine.setToolTipText("Displays right margin at column 80");
946+
marginLine.addItemListener(e -> setMarginLineEnabled(marginLine.getState()));
938947
wrapLines.addItemListener(e -> setWrapLines(wrapLines.getState()));
939948
markOccurences = new JCheckBoxMenuItem("Mark Occurences", false);
940-
markOccurences.setToolTipText("Highlights all occurrences of a double-clicked string or selected\n"
941-
+ "element. Hits are highlighted on the Editor's rightmost side");
949+
markOccurences.setToolTipText("Allows for all occurrences of a double-clicked string to be"
950+
+ " highlighted.\nLines with hits are marked on the Editor's notification strip");
942951
markOccurences.addItemListener(e -> setMarkOccurrences(markOccurences.getState()));
943952
whiteSpace = new JCheckBoxMenuItem("Show Whitespace", false);
944953
whiteSpace.addItemListener(e -> setWhiteSpaceVisible(whiteSpace.isSelected()));
945954
paintTabs = new JCheckBoxMenuItem("Show Indent Guides");
946-
paintTabs.setToolTipText("Show 'tab lines' for leading whitespace");
955+
paintTabs.setToolTipText("Displays 'tab lines' for leading whitespace");
947956
paintTabs.addItemListener(e -> setPaintTabLines(paintTabs.getState()));
948957
autocompletion = new JCheckBoxMenuItem("Enable Autocompletion", true);
949958
autocompletion.setToolTipText("Whether code completion should be used.\nNB: Not all languages support this feature");
@@ -1512,6 +1521,11 @@ private void setWrapLines(final boolean wrap) {
15121521
getEditorPane(i).setLineWrap(wrap);
15131522
}
15141523

1524+
private void setMarginLineEnabled(final boolean enabled) {
1525+
for (int i = 0; i < tabbed.getTabCount(); i++)
1526+
getEditorPane(i).setMarginLineEnabled(enabled);
1527+
}
1528+
15151529
private JMenu applyThemeMenu() {
15161530
final LinkedHashMap<String, String> map = new LinkedHashMap<>();
15171531
map.put("Default", "default");
@@ -1645,7 +1659,7 @@ public void stateChanged(final ChangeEvent e) {
16451659
editorPane.requestFocus();
16461660
checkForOutsideChanges();
16471661

1648-
whiteSpace.setSelected(editorPane.isWhitespaceVisible());
1662+
//whiteSpace.setSelected(editorPane.isWhitespaceVisible());
16491663

16501664
editorPane.setLanguageByFileName(editorPane.getFileName());
16511665
updateLanguageMenu(editorPane.getCurrentLanguage());
@@ -2154,10 +2168,12 @@ else if (tabSize == Integer.parseInt(item.getText())) {
21542168
}
21552169
markOccurences.setState(pane.getMarkOccurrences());
21562170
wrapLines.setState(pane.getLineWrap());
2171+
marginLine.setState(pane.isMarginLineEnabled());
21572172
tabsEmulated.setState(pane.getTabsEmulated());
21582173
paintTabs.setState(pane.getPaintTabLines());
21592174
whiteSpace.setState(pane.isWhitespaceVisible());
21602175
autocompletion.setState(pane.isAutoCompletionEnabled());
2176+
fallbackAutocompletion.setState(pane.isAutoCompletionFallbackEnabled());
21612177
keylessAutocompletion.setState(pane.isAutoCompletionKeyless());
21622178
}
21632179

0 commit comments

Comments
 (0)
0