scijava-common icon indicating copy to clipboard operation
scijava-common copied to clipboard

Support for file chooser that works with both files and directories

Open kephale opened this issue 4 years ago • 4 comments

I'm looking into a file chooser that works for both Files and Directories (e.g. should work with tif and n5 datasets which are directories). i presume the place to introduce this change is https://github.com/scijava/scijava-common/blob/448a8bd51c4910834e0a1f0e7af393acf3e7d7a5/src/main/java/org/scijava/ui/UserInterface.java#L163

kephale avatar Apr 21 '20 14:04 kephale

Both files and directories would be stored in a File object on the Java side.

The FileListWidget already allows for the both style:

https://github.com/scijava/scijava-common/blob/560ad964a7a1e859edd4dbe4fc48d7d9e09523f2/src/main/java/org/scijava/widget/FileListWidget.java#L51-L56

To allow the same for single files, we need to add a new style to FileWidget as well, and then adapt the UserInterface#chooseFile method as you pointed out.

imagejan avatar Apr 21 '20 18:04 imagejan

To allow the same for single files, we need to add a new style to FileWidget as well

Is it really necessary to create a new style ?
I dont understand why we could not use the both style from the FileListWidget for the FileWidget too. Is it important that a given style is part of the class it is used in ? Or can the new FileWidget style also encode for both ?

I had the same interrogation for https://github.com/scijava/scijava-common/issues/197#issuecomment-619216086. Using only directory for both FileWidget and FileListWidget so we dont have to document an additional directories style.

LauLauThom avatar Apr 27 '20 14:04 LauLauThom

Well, keeping the constants in the classes where they're used would be consistent. As FileWidget defined OPEN, SAVE (both of which are "files-only") and DIRECTORY, this was not sufficient for the requirements of FileListWidget where we wanted to select files, directories or both, but never save. That's why originally we defined new styles there. But I agree, we could also unify this and keep all styles in the FileWidget class. Maybe even be more concise and say "open-file", "open-directory", "open-both" and "save-file". But now we also have to ensure backwards-compatibility 🙁 so if we define new styles or change them, we'll have to keep the others for a while (forever?) as deprecated...

@ctrueden any opinion/suggestion?

imagejan avatar Apr 27 '20 15:04 imagejan

Alright, maybe the better is the enemy of the good here :P I think we should introduce the least changes. So as a sum up this is the current situation

File styles

  • "open"
  • "save"
  • "directory"
  • "both" (missing) -> new one ? or use FileList.both ?

FileList styles

  • "files"
  • "directories"
  • "both"

which cover most if not all cases ? So the question is really about a new "FileWidget.both" or using the existing "FileListWidget.both" in the FileWidget class, isnt it ?

LauLauThom avatar Apr 27 '20 15:04 LauLauThom