[libgda] Clear query execution history in GdaBrowser



commit 0f8d46f20775668fa16644ae8794d31fdc6cf7cd
Author: Vivien Malerba <malerba gnome-db org>
Date:   Fri Oct 9 19:04:19 2009 +0200

    Clear query execution history in GdaBrowser
    
    instead of simply removing history items one by one.

 tools/browser/query-exec/query-console.c |   22 ++++-------------
 tools/browser/query-exec/query-editor.c  |   39 +++++++++++++++++++++++++++++-
 tools/browser/query-exec/query-editor.h  |    2 +
 tools/browser/query-exec/query-result.c  |   11 ++++++++
 4 files changed, 56 insertions(+), 18 deletions(-)
---
diff --git a/tools/browser/query-exec/query-console.c b/tools/browser/query-exec/query-console.c
index f4c9ffd..617f9a9 100644
--- a/tools/browser/query-exec/query-console.c
+++ b/tools/browser/query-exec/query-console.c
@@ -272,7 +272,7 @@ static void sql_indent_clicked_cb (GtkButton *button, QueryConsole *tconsole);
 static void sql_favorite_clicked_cb (GtkButton *button, QueryConsole *tconsole);
 
 static void history_copy_clicked_cb (GtkButton *button, QueryConsole *tconsole);
-static void history_delete_clicked_cb (GtkButton *button, QueryConsole *tconsole);
+static void history_clear_clicked_cb (GtkButton *button, QueryConsole *tconsole);
 static void history_changed_cb (QueryEditor *history, QueryConsole *tconsole);
 /**
  * query_console_new
@@ -428,10 +428,10 @@ query_console_new (BrowserConnection *bcnc)
 	tconsole->priv->history_copy_button = button;
 	gtk_widget_set_sensitive (button, FALSE);
 
-	button = make_small_button (FALSE, _("Delete"), GTK_STOCK_DELETE, _("Delete history item"));
+	button = make_small_button (FALSE, _("Clear"), GTK_STOCK_CLEAR, _("Clear history"));
 	gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
 	g_signal_connect (button, "clicked",
-			  G_CALLBACK (history_delete_clicked_cb), tconsole);
+			  G_CALLBACK (history_clear_clicked_cb), tconsole);
 	tconsole->priv->history_del_button = button;
 	gtk_widget_set_sensitive (button, FALSE);
 
@@ -521,21 +521,9 @@ history_changed_cb (QueryEditor *history, QueryConsole *tconsole)
 }
 
 static void
-history_delete_clicked_cb (GtkButton *button, QueryConsole *tconsole)
+history_clear_clicked_cb (GtkButton *button, QueryConsole *tconsole)
 {
-	QueryEditorHistoryItem *qih;
-	QueryEditor *qe;
-	
-	qe = tconsole->priv->history;
-        qih = query_editor_get_current_history_item (qe);
-        if (qih)
-                query_editor_del_current_history_item (qe);
-        else {
-                QueryEditorHistoryBatch *qib;
-                qib = query_editor_get_current_history_batch (qe);
-                if (qib)
-                        query_editor_del_history_batch (qe, qib);
-        }
+	query_editor_del_all_history_items (tconsole->priv->history);
 }
 
 static void
diff --git a/tools/browser/query-exec/query-editor.c b/tools/browser/query-exec/query-editor.c
index 163e637..31d3fc6 100644
--- a/tools/browser/query-exec/query-editor.c
+++ b/tools/browser/query-exec/query-editor.c
@@ -116,11 +116,12 @@ enum
 {
         CHANGED,
 	HISTORY_ITEM_REMOVED,
+	HISTORY_CLEARED,
 	EXECUTE_REQUEST,
         LAST_SIGNAL
 };
 
-static gint query_editor_signals[LAST_SIGNAL] = { 0, 0, 0 };
+static gint query_editor_signals[LAST_SIGNAL] = { 0, 0, 0, 0 };
 
 
 /*
@@ -215,6 +216,14 @@ query_editor_class_init (QueryEditorClass *klass)
                               NULL, NULL,
                               g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
 
+	query_editor_signals[HISTORY_CLEARED] =
+                g_signal_new ("history-cleared",
+                              G_TYPE_FROM_CLASS (object_class),
+                              G_SIGNAL_RUN_FIRST,
+                              G_STRUCT_OFFSET (QueryEditorClass, history_cleared),
+                              NULL, NULL,
+                              g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
 	object_class->finalize = query_editor_finalize;
 	GTK_WIDGET_CLASS (object_class)->map = query_editor_map;
 	GTK_WIDGET_CLASS (object_class)->grab_focus = query_editor_grab_focus;
@@ -1488,6 +1497,34 @@ query_editor_del_current_history_item (QueryEditor *editor)
 }
 
 /**
+ * query_editor_del_all_history_items
+ * @editor: a #QueryEditor
+ *
+ * Clears all the history
+ */
+void
+query_editor_del_all_history_items (QueryEditor *editor)
+{
+	GtkTextBuffer *buffer;
+	GtkTextIter start, end;
+
+	g_return_if_fail (QUERY_IS_EDITOR (editor));
+	g_return_if_fail (editor->priv->mode == QUERY_EDITOR_HISTORY);
+
+	buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->priv->text));
+	hist_data_free_all (editor);
+
+	gtk_text_buffer_get_start_iter (buffer, &start);
+	gtk_text_buffer_get_end_iter (buffer, &end);
+	gtk_text_buffer_delete (buffer, &start, &end);
+
+	editor->priv->hash = g_hash_table_new_full (NULL, NULL, NULL,
+						    (GDestroyNotify) hist_item_data_unref);
+	g_signal_emit (editor, query_editor_signals[CHANGED], 0);
+	g_signal_emit (editor, query_editor_signals[HISTORY_CLEARED], 0);
+}
+
+/**
  * query_editor_del_history_batch
  * @editor: a #QueryEditor
  * @batch: a #QueryEditorHistoryBatch
diff --git a/tools/browser/query-exec/query-editor.h b/tools/browser/query-exec/query-editor.h
index 1fccfff..046c071 100644
--- a/tools/browser/query-exec/query-editor.h
+++ b/tools/browser/query-exec/query-editor.h
@@ -91,6 +91,7 @@ struct _QueryEditorClass {
 	/* signals */
 	void (* changed) (QueryEditor *editor);
 	void (* history_item_removed) (QueryEditor *editor, QueryEditorHistoryItem *item);
+	void (* history_cleared) (QueryEditor *editor);
 	void (* execute_request) (QueryEditor *editor);
 };
 
@@ -132,6 +133,7 @@ void       query_editor_add_history_item (QueryEditor *editor, QueryEditorHistor
 QueryEditorHistoryItem *query_editor_get_current_history_item (QueryEditor *editor);
 QueryEditorHistoryBatch *query_editor_get_current_history_batch (QueryEditor *editor);
 
+void       query_editor_del_all_history_items (QueryEditor *editor);
 void       query_editor_del_current_history_item (QueryEditor *editor);
 void       query_editor_del_history_batch (QueryEditor *editor, QueryEditorHistoryBatch *batch);
 
diff --git a/tools/browser/query-exec/query-result.c b/tools/browser/query-exec/query-result.c
index 655c45c..970d229 100644
--- a/tools/browser/query-exec/query-result.c
+++ b/tools/browser/query-exec/query-result.c
@@ -85,6 +85,13 @@ history_item_removed_cb (QueryEditor *history, QueryEditorHistoryItem *item, Que
 }
 
 static void
+history_cleared_cb (QueryEditor *history, QueryResult *result)
+{
+	g_hash_table_remove_all (result->priv->hash);
+	g_print ("Removed all GtkWidget\n");
+}
+
+static void
 query_result_finalize (GObject *object)
 {
 	QueryResult *result = (QueryResult *) object;
@@ -97,6 +104,8 @@ query_result_finalize (GObject *object)
 	if (result->priv->history) {
 		g_signal_handlers_disconnect_by_func (result->priv->history,
 						      G_CALLBACK (history_item_removed_cb), result);
+		g_signal_handlers_disconnect_by_func (result->priv->history,
+						      G_CALLBACK (history_cleared_cb), result);
 		g_object_unref (result->priv->history);
 	}
 	if (result->priv->hbatch)
@@ -149,6 +158,8 @@ query_result_new (QueryEditor *history)
 	result = g_object_new (QUERY_TYPE_RESULT, NULL);
 	g_signal_connect (history, "history-item-removed",
 			  G_CALLBACK (history_item_removed_cb), result);
+	g_signal_connect (history, "history-cleared",
+			  G_CALLBACK (history_cleared_cb), result);
 	result->priv->history = g_object_ref (history);
 
 



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