void (*finished_loading) (GtkFileSystemModel *model, GError *error);
};
+static void freeze_updates (GtkFileSystemModel *model);
+static void thaw_updates (GtkFileSystemModel *model);
+
static guint node_get_for_file (GtkFileSystemModel *model,
GFile *file);
{
GtkFileSystemModel *model = data;
- _gtk_file_system_model_thaw_updates (model);
+ thaw_updates (model);
model->dir_thaw_source = 0;
return FALSE;
{
if (model->dir_thaw_source == 0)
{
- _gtk_file_system_model_freeze_updates (model);
+ freeze_updates (model);
model->dir_thaw_source = gdk_threads_add_timeout_full (IO_PRIORITY + 1,
50,
thaw_func,
{
g_source_remove (model->dir_thaw_source);
model->dir_thaw_source = 0;
- _gtk_file_system_model_thaw_updates (model);
+ thaw_updates (model);
}
g_signal_emit (model, file_system_model_signals[FINISHED_LOADING], 0, error);
return;
}
- _gtk_file_system_model_freeze_updates (model);
+ freeze_updates (model);
/* start at index 1, don't change the editable */
for (i = 1; i < model->files->len; i++)
node_compute_visibility_and_filters (model, i);
model->filter_on_thaw = FALSE;
- _gtk_file_system_model_thaw_updates (model);
+ thaw_updates (model);
}
/**
return TRUE;
}
+/* When an element is added or removed to the model->files array, we need to
+ * update the model->file_lookup mappings of (node, index), as the indexes
+ * change. This function adds the specified increment to the index in that pair
+ * if the index is equal or after the specified id. We use this to slide the
+ * mappings up or down when a node is added or removed, respectively.
+ */
+static void
+adjust_file_lookup (GtkFileSystemModel *model, guint id, int increment)
+{
+ GHashTableIter iter;
+ gpointer key;
+ gpointer value;
+
+ g_hash_table_iter_init (&iter, model->file_lookup);
+
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ {
+ guint index = GPOINTER_TO_UINT (value);
+
+ if (index >= id)
+ {
+ index += increment;
+ g_hash_table_iter_replace (&iter, GUINT_TO_POINTER (index));
+ }
+ }
+}
+
/**
* add_file:
* @model: the model
{
FileModelNode *node;
guint id;
+ guint row;
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
g_return_if_fail (G_IS_FILE (file));
return;
node = get_node (model, id);
- node_set_visible_and_filtered_out (model, id, FALSE, FALSE);
+ row = node_get_tree_row (model, id);
+
+ node_invalidate_index (model, id);
g_hash_table_remove (model->file_lookup, file);
g_object_unref (node->file);
+ adjust_file_lookup (model, id, -1);
if (node->info)
g_object_unref (node->info);
g_array_remove_index (model->files, id);
- g_hash_table_remove_all (model->file_lookup);
- /* We don't need to resort, as removing a row doesn't change the sorting order */
+
+ /* We don't need to resort, as removing a row doesn't change the sorting order of the other rows */
+
+ emit_row_deleted_for_row (model, row);
}
/**
}
/**
- * _gtk_file_system_model_freeze_updates:
+ * freeze_updates:
* @model: a #GtkFileSystemModel
*
- * Freezes most updates on the model, so that performing multiple
- * operations on the files in the model do not cause any events.
- * Use _gtk_file_system_model_thaw_updates() to resume proper
- * operations. It is fine to call this function multiple times as
- * long as freeze and thaw calls are balanced.
+ * Freezes most updates on the model, so that performing multiple operations on
+ * the files in the model do not cause any events. Use thaw_updates() to resume
+ * proper operations. It is fine to call this function multiple times as long as
+ * freeze and thaw calls are balanced.
**/
-void
-_gtk_file_system_model_freeze_updates (GtkFileSystemModel *model)
+static void
+freeze_updates (GtkFileSystemModel *model)
{
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
}
/**
- * _gtk_file_system_model_thaw_updates:
+ * thaw_updates:
* @model: a #GtkFileSystemModel
*
- * Undoes the effect of a previous call to
- * _gtk_file_system_model_freeze_updates()
+ * Undoes the effect of a previous call to freeze_updates()
**/
-void
-_gtk_file_system_model_thaw_updates (GtkFileSystemModel *model)
+static void
+thaw_updates (GtkFileSystemModel *model)
{
gboolean stuff_added;