[nautilus/gnome-3-6] query-editor: don't always re-add mimetype rows when setting query



commit 708ed78e6fc5889f7c38c7149c91c468a7cdbd4d
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Nov 12 15:53:55 2012 -0500

    query-editor: don't always re-add mimetype rows when setting query
    
    Since we also use nautilus_query_editor_set_query() when the query
    editor already has a query, don't unconditionally add mimetype rows from
    there, but only when we're being called with a previous query.
    
    Fix a bug where mimetype rows were added when switching between current
    location and all files.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=687537

 src/nautilus-query-editor.c |   45 +++++++++++++++++++++++++++++++++---------
 1 files changed, 35 insertions(+), 10 deletions(-)
---
diff --git a/src/nautilus-query-editor.c b/src/nautilus-query-editor.c
index b4cc290..e356374 100644
--- a/src/nautilus-query-editor.c
+++ b/src/nautilus-query-editor.c
@@ -70,6 +70,8 @@ struct NautilusQueryEditorDetails {
 
 	GList *rows;
 	gboolean got_preedit;
+
+	NautilusQuery *query;
 };
 
 enum {
@@ -247,6 +249,8 @@ nautilus_query_editor_dispose (GObject *object)
 		editor->details->typing_timeout_id = 0;
 	}
 
+	g_clear_object (&editor->details->query);
+
 	G_OBJECT_CLASS (nautilus_query_editor_parent_class)->dispose (object);
 }
 
@@ -852,15 +856,20 @@ get_next_free_type (NautilusQueryEditor *editor)
 }
 
 static void
+row_destroy (NautilusQueryEditorRow *row)
+{
+	gtk_widget_destroy (row->toolbar);
+	g_free (row);
+}
+
+static void
 remove_row_cb (GtkButton *clicked_button, NautilusQueryEditorRow *row)
 {
 	NautilusQueryEditor *editor;
 
 	editor = row->editor;
-	gtk_container_remove (GTK_CONTAINER (editor), row->toolbar);
-	
 	editor->details->rows = g_list_remove (editor->details->rows, row);
-	g_free (row);
+	row_destroy (row);
 
 	nautilus_query_editor_changed (editor);
 }
@@ -1172,11 +1181,29 @@ nautilus_query_editor_set_location (NautilusQueryEditor *editor,
 	update_location (editor);
 }
 
+static void
+update_rows (NautilusQueryEditor *editor,
+	     NautilusQuery       *query)
+{
+	NautilusQueryEditorRowType type;
+
+	/* if we were just created, set the rows from query,
+	 * otherwise, re-use the query setting we have already.
+	 */
+	if (query != NULL && editor->details->query == NULL) {
+		for (type = 0; type < NAUTILUS_QUERY_EDITOR_ROW_LAST; type++) {
+			row_type[type].add_rows_from_query (editor, query);
+		}
+	} else if (query == NULL && editor->details->query != NULL) {
+		g_list_free_full (editor->details->rows, (GDestroyNotify) row_destroy);
+		editor->details->rows = NULL;
+	}
+}
+
 void
 nautilus_query_editor_set_query (NautilusQueryEditor	*editor,
 				 NautilusQuery		*query)
 {
-	NautilusQueryEditorRowType type;
 	char *text = NULL;
 
 	if (query != NULL) {
@@ -1193,16 +1220,14 @@ nautilus_query_editor_set_query (NautilusQueryEditor	*editor,
 	g_free (editor->details->current_uri);
 	editor->details->current_uri = NULL;
 
+	update_rows (editor, query);
+	g_clear_object (&editor->details->query);
+
 	if (query != NULL) {
+		editor->details->query = g_object_ref (query);
 		editor->details->current_uri = nautilus_query_get_location (query);
 		update_location (editor);
-
-
-		for (type = 0; type < NAUTILUS_QUERY_EDITOR_ROW_LAST; type++) {
-			row_type[type].add_rows_from_query (editor, query);
-		}
 	}
 
-
 	editor->details->change_frozen = FALSE;
 }



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