[libgda] GdaBrowser: improved feedback when executing statements



commit 980460c9525a6bea35f6ce8c29edac8fa03ca6c7
Author: Vivien Malerba <malerba gnome-db org>
Date:   Tue Sep 22 22:25:11 2009 +0200

    GdaBrowser: improved feedback when executing statements
    
    the status bar is updated and a notice is shown if a transaction
    was started by the executed statement even though it was not a BEGIN
    statement (which is usually the case when using BLOBs)

 tools/browser/query-exec/query-console.c |   19 +++++++
 tools/browser/support.c                  |   82 +++++++++++++++++++++++++++++-
 tools/browser/support.h                  |    1 +
 3 files changed, 101 insertions(+), 1 deletions(-)
---
diff --git a/tools/browser/query-exec/query-console.c b/tools/browser/query-exec/query-console.c
index 12bb3b7..3076e9a 100644
--- a/tools/browser/query-exec/query-console.c
+++ b/tools/browser/query-exec/query-console.c
@@ -28,6 +28,7 @@
 #include "../support.h"
 #include "../cc-gray-bar.h"
 #include "query-exec-perspective.h"
+#include "../browser-window.h"
 #include "../browser-page.h"
 #include "../browser-stock-icons.h"
 #include "query-editor.h"
@@ -893,6 +894,7 @@ sql_execute_clicked_cb (GtkButton *button, QueryConsole *tconsole)
 		return;
 	}
 
+	/* mark the current SQL to be kept by the editor as an internal history */
 	query_editor_keep_current_state (tconsole->priv->editor);
 
 	/* actual Execution */
@@ -979,6 +981,23 @@ query_exec_fetch_cb (QueryConsole *tconsole)
 					 * FIXME: store error in history => modify QueryEditorHistoryItem
 					 */
 				}
+				else
+					browser_window_push_status (BROWSER_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
+								    "QueryConsole", _("Statement executed"), TRUE);
+
+				/* display a message if a transaction has been started */
+				if (! history->within_transaction &&
+				    browser_connection_get_transaction_status (tconsole->priv->bcnc) &&
+				    gda_statement_get_statement_type (estmt->stmt) != GDA_SQL_STATEMENT_BEGIN) {
+					browser_show_notice (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
+							     "QueryExecTransactionStarted",
+							     "%s", _("A transaction has automatically been started\n"
+								     "during this statement's execution, this usually\n"
+								     "happens when blobs are selected (and the transaction\n"
+								     "will have to remain opened while the blobs are still\n"
+								     "accessible, clear the corresponding history item before\n"
+								     "closing the transaction)."));
+				}
 				
 				query_editor_add_history_item (tconsole->priv->history, history);
 				query_editor_history_item_unref (history);
diff --git a/tools/browser/support.c b/tools/browser/support.c
index 013880e..94030de 100644
--- a/tools/browser/support.c
+++ b/tools/browser/support.c
@@ -110,7 +110,7 @@ browser_connection_close (GtkWindow *parent, BrowserConnection *bcnc)
  * @format: printf() style format string
  * @...: arguments for @format
  *
- * Displays a modal error notice untill the user aknowledges it.
+ * Displays a modal error until the user aknowledges it.
  */
 void
 browser_show_error (GtkWindow *parent, const gchar *format, ...)
@@ -136,6 +136,86 @@ browser_show_error (GtkWindow *parent, const gchar *format, ...)
         gtk_widget_destroy (dialog);
 }
 
+/* hash table to remain which context notices have to be hidden: key=context, value=GINT_TO_POINTER (1) */
+static GHashTable *hidden_contexts = NULL;
+
+static void
+hide_notice_toggled_cb (GtkToggleButton *toggle, gchar *context)
+{
+	g_assert (hidden_contexts);
+	if (gtk_toggle_button_get_active (toggle))
+		g_hash_table_insert (hidden_contexts, g_strdup (context), GINT_TO_POINTER (TRUE));
+	else
+		g_hash_table_remove (hidden_contexts, context);
+}
+
+/**
+ * browser_show_notice
+ * @parent: a #GtkWindow
+ * @context: a context string or %NULL
+ * @format: printf() style format string
+ * @...: arguments for @format
+ *
+ * Displays a modal notice until the user aknowledges it.
+ *
+ * If @context is not NULL, then the message box contains a check box to avoid displaying the
+ * same massage again.
+ */
+void
+browser_show_notice (GtkWindow *parent, const gchar *context, const gchar *format, ...)
+{
+        va_list args;
+        gchar sz[2048];
+        GtkWidget *dialog;
+	gboolean hide = FALSE;
+
+        /* build the message string */
+        va_start (args, format);
+        vsnprintf (sz, sizeof (sz), format, args);
+        va_end (args);
+
+	if (context) {
+		if (!hidden_contexts)
+			hidden_contexts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+		hide = g_hash_table_lookup (hidden_contexts, context);
+	}
+
+	if (hide) {
+		if (BROWSER_IS_WINDOW (parent)) {
+			gchar *ptr;
+			for (ptr = sz; *ptr && (*ptr != '\n'); ptr++);
+			if (*ptr) {
+				*ptr = '.'; ptr++;
+				*ptr = '.'; ptr++;
+				*ptr = '.'; ptr++;
+				*ptr = 0;
+			}
+			browser_window_push_status (BROWSER_WINDOW (parent),
+						    "SupportNotice", sz, TRUE);
+		}
+	}
+	else {
+		/* create the error message dialog */
+		dialog = gtk_message_dialog_new_with_markup (parent,
+							     GTK_DIALOG_DESTROY_WITH_PARENT |
+							     GTK_DIALOG_MODAL, GTK_MESSAGE_INFO,
+							     GTK_BUTTONS_CLOSE,
+							     "<span weight=\"bold\">%s</span>\n%s", _("Note:"), sz);
+		if (context) {
+			GtkWidget *cb;
+			cb = gtk_check_button_new_with_label (_("Don't show this message again"));
+			g_signal_connect_data (cb, "toggled",
+					       G_CALLBACK (hide_notice_toggled_cb), g_strdup (context),
+					       (GClosureNotify) g_free, 0);
+			gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), cb, FALSE, FALSE, 10);
+		}
+		
+		gtk_widget_show_all (dialog);
+		gtk_dialog_run (GTK_DIALOG (dialog));
+		gtk_widget_destroy (dialog);
+	}
+}
+
 static GtkWidget *
 _browser_make_tab_label (const gchar *label,
 			 GtkWidget *img, gboolean with_close,
diff --git a/tools/browser/support.h b/tools/browser/support.h
index 2752605..1efb212 100644
--- a/tools/browser/support.h
+++ b/tools/browser/support.h
@@ -31,6 +31,7 @@ G_BEGIN_DECLS
 BrowserConnection *browser_connection_open (GError **error);
 gboolean           browser_connection_close (GtkWindow *parent, BrowserConnection *bcnc);
 void               browser_show_error (GtkWindow *parent, const gchar *format, ...);
+void               browser_show_notice (GtkWindow *parent, const gchar *context, const gchar *format, ...);
 
 GtkWidget*         browser_make_tab_label_with_stock (const gchar *label,
 						      const gchar *stock_id, gboolean with_close,



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