[gtk+/filesystemmodel: 27/28] allow flushing cached values in the model
- From: Benjamin Otte <otte src gnome org>
- To: svn-commits-list gnome org
- Subject: [gtk+/filesystemmodel: 27/28] allow flushing cached values in the model
- Date: Tue, 23 Jun 2009 16:19:07 -0400 (EDT)
commit 2c807173aa4771bfabf38aa68667daf267e34ca0
Author: Benjamin Otte <otte gnome org>
Date: Tue Jun 23 11:59:58 2009 +0200
allow flushing cached values in the model
... and use it to handle icon theme changes
gtk/gtkfilechooserdefault.c | 16 +++++++++++
gtk/gtkfilesystemmodel.c | 60 +++++++++++++++++++++++++++++++++++++++++++
gtk/gtkfilesystemmodel.h | 2 +
3 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 94b9b4b..3d5c60e 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -4484,6 +4484,10 @@ create_file_list (GtkFileChooserDefault *impl)
gtk_tree_view_column_set_title (impl->list_name_column, _("Name"));
renderer = gtk_cell_renderer_pixbuf_new ();
+ /* We set a fixed size so that we get an emoty row even if no icons are loaded yet */
+ gtk_cell_renderer_set_fixed_size (renderer,
+ renderer->xpad * 2 + impl->icon_size,
+ renderer->ypad * 2 + impl->icon_size);
gtk_tree_view_column_pack_start (impl->list_name_column, renderer, FALSE);
impl->list_name_renderer = gtk_cell_renderer_text_new ();
@@ -5696,6 +5700,8 @@ change_icon_theme (GtkFileChooserDefault *impl)
{
GtkSettings *settings;
gint width, height;
+ GtkCellRenderer *renderer;
+ GList *cells;
profile_start ("start", NULL);
@@ -5707,6 +5713,16 @@ change_icon_theme (GtkFileChooserDefault *impl)
impl->icon_size = FALLBACK_ICON_SIZE;
shortcuts_reload_icons (impl);
+ /* the first cell in the first column is the icon column, and we have a fixed size there */
+ cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (
+ gtk_tree_view_get_column (GTK_TREE_VIEW (impl->browse_files_tree_view), 0)));
+ renderer = GTK_CELL_RENDERER (cells->data);
+ gtk_cell_renderer_set_fixed_size (renderer,
+ renderer->xpad * 2 + impl->icon_size,
+ renderer->ypad * 2 + impl->icon_size);
+ g_list_free (cells);
+ if (impl->browse_files_model)
+ _gtk_file_system_model_clear_cache (impl->browse_files_model, MODEL_COL_PIXBUF);
gtk_widget_queue_resize (impl->browse_files_tree_view);
profile_end ("end", NULL);
diff --git a/gtk/gtkfilesystemmodel.c b/gtk/gtkfilesystemmodel.c
index f2194da..a5cf03a 100644
--- a/gtk/gtkfilesystemmodel.c
+++ b/gtk/gtkfilesystemmodel.c
@@ -1483,3 +1483,63 @@ _gtk_file_system_model_thaw_updates (GtkFileSystemModel *model)
}
}
+/**
+ * _gtk_file_system_model_clear_cached_values:
+ * @model: a #GtkFileSystemModel
+ * @column: the column to clear or -1 for all columns
+ *
+ * Clears the cached values in the model for the given @column. Use
+ * this function whenever your get_value function would return different
+ * values for a column.
+ * The file chooser uses this for example when the icon theme changes to
+ * invalidate the cached pixbufs.
+ **/
+void
+_gtk_file_system_model_clear_cache (GtkFileSystemModel *model,
+ int column)
+{
+ guint i, start, end;
+ gboolean changed;
+
+ g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
+ g_return_if_fail (column >= -1 && (guint) column < model->n_columns);
+
+ if (column)
+ {
+ start = column;
+ end = column + 1;
+ }
+ else
+ {
+ start = 0;
+ end = model->n_columns;
+ }
+
+ for (i = 0; i < model->files->len; i++)
+ {
+ FileModelNode *node = get_node (model, i);
+ changed = FALSE;
+ for (column = start; column < end; column++)
+ {
+ if (!G_VALUE_TYPE (&node->values[column]))
+ continue;
+
+ g_value_unset (&node->values[column]);
+ changed = TRUE;
+ }
+
+ if (changed && node->visible)
+ {
+ GtkTreePath *path;
+ GtkTreeIter iter;
+
+ path = gtk_tree_path_new_from_node (model, i);
+ ITER_INIT_FROM_INDEX (model, &iter, i);
+ gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
+ gtk_tree_path_free (path);
+ }
+ }
+
+ /* FIXME: resort? */
+}
+
diff --git a/gtk/gtkfilesystemmodel.h b/gtk/gtkfilesystemmodel.h
index 08d2bee..cb91fce 100644
--- a/gtk/gtkfilesystemmodel.h
+++ b/gtk/gtkfilesystemmodel.h
@@ -71,6 +71,8 @@ void _gtk_file_system_model_set_show_files (GtkFileSystemModel
gboolean show_files);
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,
+ int column);
typedef gboolean (*GtkFileSystemModelFilter) (GtkFileSystemModel *model,
GFile *file,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]