Skip to content

Commit

Permalink
Merge pull request #480 from tischi/file-widget-both
Browse files Browse the repository at this point in the history
Add FileWidget.FILE_AND_DIRECTORY_STYLE
  • Loading branch information
ctrueden authored Jul 10, 2024
2 parents a2d0042 + 79a92d8 commit 9a9fb72
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
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";

}

0 comments on commit 9a9fb72

Please sign in to comment.