Skip to content
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

Integrate NB Favorites with the FileChooser shortcuts panel #7164

Merged
merged 3 commits into from
Apr 4, 2024

Conversation

mbien
Copy link
Member

@mbien mbien commented Mar 16, 2024

Link the Favorites view with FlatLaf's FileChooser shortcuts panel.

  • the first commit is code cleanup
  • second commit contains minor updates to the path completion functionality (who knew that the NB directory chooser had auto completion?)
  • third commit is the main change which provides the favorites shortcuts list

screenshots:
JDK's FileChooser with favorites:
favs-in-file-chooser

NB's custom DirectoryChooser displaying lots of favorites in a JScrollPane.
favs-in-file-chooser_scroll

can be enabled via FlatLaf options (last checkbox):
image

@mbien mbien added Look and Feel UI User Interface ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Mar 16, 2024
Comment on lines 306 to 315
if (useNBShortcutsPanel()) {
FlatShortcutsPanel shortcuts = new FlatShortcutsPanel(fileChooser);
JScrollPane sp = new JScrollPane(shortcuts, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
sp.setPreferredSize(new Dimension(100, 300));
return sp;
}
Copy link
Member Author

@mbien mbien Mar 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DevCharly do you think it would make sense for FlatLaf to wrap the FlatShortcutsPanel in a JScrollPane like here? (see second screenshot)

NB uses two file choosers, one is customized (DirectoryChooserUI) and used for opening projects etc, the other one is the standard JDK file chooser. Now when the shortcuts panel has lots of items the standard JDK file chooser will get very tall.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@neilcsmith-net neilcsmith-net left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! But I'd like to see it done without additional dependencies or look-and-feel specific checks being added. UIManager keys should be the way to centralise this in my opinion.

ide/o.n.swing.dirchooser/nbproject/project.xml Outdated Show resolved Hide resolved
}
return list.toArray(File[]::new);
};
UIManager.put("FileChooser.shortcuts.filesFunction", fun);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adopt this as a provided NetBeans key and provide from the Favorites module directly?

Could also consider if Favorites should prepopulate favorites from the shell folders on Windows, and then allow all OS to use Favorites to customise links in file chooser panels for consistency?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is a NetBeans Key?

Copy link
Member

@neilcsmith-net neilcsmith-net Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just meant a UI key that's added and documented in https://github.com/apache/netbeans/blob/master/platform/o.n.swing.plaf/src/org/netbeans/swing/plaf/LFCustoms.java Although it would be kind of operating in reverse to most UI keys, in the sense that it's set outside and read by the LAF.

Copy link
Member Author

@mbien mbien Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also consider if Favorites should prepopulate favorites from the shell folders on Windows, and then allow all OS to use Favorites to customise links in file chooser panels for consistency?

the way it works right now on windows is that the NB favorites are appended to the windows specific shortcuts:
image

the win ShellFolder reflection code is essentially not needed in dir file folder if FlatLaf is used since the shortcuts panel is doing this already. actually: I believe this isn't quite correct, some of the code is probably still active.

@mbien mbien force-pushed the filechooser-shortcuts-panel branch 2 times, most recently from d9e8dff to 99e6f7a Compare March 24, 2024 23:14
@mbien
Copy link
Member Author

mbien commented Mar 24, 2024

this can be now enabled via FlatLaf options (no restart required), see added screenshot

@mbien mbien force-pushed the filechooser-shortcuts-panel branch from 99e6f7a to 71d4d2a Compare March 25, 2024 12:46
@mbien mbien marked this pull request as ready for review March 25, 2024 12:46
@mbien mbien added this to the NB22 milestone Mar 25, 2024
@mbien mbien added the Platform [ci] enable platform tests (platform/*) label Mar 25, 2024
@apache apache locked and limited conversation to collaborators Mar 25, 2024
@apache apache unlocked this conversation Mar 25, 2024
@mbien mbien force-pushed the filechooser-shortcuts-panel branch from 71d4d2a to 80d65f9 Compare March 25, 2024 15:12
@mbien
Copy link
Member Author

mbien commented Apr 2, 2024

appended (experimental) to the checkbox text and rebased PR to latest of master
image

Copy link
Member

@neilcsmith-net neilcsmith-net left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me. I guess you could remove the dependency changes entirely by using String literals, but pros and cons to that.

Comment on lines +440 to +445
/**
* FileChooser
*/
public static final String FILECHOOSER_SHORTCUTS_FILESFUNCTION = "FileChooser.shortcuts.filesFunction";
public static final String FILECHOOSER_SHORTCUTS_PANEL_FACTORY = "FileChooser.shortcuts.panel.factory";
public static final String FILECHOOSER_FAVORITES_ENABLED = "FileChooser.favorites.enabled";
Copy link
Member Author

@mbien mbien Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neilcsmith-net btw the _FILESFUNCTION key value (FileChooser.shortcuts.filesFunction) is taken right from FlatLaf. Not sure if this is elegant or a horrible idea. I just thought that mapping one key to another would create more problems than its worth the trouble since it can get out of sync easily.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I knew that when I suggested adopting it. Don't see a reason to use something different and have the problems of syncing. Whether it's elegant or horrible ... 🤷

 - added ctrl+space to the trigger list
 - increased popup size from 4 to 6 lines
 - filter out hidden files
 - file chooser shortcuts panel can optionally append the tree roots
   of the favorites view
 - can be toggled in the FlatLaf options

This requires to open com.formdev.flatlaf.ui as friend dependency,
which is as mentioned in project.properties not part of the stable API.
@mbien mbien removed the ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) label Apr 4, 2024
@mbien mbien force-pushed the filechooser-shortcuts-panel branch from 10b3c5b to ce3cca2 Compare April 4, 2024 15:29
@mbien
Copy link
Member Author

mbien commented Apr 4, 2024

fixed a typo, going to merge once green again. Thanks for reviewing.

@mbien mbien merged commit 18f73f7 into apache:master Apr 4, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Look and Feel Platform [ci] enable platform tests (platform/*) UI User Interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants