[gtk+] Freeze file system model during editing



commit cbb2938587dc335de898d9b2347d072a51c408ee
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Wed Nov 19 14:43:10 2014 +0000

    Freeze file system model during editing
    
    If a file system event arrives while GtkFileChooserWidget is asking the
    user to edit the name of a newly created folder, the file system model
    will drop the row with the editable cell, and the user will have to
    start from scratch.
    
    This makes creating new directories impossible inside a directory with a
    file currently being downloaded, for instance, and it's really unhelpful
    to the user because the editable row simply disappears.
    
    We already have a mechanism in place to freeze the file system model, so
    we can reuse it between the add_editable() and the remove_editable()
    calls.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=729927

 gtk/gtkfilesystemmodel.c |   81 +++++++++++++++++++++++++---------------------
 1 files changed, 44 insertions(+), 37 deletions(-)
---
diff --git a/gtk/gtkfilesystemmodel.c b/gtk/gtkfilesystemmodel.c
index 909359a..85a282e 100644
--- a/gtk/gtkfilesystemmodel.c
+++ b/gtk/gtkfilesystemmodel.c
@@ -1993,43 +1993,6 @@ _gtk_file_system_model_set_filter (GtkFileSystemModel      *model,
 }
 
 /**
- * _gtk_file_system_model_add_editable:
- * @model: a #GtkFileSystemModel
- * @iter: Location to return the iter corresponding to the editable row
- * 
- * Adds an “empty” row at the beginning of the model.  This does not refer to
- * any file, but is a temporary placeholder for a file name that the user will
- * type when a corresponding cell is made editable.  When your code is done
- * using this temporary row, call _gtk_file_system_model_remove_editable().
- **/
-void
-_gtk_file_system_model_add_editable (GtkFileSystemModel *model, GtkTreeIter *iter)
-{
-  g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
-  g_return_if_fail (!get_node (model, 0)->visible);
-
-  node_set_visible_and_filtered_out (model, 0, TRUE, FALSE);
-  ITER_INIT_FROM_INDEX (model, iter, 0);
-}
-
-/**
- * _gtk_file_system_model_remove_editable:
- * @model: a #GtkFileSystemModel
- * 
- * Removes the “empty” row at the beginning of the model that was
- * created with _gtk_file_system_model_add_editable().  You should call
- * this function when your code is finished editing this temporary row.
- **/
-void
-_gtk_file_system_model_remove_editable (GtkFileSystemModel *model)
-{
-  g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
-  g_return_if_fail (get_node (model, 0)->visible);
-
-  node_set_visible_and_filtered_out (model, 0, FALSE, FALSE);
-}
-
-/**
  * freeze_updates:
  * @model: a #GtkFileSystemModel
  *
@@ -2166,3 +2129,47 @@ _gtk_file_system_model_add_and_query_file (GtkFileSystemModel *model,
                            gtk_file_system_model_query_done,
                            model);
 }
+
+/**
+ * _gtk_file_system_model_add_editable:
+ * @model: a #GtkFileSystemModel
+ * @iter: Location to return the iter corresponding to the editable row
+ * 
+ * Adds an “empty” row at the beginning of the model.  This does not refer to
+ * any file, but is a temporary placeholder for a file name that the user will
+ * type when a corresponding cell is made editable.  When your code is done
+ * using this temporary row, call _gtk_file_system_model_remove_editable().
+ **/
+void
+_gtk_file_system_model_add_editable (GtkFileSystemModel *model, GtkTreeIter *iter)
+{
+  g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
+  g_return_if_fail (!get_node (model, 0)->visible);
+
+  node_set_visible_and_filtered_out (model, 0, TRUE, FALSE);
+  ITER_INIT_FROM_INDEX (model, iter, 0);
+
+  /* we don't want file system changes to affect the model while
+   * editing is in place
+   */
+  freeze_updates (model);
+}
+
+/**
+ * _gtk_file_system_model_remove_editable:
+ * @model: a #GtkFileSystemModel
+ * 
+ * Removes the “empty” row at the beginning of the model that was
+ * created with _gtk_file_system_model_add_editable().  You should call
+ * this function when your code is finished editing this temporary row.
+ **/
+void
+_gtk_file_system_model_remove_editable (GtkFileSystemModel *model)
+{
+  g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
+  g_return_if_fail (get_node (model, 0)->visible);
+
+  thaw_updates (model);
+
+  node_set_visible_and_filtered_out (model, 0, FALSE, FALSE);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]