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

Add FileWidget.FILE_AND_DIRECTORY_STYLE #480

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@
<url>https://imagej.net/people/jaywarrick</url>
<properties><id>jaywarrick</id></properties>
</contributor>
<contributor>
<name>Christian Tischer</name>
<url>https://imagej.net/people/tischi</url>
<properties><id>tischi</id></properties>
</contributor>
</contributors>

<mailingLists>
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/scijava/ui/UserInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.scijava.ui.console.ConsolePane;
import org.scijava.ui.viewer.DisplayWindow;
import org.scijava.widget.FileWidget;
import org.scijava.widget.WidgetStyle;

/**
* An end-user SciJava application user interface.
Expand Down Expand Up @@ -160,11 +161,11 @@ DialogPrompt dialogPrompt(String message, String title,
default File chooseFile(final File file, final String style) {
final String title;
// style can be a string with multiple comma-separated keywords
// TODO use a utility class for style handling, e.g. StyleUtils.isStyle(style, ...)
if (style == null) title = "Choose a file";
else if (style.toLowerCase().contains(FileWidget.DIRECTORY_STYLE)) title = "Choose a directory";
else if (style.toLowerCase().contains(FileWidget.OPEN_STYLE)) title = "Open";
else if (style.toLowerCase().contains(FileWidget.SAVE_STYLE)) title = "Save";
else if (WidgetStyle.isStyle(style, FileWidget.DIRECTORY_STYLE)) title = "Choose a directory";
else if (WidgetStyle.isStyle(style, FileWidget.FILE_AND_DIRECTORY_STYLE)) title = "Choose a file or directory";
else if (WidgetStyle.isStyle(style, FileWidget.OPEN_STYLE)) title = "Open";
else if (WidgetStyle.isStyle(style, FileWidget.SAVE_STYLE)) title = "Save";
else title = "Choose a file";

return chooseFile(title, file, style);
Expand All @@ -180,6 +181,7 @@ default File chooseFile(final File file, final String style) {
* <li>{@link FileWidget#OPEN_STYLE}</li>
* <li>{@link FileWidget#SAVE_STYLE}</li>
* <li>{@link FileWidget#DIRECTORY_STYLE}</li>
* <li>{@link FileWidget#FILE_AND_DIRECTORY_STYLE}</li>
* </ul>
* @return The {@link File} chosen by the user, or null if prompt is not
* available
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/scijava/widget/FileWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,11 @@ public interface FileWidget<U> extends InputWidget<File, U> {
*/
String DIRECTORY_STYLE = "directory";

/**
* Widget style for directory chooser dialogs.
*
* @see org.scijava.plugin.Parameter#style()
*/
String FILE_AND_DIRECTORY_STYLE = "both";

}
Loading