summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2011-11-07 15:18:40 +0100
committerBenjamin Otte <otte@redhat.com>2011-12-16 20:09:14 +0100
commit98fb16e30718fd42123e6d755c7780b09b1ff0b9 (patch)
tree05070c944c100cbbc6de22dde3581c5330c8873d
parentb47b6d307e0958097bd3e5792bc9a39bd54f5f3a (diff)
downloadgtk+-98fb16e30718fd42123e6d755c7780b09b1ff0b9.tar.gz
filesystemmodel: Add a toggle for whether directories are filtered
-rw-r--r--gtk/gtkfilesystemmodel.c51
-rw-r--r--gtk/gtkfilesystemmodel.h2
2 files changed, 43 insertions, 10 deletions
diff --git a/gtk/gtkfilesystemmodel.c b/gtk/gtkfilesystemmodel.c
index 15497e645f..7cfc5a1567 100644
--- a/gtk/gtkfilesystemmodel.c
+++ b/gtk/gtkfilesystemmodel.c
@@ -169,6 +169,7 @@ struct _GtkFileSystemModel
guint show_hidden :1; /* whether to show hidden files */
guint show_folders :1;/* whether to show folders */
guint show_files :1; /* whether to show files */
+ guint filter_folders :1;/* whether filter applies to folders */
};
#define GTK_FILE_SYSTEM_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_SYSTEM_MODEL, GtkFileSystemModelClass))
@@ -340,7 +341,7 @@ node_should_be_visible (GtkFileSystemModel *model, guint id)
FileModelNode *node = get_node (model, id);
GtkFileFilterInfo filter_info = { 0, };
GtkFileFilterFlags required;
- gboolean is_folder, result;
+ gboolean result;
char *mime_type = NULL;
char *filename = NULL;
char *uri = NULL;
@@ -352,15 +353,19 @@ node_should_be_visible (GtkFileSystemModel *model, guint id)
(g_file_info_get_is_hidden (node->info) || g_file_info_get_is_backup (node->info)))
return FALSE;
- is_folder = _gtk_file_info_consider_as_directory (node->info);
-
- /* wtf? */
- if (model->show_folders != model->show_files &&
- model->show_folders != is_folder)
- return FALSE;
+ if (_gtk_file_info_consider_as_directory (node->info))
+ {
+ if (!model->show_folders)
+ return FALSE;
- if (is_folder)
- return TRUE;
+ if (!model->filter_folders)
+ return TRUE;
+ }
+ else
+ {
+ if (!model->show_files)
+ return FALSE;
+ }
if (model->filter == NULL)
return TRUE;
@@ -1035,6 +1040,7 @@ _gtk_file_system_model_init (GtkFileSystemModel *model)
model->show_files = TRUE;
model->show_folders = TRUE;
model->show_hidden = FALSE;
+ model->filter_folders = FALSE;
model->sort_column_id = GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID;
@@ -1474,6 +1480,30 @@ _gtk_file_system_model_set_show_files (GtkFileSystemModel *model,
}
/**
+ * _gtk_file_system_model_set_filter_folders:
+ * @model: a #GtkFileSystemModel
+ * @filter_folders: whether the filter applies to folders
+ *
+ * Sets whether the filter set by _gtk_file_system_model_set_filter()
+ * applies to folders. By default, it does not and folders are always
+ * visible.
+ **/
+void
+_gtk_file_system_model_set_filter_folders (GtkFileSystemModel *model,
+ gboolean filter_folders)
+{
+ g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
+
+ filter_folders = filter_folders != FALSE;
+
+ if (filter_folders != model->filter_folders)
+ {
+ model->filter_folders = filter_folders;
+ gtk_file_system_model_refilter_all (model);
+ }
+}
+
+/**
* _gtk_file_system_model_get_cancellable:
* @model: the model
*
@@ -1815,7 +1845,8 @@ _gtk_file_system_model_update_file (GtkFileSystemModel *model,
* @filter: (allow-none): %NULL or filter to use
*
* Sets a filter to be used for deciding if a row should be visible or not.
- * Directories are always visible.
+ * Whether this filter applies to directories can be toggled with
+ * _gtk_file_system_model_set_filter_folders().
**/
void
_gtk_file_system_model_set_filter (GtkFileSystemModel *model,
diff --git a/gtk/gtkfilesystemmodel.h b/gtk/gtkfilesystemmodel.h
index a6fbab936f..4a533daddb 100644
--- a/gtk/gtkfilesystemmodel.h
+++ b/gtk/gtkfilesystemmodel.h
@@ -80,6 +80,8 @@ void _gtk_file_system_model_set_show_folders (GtkFileSystemModel
gboolean show_folders);
void _gtk_file_system_model_set_show_files (GtkFileSystemModel *model,
gboolean show_files);
+void _gtk_file_system_model_set_filter_folders (GtkFileSystemModel *model,
+ gboolean show_folders);
void _gtk_file_system_model_freeze_updates (GtkFileSystemModel *model);
void _gtk_file_system_model_thaw_updates (GtkFileSystemModel *model);
void _gtk_file_system_model_clear_cache (GtkFileSystemModel *model,