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

Allow including and excluding files from the list using globbing pattern - p3 #19

Closed
DaveJarvis opened this issue Apr 9, 2021 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@DaveJarvis
Copy link
Collaborator

DaveJarvis commented Apr 9, 2021

Sometimes users (or developers) may wish to hide certain files. It would be convenient to use a globbing pattern in such cases. For example, consider the following API:

  /**
   * Sets the list of file names to display. For example, a single call to
   * this method with values of ("**.pdf", "Portable Document Format (PDF)")
   * would display only a file listing of PDF files.
   *
   * @param glob        Pattern that allows matching file names to be listed.
   * @param description Human-readable description of the pattern.
   */
  void addIncludeFileFilter( String glob, String description );

  /**
   * Sets the list of file names to suppress. For example, a single call to
   * this method with values of (".*") would prevent listing files that begin
   * with a period.
   *
   * @param glob Pattern that allows matching file names to be suppressed.
   */
  void addExcludeFileFilter( String glob );

Multiple calls would be permitted, as well as mixing. Such as:

builder.addIncludeFileFilter( "**.md, **.Rmd, **.markdown", "Markdown Files" );
builder.addIncludeFileFilter( "*.ps, **.eps", "(Encapsulated) PostScript" );
builder.addExcludeFileFilter( ".*" ); // Don't show hidden files

This API is a bit simpler, IMO, than creating JWFileChooserFilterType instances. (It's syntactic sugar, really.)

Given that the user cannot select excluded files, it needs no description. See FileSystem.getPathMatcher for globbing details.

@DaveJarvis DaveJarvis changed the title Allow suppressing files from the list Allow including and excluding files from the list using globbing pattern Apr 9, 2021
@DaveJarvis DaveJarvis changed the title Allow including and excluding files from the list using globbing pattern Allow including and excluding files from the list using globbing pattern - p3 Apr 9, 2021
@io7m
Copy link
Owner

io7m commented Apr 9, 2021

I need to think about this a bit. For uniformity, I'd like to keep the implementation itself based around filters, but we could use a more terse API to create them (similar to the above example) and to allow for one or more filters to be invisibly and always enabled.

@io7m io7m self-assigned this Apr 10, 2021
@io7m
Copy link
Owner

io7m commented Apr 10, 2021

I'd like to nail down the semantics of globbing filters. An isolated "include" glob is easy to understand, as is an isolated "exclude" glob. Combining arbitrary includes and excludes is somewhat less easy to understand, and there are many different ways to interpret the combinations.

I generally favour the semantics provided by sequential evaluation with explicit halts. The key thing to note is that the rules are evaluated in declaration order, and the difference here would be that the match patterns would be the glob syntax supported by FileSystem.getPathMatcher. Would this be acceptable if I put a pleasant API over it?

@DaveJarvis
Copy link
Collaborator Author

DaveJarvis commented Apr 10, 2021

I see what you mean.

builder.addIncludeFileFilter( "**.{md,Rmd,markdown}", "Markdown Files" );
builder.addExcludeFileFilter( "*.*md" );

I'd expect that all .Rmd files would be listed, but no .cmd files. Call order is imperative, yes, and enforcing it is fine. Perhaps throw an exception? Haven't fully thought this through, but the following examples should probably throw:

// Don't permit exclude before include?
builder.addExcludeFileFilter( "*.*md" );
builder.addIncludeFileFilter( "**.{md,Rmd,markdown}", "Markdown Files" ); // throw?

// Don't permit include after exclude?
builder.addIncludeFileFilter( "**.{md,Rmd,markdown}", "Markdown Files" );
builder.addExcludeFileFilter( "*.*md" );
builder.addIncludeFileFilter( "**.{asc,text}", "Text Files" );  // throw?

Even evaluating in declaration order without exceptions is fine, if you think it'll work. My preference is to force the programmer to deal with potentially ambiguous outcomes.

@io7m
Copy link
Owner

io7m commented Apr 11, 2021

You might want to take a look at the feature/globbing-19 branch. There's information in the README.md file now about how the API works, and various unit tests.

@DaveJarvis DaveJarvis added the enhancement New feature or request label Apr 11, 2021
@io7m
Copy link
Owner

io7m commented Apr 29, 2021

I've merged the globbing-19 branch. Additions/changes should be specified in new tickets.

@io7m io7m closed this as completed Apr 29, 2021
io7m added a commit that referenced this issue May 18, 2021
Release: com.io7m.jwheatsheaf 3.0.0

A big thanks to @DaveJarvis for suggestions, bug reports, and some
code contributions!

Change: Add the ability to specify custom strings (Ticket: #7)
Change: Add the ability to confirm file selections (Ticket: #17)
Change: Allow for including ".." in directory listings (Ticket: #23)
Change: Improve "select directly" dialog behaviour (Ticket: #29)
Change: Fix the size formatter (Ticket: #30)
Change: Use the default filesystem by default (Ticket: #21)
Change: Add support for glob-based filters (Ticket: #19)
Change: Improve filename field behaviour (Ticket: #28)
Change: Add an optional home directory button (Ticket: #12)
Change: Enable sorting of directory items (Ticket: #22)
Change: Allow for setting a default file filter (Ticket: #9)
Change: Allow the escape key to close file choosers (Ticket: #14)
Change: Allow for specifying an initial filename in choosers (Ticket: #15)
Change: Allow for specifying custom dialog titles (Ticket: #8)
Change: Make the default filters part of the public API (Ticket: #10)
io7m added a commit that referenced this issue May 18, 2021
Release: com.io7m.jwheatsheaf 3.0.0

A big thanks to @DaveJarvis for suggestions, bug reports, and some
code contributions!

Change: Add the ability to specify custom strings (Ticket: #7)
Change: Add the ability to confirm file selections (Ticket: #17)
Change: Allow for including ".." in directory listings (Ticket: #23)
Change: Improve "select directly" dialog behaviour (Ticket: #29)
Change: Fix the size formatter (Ticket: #30)
Change: Use the default filesystem by default (Ticket: #21)
Change: Add support for glob-based filters (Ticket: #19)
Change: Improve filename field behaviour (Ticket: #28)
Change: Add an optional home directory button (Ticket: #12)
Change: Enable sorting of directory items (Ticket: #22)
Change: Allow for setting a default file filter (Ticket: #9)
Change: Allow the escape key to close file choosers (Ticket: #14)
Change: Allow for specifying an initial filename in choosers (Ticket: #15)
Change: Allow for specifying custom dialog titles (Ticket: #8)
Change: Make the default filters part of the public API (Ticket: #10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants