[nautilus] window: accumulate saving the sidebar width in GSettings



commit ddd59a578e403e815f76006477bf5eaea5b20c1e
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri Feb 18 18:41:26 2011 -0500

    window: accumulate saving the sidebar width in GSettings
    
    We don't want to hammer DConf with writes.

 src/nautilus-window-private.h |    2 ++
 src/nautilus-window.c         |   35 +++++++++++++++++++++++++++++------
 2 files changed, 31 insertions(+), 6 deletions(-)
---
diff --git a/src/nautilus-window-private.h b/src/nautilus-window-private.h
index a45473a..3953e6f 100644
--- a/src/nautilus-window-private.h
+++ b/src/nautilus-window-private.h
@@ -111,6 +111,8 @@ struct NautilusWindowDetails
         GtkWidget *split_view_hpane;
 
         gboolean disable_chrome;
+
+        guint sidebar_width_handler_id;
 };
 
 #define NAUTILUS_MENU_PATH_BACK_ITEM			"/menu/Go/Back"
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index a125252..cd15c70 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -429,6 +429,21 @@ nautilus_window_set_initial_window_geometry (NautilusWindow *window)
 				          max_height_for_screen));
 }
 
+static gboolean
+save_sidebar_width_cb (gpointer user_data)
+{
+	NautilusWindow *window = user_data;
+
+	window->details->sidebar_width_handler_id = 0;
+
+	DEBUG ("Saving sidebar width: %d", window->details->side_pane_width);
+
+	g_settings_set_int (nautilus_window_state,
+			    NAUTILUS_WINDOW_STATE_SIDEBAR_WIDTH,
+			    window->details->side_pane_width);
+
+	return FALSE;
+}
 
 /* side pane helpers */
 static void
@@ -440,14 +455,17 @@ side_pane_size_allocate_callback (GtkWidget *widget,
 
 	window = user_data;
 
-	if (allocation->width != window->details->side_pane_width) {
+	if (window->details->sidebar_width_handler_id != 0) {
+		g_source_remove (window->details->sidebar_width_handler_id);
+		window->details->sidebar_width_handler_id = 0;
+	}
+
+	if (allocation->width != window->details->side_pane_width &&
+	    allocation->width > 1) {
 		window->details->side_pane_width = allocation->width;
 
-		DEBUG ("Saving sidebar width: %d", allocation->width);
-		
-		g_settings_set_int (nautilus_window_state,
-				    NAUTILUS_WINDOW_STATE_SIDEBAR_WIDTH,
-				    allocation->width <= 1 ? 0 : allocation->width);
+		window->details->sidebar_width_handler_id =
+			g_idle_add (save_sidebar_width_cb, window);
 	}
 }
 
@@ -768,6 +786,11 @@ nautilus_window_finalize (GObject *object)
 
 	window = NAUTILUS_WINDOW (object);
 
+	if (window->details->sidebar_width_handler_id != 0) {
+		g_source_remove (window->details->sidebar_width_handler_id);
+		window->details->sidebar_width_handler_id = 0;
+	}
+
 	g_free (window->details->sidebar_id);
 	g_clear_object (&window->details->nav_state);
 



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