8000 GUI improvements by tferr · Pull Request #56 · scijava/script-editor · GitHub
[go: up one dir, main page]

Skip to content

GUI improvements #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Feb 24, 2022
Merged

GUI improvements #56

merged 21 commits into from
Feb 24, 2022

Conversation

tferr
Copy link
Collaborator
@tferr tferr commented Feb 24, 2022

I've been using the editor these days quite a lot. One thing that use to bonkers me all the time was the fact that font sizes were never consistently stored across restarts (e.g., the console would always have 12pt at startup). With a hiDPI screen, I was always changing the fonts. So, I decided to finally cleanup all the hardwired values...

At a certain point, it became obvious that we are not using RSyntaxArea to its full potential. One thing led to the other, and I ended up doing way more than what I had expected. Here is a summary:

  • EditorPane:

    • Themes (!!), including a dark option
    • Tweaks using RSyntaxTextArea's built-in options to recap the behavior of most IDEs: Highlight occurrences of selected text; code folding with 'peek' pop-up view over folded code, etc. Some of these are toggleable in the GUI
    • Reinstated bookmarks (were broken for many years): This allows to mark lines by clicking on the left gutter as in most IDEs
  • Autocompletion:

    • There are now two fallbacks to handle unsupported languages:
      1. If no SciJava support exits, the editor will try to load support from RSyntaxTextArea's LanguageSupportFactory. Currently there is really nothing useful there for us, but the project remains quite active, so this could change in the future (e.g., newer v3.1.6 supports Markdown and Kotlin)
      2. If that did not work, there is now an option for using Java as 'fallback': This tells the EditorPane to use Java as last resort. As you can imagine, this is a bit silly to say the least: it is pretty useless beyond static access to java.lang classes, but at least is something more than nothing
    • When a language is chosen in the menu, the console displays the status and current settings of the auto-completion
    • Option for 'Auto-activation' (no need for Ctrl+Space), as per Improve visibility of auto-completion shortcut script-editor-jython#8:
      • @haesleinhuepf: RSyntaxArea supported this all along: Please test the new option: If it works well for you, I would suggest you disable your implementation. The preference is persistent and is on by default for backwards compatibility. (Those of us who dislike, we'll have to disable it and run 'Save Preferences', doing other-wise would break the status quo for IJ Macros)
  • Other Improvements/Tweaks:

    • Opening of files by Drag & Drop: Dropping folders into the File Tree pane adds them there. Dropping files into the editor pane, opens them. For responsiveness, a confirmation prompt is shown when a large no. of files is involved
    • Options to toggle File Tree Pane, and Console
    • FileTree: Options for case-sensitive searches. Options to Expand/Collapse/Reveal in OS, etc. (contextual menu). Added a built-in help dialog with regex examples.
      • @cardona: there are two deviations from your implementation: Filter is case-insensitive by default, and the '/' trigger for Regex is now a checkbox, for consistency with the other options. Agree?
    • More consistent settings across restarts: Previous some preferences were not being stored or were being overwritten by hardwired values at startup
    • Filename tabs: Can be moved to any side of the window, and are navigable using scroll-w 10000 heel
    • Organized menus. Find and Replace are now aggregated into a single menu entry.
    • The new Help menu includes links to online resources
    • Line numbers in gutter are always scaled proportionally

@ctrueden I felt easier to add this class that implements the File Drag&Drop. it is in the public domain. It works quite well (SNT uses it a lot). Would be super useful to add it to all the scijava Swing-based components that handle files (e.g., file prompts)

@imagejan, @ctrueden, @haesleinhuepf, @acardona: Unfortunately, I won't have time to do much more. Would be great if you guys could test things on your end. The Editor is getting better and better all the time!!

I am attaching a binary here, in case it helps (note the dummy .zip extension appended to fool the uploader).
script-editor-0.6.2-SNAPSHOT.jar.zip

Also, here are some snapshots:

image

image

image

@imagesc-bot
Copy link

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/would-someone-make-a-dark-script-editor/51870/6

@ctrueden
Copy link
Member
ctrueden commented Feb 24, 2022

@tferr Awesome! Once you are ready, I'll squash and merge this, to purge the WIPs from the history. Or if you feel strongly about keeping the history, I could squash only those commits that fail to build with passing tests. What do you think? I don't want to lose the whole history of this PR—it's too nice. So I'm doing a check-branch (from scijava-scripts) to figure out which commits are broken.

Also: I fixed the repeated output of the same language's support status.

tferr and others added 21 commits February 24, 2022 14:12
- Improve Consistency of Title Case
- Add titled separators to larger menus
- errorScreen: Adopt pane font size, not hardwired value
- Bookmarks: Info message when list is empty
- Disable 'clear' menu entry, redundant with JButton of 'errorScreen'
- Contextual Menu: (Collapse, Expand, Reveal Selection in OS, Reset)
- Add button: prompt remembers last folder and accepts drag & drop
- Drag & drop support from the OS' File Explorer
- Fix hardwired colors for compatibility with dark L&F
- Minor Improvements to dialogs
- Do not collapse nodes when reloading
- File filtering:
   - Help message in tooltip
   - Case insensitive by default
   - Clearing field  resets tree
This simplifies things quite a bit.
While at it, add options for Regex, Cases sensitive, built-in help, etc.
- Controls for tab placement
- Opening files via drag & drop
- Navigate tabs using scrollwheel
- Fix drag & drop related exception

Plus minor code cleanup of FileSystemTreePanel.

Signed-off-by: Curtis Rueden <ctrueden@wisc.edu>
- Edit>
  - Organize by categories
  - Moved entries to Options> menu
- Window>
  - Toggles for panels
  - Tab navigation (previous Tabs> menu)
- Options>
  - Use titled dividers
  - Indention controls
  - Themes!!
  - Autocompletion controls
  - Prefs. controls
- Help>
  - List of developer resources
Especially 'contextual help' menu entries.

Signed-off-by: Curtis Rueden <ctrueden@wisc.edu>
While at it, ensure Menu choices updates on theme change
- Move FileSystemTree tweaks to FileSystemTreePanel
- Ensure Filtering field is large enough to display placeholders
- Add explicit error messages to buttons
- Cleanup API
- Misc
- GUI Tweaks:
   - Improve dialogs, capitalization, tooltips, etc.
   - Organize options menu & disable non-applicable options as needed
   - Use Find/Replace (as opposed to segregated commands)
   - Correct changeListener -> ItemListener
 - Minor code/API cleanup
Lots of new things now.
@ctrueden ctrueden merged commit 0308ae2 into master Feb 24, 2022
@ctrueden ctrueden deleted the gui-improvements branch February 24, 2022 20:15
@ctrueden
Copy link
Member
ctrueden commented Feb 24, 2022

Rebased and merged. All final commits compile with passing tests. If there are any lingering issues, we can address them with followup commits/PRs.

@acardona
Copy link
Collaborator

Hi @tferr looks great, thanks so much!

On the toggle for autocompletions with control+space vs without: when opening the Script Editor, the checkbox is ticked but one has to use control+space to activate autocompletions. So either it's initialized wrong or the logic is the other way. Also, I can't seem to get it to work without control+space for jython.

By the way: I added method and constructor parameterized autocompletion for jython https://github.com/scijava/script-editor-jython/commits/main -- we should release both repos.

@acardona
Copy link
Collaborator

The themes: seem to only apply to the script textarea? The output and error textareas and the file tree don't change, in Ubuntu 20.04 with java 8.

@acardona
Copy link
Collaborator
acardona commented Feb 25, 2022

The little arrows that enabled the left and right panels to be collapsed seem to have disappeared. Yes, I see under the "Window" menu new menu items to collapse/show them. But was it necessary to remove the arrows? I like that they are visually explicit, and use them all the time.

@acardona
Copy link
Collaborator

When opening a new tab, the theme isn't the same as the last active tab. It's actually the default theme. That should change, similar to how the new tab inherits the language of the previously active one.

@acardona
Copy link
Collaborator

The Options menu item for "Mark occurrences" doesn't seem to do anything: upon text search, occurrences are marked regardless of the checkbox status.

@tferr
Copy link
Collaborator Author
tferr commented Feb 25, 2022

@acardona,

I added method and constructor parameterized autocompletion for jython

Wow. Great!

The Options menu item for "Mark occurrences" doesn't seem to do anything:

Grrrr, I can confirm this. The same seems to apply to the "indent guides" (that shoudl display a vertical line of sorts at each tab location). Weird because those checkboxes just waive the option to the RSyntaxArea. Will look

I can't seem to get it to work without control+space for jython.

I will check the logic. But again, we are just waiving the option to the LanguageSupport here:

support.setAutoCompleteEnabled(autoCompletionEnabled);
support.setAutoActivationEnabled(autoCompletionWithoutKey);
support.setAutoActivationDelay(200);

I have no explanation as per why is not working. Maybe the 200ms delay is the problem? Meanwhile, let me know if you have insights

When opening a new tab, the theme isn't the same as the last active tab.

Oops. Good point. Will look.

The little arrows that enabled the left and right panels to be collapsed seem to have disappeared. Yes, I see under the "Window" menu new menu items to collapse/show them. But was it necessary to remove the arrows?
I forgot to bring that up. I saw that you had JSplitPane#setOneTouchExpandable() calls, so I imaged you were using it. I left a comment here:

The reason was twofold: 1) those arrows are only present on certain L&F (i think metal does not have them), so I thought the menu would bring collapsible panes to more people, and 2) I just could not get the checkboxes in the Window> menu to become aware of their state. I did try, but I ran out of time and gave up. Basically, if you toggle those arrows, then the checkboxes in the menu become auto-of-sync, and I came across funky states, where I had to reset the preferences to have the panes back. I left a comment here:

// TF: disable setOneTouchExpandable() due to inconsistent behavior when
// applying preferences at startup. Also, it does not apply to all L&Fs.
// Users can use the controls in the menu bar to toggle the pane
body.setOneTouchExpandable(false);

An easy fix would be to bring the arrows back, and add a "Reset Layout" menu item that restores all panes, so that folks can use in case of 'out-of-sync-panic'.

The themes: seem to only apply to the script textarea?

That is correct. Outside the EditorPane the theme is set by the LookAndFeel. I am also on Ubuntu and when the system-wide (Gnome) theme is set to "dark" (the default for me!?) GTK+ also adapts a dark theme. The snapshots I sent were using FlatLaf. It has been a lifesaver for me, not because of aesthetics (but it does look great!), but because they have been plowing through a bunch of limitations of Swing, namely proper support for hiDPI screens. One can say they brought Swing back from the dead. Without it, nothing ever scales properly on linux (at least with Java8). Also, they keep improving it, and patching all sorts of old bugs: E.g., I used to get a segfault(!!) when dragging certain dialogs/frames across screens: It is an old bug that won't be fixed, but they have a workaround for it!
Update: I proposed using FlatLaf as an option in Fiji here: scijava/scijava-ui-swing#61

@acardona
Copy link
Collaborator

I added method and constructor parameterized autocompletion for jython

Wow. Great!

Was needed, wasn't it. This makes exploring the java libraries much easier. I even added an attempt at guessing which existing variable names are suitable for each constructor or method argument, based on their type when the latter can be inferred.

By the way, won't compile without latest commit to script-editor, in other words, you have to adjust the pom.xml of script-editor-jython to use the 0.6.2-SNAPSHOT of script-editor.

@tferr
Copy link
Collaborator Author
tferr commented Feb 25, 2022

Quick update on the keyless auto-completion: It seems to be working indeed, just i 6855 n an awkward way:

  1. Enable it and set the language to Java (it is one of the languages supported by RSyntaxTextArea directly)
  2. Type import java. and wait. You should get the auto-completion dialog

It seems that the behavior of what triggers it is defined here, i.e., by all the classes that extend DefaultCompletionProvider:

https://github.com/bobbylight/AutoComplete/blob/acf52c8eb29e484956f8fe17cdaa6d0c39445218/AutoComplete/src/main/java/org/fife/ui/autocomplete/CompletionProviderBase.java#L189

For Java, it seems that the default is just the '.', i.e., nothing else will trigger it. I suspect, the jython-autocompletion would have to adjust the rules to meet expectations. @haesleinhuepf, this would apply to your ij1 macro completions too.

won't compile without latest commit to script-editor,

I will try to look over the weekend

tferr added a commit that referenced this pull request Feb 27, 2022
tferr added a commit that referenced this pull request Feb 27, 2022
tferr added a commit that referenced this pull request Feb 27, 2022
The Mark All' occurrences feature is restricted to certain identifiers defined on individually for each language.
This makes it so, that in addition to whatever is being specified, it is also possible to double-click on any string
to highlight all occurrences. In addition, this adds an error strip to the right side of the text area, marking the positioning of lines associated with syntax errors and 'Mark all'/'Find all' occurrences.

Related to @acardona's report, #56 (comment)
@tferr
Copy link
Collaborator Author
tferr commented Feb 27, 2022

@acardona: just pushed a couple of fixes for the stuff you reported. The "Mark All" occurrences being language specific was bothering me, so I made it so that when you double-click on a string (any string), all of its occurrences get highlighted. Also, now there is an "Error strip" on the right side of the pane (like in Eclipse) that highlights all the lines with 1) errors and warnings, 2) "Find all" and 3) "Mark all" occurrences. It is kind of neat! I also made it so, if there is a URL, ctrl-clicking on it, will open it in the browser.

The "Indent tab lines' works, but it only marks leading white space and the detection of such is also language-specific, so it may not do much by default.

Updated: I opened a couple of PRs on the jython side:
scijava/script-editor-jython#12: Should reinstate compilation
scijava/script-editor-jython#13: Should make keyless auto-completion functional in jython

@acardona
Copy link
Collaborator
acardona commented Mar 1, 2022

Question on hyperlinks: I see them become underlined in java documentation (/** .... */ style), but not in e.g., python (""" .... """ style). In the code, the implementation seems language neutral, meaning, this is likely delegated to the language support classes? Any hints here on how to enable it for languages other than java?

The line in question:
src/main/java/org/scijava/ui/swing/script/EditorPane.java: setHyperlinksEnabled(true);

@tferr
Copy link
Collaborator Author
tferr commented Mar 1, 2022

RSyntaxTextArea is quite awkward in the sense that even 'global' TextArea options become language specific when a language is set. I can try to look

@tferr
Copy link
Collaborator Author
tferr commented Mar 2, 2022

The MouseListener in RSyntaxTextArea triggers HyperlinkListener related code when Token#isHyperLink() is true, like here

Token#isHyperLink() is only true in comments. The logic works with clojure (;;) and all the "//" languages, but not with Python or Ruby (#), so it must be something related to "#" languages.
I wanted to see if that still existed with newer version fo RSyntaxTextArea (before reporting the bug there), but ran out of time.
Either way, I added a "Open URL at Cursor" entry to the popup menu: It uses regex to extract the first URL from the cursor line and will try to open that instead. Kludge, but at least is something...

@tferr
Copy link
Collaborator Author
tferr commented Mar 2, 2022

BTW, I just noticed that auto-completions also propose useful stuff in Java when called from a comment. Neat idea.

image

@imagesc-bot
Copy link

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/shiny-new-script-editor/64160/38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0