Commit 98fb16e3 authored by Benjamin Otte's avatar Benjamin Otte

filesystemmodel: Add a toggle for whether directories are filtered

parent b47b6d30
......@@ -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;
......@@ -1473,6 +1479,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,
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment