diff options
author | Owen Taylor <otaylor@redhat.com> | 2003-07-23 15:31:10 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2003-07-23 15:31:10 +0000 |
commit | 733f4489ade5b79227af871e1cbe694806ec367e (patch) | |
tree | cb11e44251dfd274d38a2ef88d2cd7f3bb8619f1 /gtk/gtkfilesystemmodel.c | |
parent | 96ba7bb65e02858e08f78922f4d837ac7d1a65a0 (diff) | |
download | gtk+-733f4489ade5b79227af871e1cbe694806ec367e.tar.gz |
File filter objects.
Wed Jul 23 11:23:43 2003 Owen Taylor <otaylor@redhat.com>
* gtkfilefilter.[ch]: File filter objects.
* gtkfilechooser.[ch] gtkfilechooserutils.[ch]: Add
file filtering to API.
* gtkfilechooserimpldefault.c: Implement file filters.
* testfilechooser.c: Try out the filter functionality.
* gtkfilesystemmodel.c: Add
_gtk_file_system_model_set_filter() to set a callback
function for filtering.
* gtkfilechooserutils.c: Propagate property notification
to the receiver.
* fnmatch.c: Copy this from GTK+ temporarily to get
UTF-8 pattern matching functionality.
Diffstat (limited to 'gtk/gtkfilesystemmodel.c')
-rw-r--r-- | gtk/gtkfilesystemmodel.c | 62 |
1 files changed, 43 insertions, 19 deletions
diff --git a/gtk/gtkfilesystemmodel.c b/gtk/gtkfilesystemmodel.c index ed738481b6..2a28d44152 100644 --- a/gtk/gtkfilesystemmodel.c +++ b/gtk/gtkfilesystemmodel.c @@ -44,6 +44,9 @@ struct _GtkFileSystemModel FileModelNode *roots; GtkFileFolder *root_folder; + GtkFileSystemModelFilter filter_func; + gpointer filter_data; + GSList *idle_clears; GSource *idle_clear_source; @@ -561,7 +564,8 @@ _gtk_file_system_model_new (GtkFileSystem *file_system, GtkFileInfoType types) { GtkFileSystemModel *model; - GSList *roots, *tmp_list; + GSList *roots = NULL; + GSList *tmp_list; g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL); @@ -686,6 +690,16 @@ model_refilter_recurse (GtkFileSystemModel *model, } } +static void +model_refilter_all (GtkFileSystemModel *model) +{ + GtkTreePath *path; + + path = gtk_tree_path_new (); + model_refilter_recurse (model, NULL, path); + gtk_tree_path_free (path); +} + /** * _gtk_file_system_model_set_show_hidden: * @model: a #GtkFileSystemModel @@ -702,13 +716,8 @@ _gtk_file_system_model_set_show_hidden (GtkFileSystemModel *model, if (show_hidden != model->show_hidden) { - GtkTreePath *path; - model->show_hidden = show_hidden; - - path = gtk_tree_path_new (); - model_refilter_recurse (model, NULL, path); - gtk_tree_path_free (path); + model_refilter_all (model); } } @@ -728,13 +737,8 @@ _gtk_file_system_model_set_show_folders (GtkFileSystemModel *model, if (show_folders != model->show_folders) { - GtkTreePath *path; - model->show_folders = show_folders; - - path = gtk_tree_path_new (); - model_refilter_recurse (model, NULL, path); - gtk_tree_path_free (path); + model_refilter_all (model); } } @@ -755,13 +759,8 @@ _gtk_file_system_model_set_show_files (GtkFileSystemModel *model, if (show_files != model->show_files) { - GtkTreePath *path; - model->show_files = show_files; - - path = gtk_tree_path_new (); - model_refilter_recurse (model, NULL, path); - gtk_tree_path_free (path); + model_refilter_all (model); } } @@ -898,6 +897,29 @@ find_and_ref_path (GtkFileSystemModel *model, } /** + * _gtk_file_system_model_set_filter: + * @mode: a #GtkFileSystemModel + * @filter: function to be called for each file + * @user_data: data to pass to @filter + * + * Sets a callback called for each file/directory to see whether + * it should be included in model. If this function was made + * public, we'd want to include a GDestroyNotify as well. + **/ +void +_gtk_file_system_model_set_filter (GtkFileSystemModel *model, + GtkFileSystemModelFilter filter, + gpointer user_data) +{ + g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model)); + + model->filter_func = filter; + model->filter_data = user_data; + + model_refilter_all (model); +} + +/** * _gtk_file_system_model_path_do: * @model: a #GtkFileSystemModel * @path: a path pointing to a file in the filesystem @@ -1024,6 +1046,8 @@ file_model_node_is_visible (GtkFileSystemModel *model, return FALSE; if (!model->show_hidden && gtk_file_info_get_is_hidden (info)) return FALSE; + if (model->filter_func && !model->filter_func (model, node->path, info, model->filter_data)) + return FALSE; return TRUE; } |