scijava / script-editor

Script Editor and Interpreter for SciJava script languages
http://imagej.net/Script_Editor
BSD 2-Clause "Simplified" License
12 stars 12 forks source link

GUI improvements #56

Closed tferr closed 2 years ago

tferr commented 2 years ago

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:

@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 commented 2 years ago

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 commented 2 years ago

@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.

ctrueden commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@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: https://github.com/scijava/script-editor/blob/7c55b2dfd681bf49cc4ce14daeaeeb6218234b8c/src/main/java/org/scijava/ui/swing/script/EditorPane.java#L569-L571 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: https://github.com/scijava/script-editor/blob/7c55b2dfd681bf49cc4ce14daeaeeb6218234b8c/src/main/java/org/scijava/ui/swing/script/TextEditor.java#L640-L643

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: https://github.com/scijava/scijava-ui-swing/issues/61

acardona commented 2 years ago

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 commented 2 years ago

Quick update on the keyless auto-completion: It seems to be working indeed, just in 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 commented 2 years ago

@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: https://github.com/scijava/script-editor-jython/pull/12: Should reinstate compilation https://github.com/scijava/script-editor-jython/pull/13: Should make keyless auto-completion functional in jython

acardona commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

image

imagesc-bot commented 2 years ago

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