After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 679333 - unable to filter folders in folder select mode
unable to filter folders in folder select mode
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkFileChooser
unspecified
Other Linux
: Normal normal
: ---
Assigned To: William Jon McCann
Federico Mena Quintero
Depends on:
Blocks: 679579
 
 
Reported: 2012-07-03 15:34 UTC by William Jon McCann
Modified: 2012-12-31 20:11 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Filter directories when in direction selection mode (1.80 KB, patch)
2012-07-08 07:26 UTC, William Jon McCann
none Details | Review
Desensitize filtered folders when in folder selection mode (13.52 KB, patch)
2012-07-10 15:49 UTC, William Jon McCann
none Details | Review

Description William Jon McCann 2012-07-03 15:34:22 UTC
It would be nice to have a way for an app to mark certain items as insensitive or disallow selection of them.

The specific use case is for nautilus. We now show the file chooser when selecting a destination directory for a copy/move. We should disallow using the source files/dirs as the destination.
Comment 1 Federico Mena Quintero 2012-07-03 16:00:17 UTC
You can gtk_file_chooser_set_filter().  Just create a GtkFileFilter, and add a custom filtering callback with gtk_file_filter_add_custom().
Comment 2 William Jon McCann 2012-07-03 17:07:33 UTC
Doesn't seem to filter directories. Maybe due to:
  model->filter_folders = FALSE;

?
Comment 3 Federico Mena Quintero 2012-07-03 20:12:38 UTC
Hmmm.  There's an internal gtk_file_system_model_set_filter_folders(), and it's just used from GtkFileChooserEntry.

GtkFileChooserDefault could very well use that function.  Can you test how it feels when turned on?  (Do you only need SELECT_FOLDER mode, or do you need to select files as well?)

I *vaguely* remember something about having trouble with filtering folders, but don't have any bugs in mind right now.
Comment 4 William Jon McCann 2012-07-08 07:26:20 UTC
Created attachment 218258 [details] [review]
Filter directories when in direction selection mode
Comment 5 William Jon McCann 2012-07-08 07:28:06 UTC
This patch seems to work. One issue is that I think for directories it may be better to disable selection (make insensitive) rather than simply hide them. It was a little disconcerting to not see the directories at all.
Comment 6 William Jon McCann 2012-07-09 13:44:19 UTC
Perhaps we can add a flag that allows changing the behavior of the filter from hide to disable?
Comment 7 Federico Mena Quintero 2012-07-09 22:40:15 UTC
We could have a little gtk_file_filter_set_style (filter, enum { HIDE, DISABLE } ) API, but then we could run into inconsistencies with how apps set that.  This single use case (the "disable the source files/dirs") would be perfect for this, though.

... Alternatively, we could make it so that filtered folders *are* shown, just desensitized.  GtkFileSystemModel does the filtering.  node_should_be_visible() has a big fat "if (is_folder) return TRUE;", which gets passed to node_set_visible() from various places.  Maybe node_should_be_visible() should return a yes/no/disabled enum.

Take your pick; in either case the file system model would need some massaging :)
Comment 8 William Jon McCann 2012-07-10 15:49:27 UTC
Created attachment 218436 [details] [review]
Desensitize filtered folders when in folder selection mode
Comment 9 William Jon McCann 2012-07-10 16:25:21 UTC
Another thing I noticed is that it would be nice to disallow selecting the current directory (parent of the folders selected to move/copy) but still make the current directory sensitive so you can navigate through it. But we wouldn't want to allow navigating into the folders set to be moved. Not sure how to do that.
Comment 10 Federico Mena Quintero 2012-07-11 14:52:28 UTC
I'll be looking at your patch today; thanks!
Comment 11 Federico Mena Quintero 2012-07-11 21:09:10 UTC
I've just pushed a filechooser-filtered-folders branch with your patch and some minor changes.

One thing that bothers me is that:

1. node_should_be_filtered_out() calls gtk_file_filter_filter() and negates the result.

2. file_system_model_set() takes *that* and negates the result again.

... even though I put in a commit to s/filtered/filtered_out to make it clear what the result means.

Maybe we should keep "filtered" mean "passed the filter" as usual, and avoid flipping booleans all over the place.  Or we can s/filtered_out/filtered_in and remove the negations.  What do you thinK?

Please make that final change and feel free to merge the branch into master.  Don't forget to add the bug number to the message of the merge commit.  Thanks!

(In reply to comment #9)
> Another thing I noticed is that it would be nice to disallow selecting the
> current directory (parent of the folders selected to move/copy) but still make
> the current directory sensitive so you can navigate through it. But we wouldn't
> want to allow navigating into the folders set to be moved. Not sure how to do
> that.

If you try to move/copy to $cwd/original_name, I'd just make that idempotent and not do anything at all ("the files are where you wanted them to end up").  The folders set to be moved/copied will be insensitive anyway.
Comment 12 Federico Mena Quintero 2012-12-31 20:10:09 UTC
See bug #689451 for a bug exposed by this change.
Comment 13 Federico Mena Quintero 2012-12-31 20:11:29 UTC
AFAICT this is already merged into master, so I'll close this bug.  The one mentioned in comment #12 is still valid.