[libgda] GdaBrowser: improved query execution history
- From: Vivien Malerba <vivien src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgda] GdaBrowser: improved query execution history
- Date: Fri, 4 Sep 2009 20:11:51 +0000 (UTC)
commit 1d57f7be9c73e2571583d68c2b6ec0e6d5721ba4
Author: Vivien Malerba <malerba gnome-db org>
Date: Fri Sep 4 21:57:00 2009 +0200
GdaBrowser: improved query execution history
Added copy to editor and delete history items
tools/browser/query-exec/query-console.c | 82 +++++++++++++++++++++++++++++-
tools/browser/query-exec/query-editor.c | 5 ++-
2 files changed, 85 insertions(+), 2 deletions(-)
---
diff --git a/tools/browser/query-exec/query-console.c b/tools/browser/query-exec/query-console.c
index c688ca6..274fc3f 100644
--- a/tools/browser/query-exec/query-console.c
+++ b/tools/browser/query-exec/query-console.c
@@ -64,6 +64,8 @@ struct _QueryConsolePrivate {
GtkWidget *params_form;
QueryEditor *history;
+ GtkWidget *history_del_button;
+ GtkWidget *history_copy_button;
};
static void query_console_class_init (QueryConsoleClass *klass);
@@ -196,6 +198,9 @@ static void sql_variables_clicked_cb (GtkToggleButton *button, QueryConsole *tco
static void sql_execute_clicked_cb (GtkButton *button, QueryConsole *tconsole);
static void sql_indent_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_changed_cb (QueryEditor *history, QueryConsole *tconsole);
/**
* query_console_new
*
@@ -330,12 +335,26 @@ query_console_new (BrowserConnection *bcnc)
query_editor_set_mode (tconsole->priv->history, QUERY_EDITOR_HISTORY);
gtk_widget_set_size_request (wid, 200, -1);
gtk_box_pack_start (GTK_BOX (vbox), wid, TRUE, TRUE, 0);
+ g_signal_connect (wid, "changed",
+ G_CALLBACK (history_changed_cb), tconsole);
- bbox = gtk_vbutton_box_new ();
+ bbox = gtk_hbutton_box_new ();
gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0);
+ gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
+
+ button = make_small_button (FALSE, _("Copy"), GTK_STOCK_COPY, _("Copy selected history\nto editor"));
+ gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (history_copy_clicked_cb), tconsole);
+ tconsole->priv->history_copy_button = button;
+ gtk_widget_set_sensitive (button, FALSE);
button = make_small_button (FALSE, _("Delete"), GTK_STOCK_DELETE, _("Delete history item"));
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (history_delete_clicked_cb), tconsole);
+ tconsole->priv->history_del_button = button;
+ gtk_widget_set_sensitive (button, FALSE);
/* bottom right */
vbox = gtk_vbox_new (FALSE, 0);
@@ -397,6 +416,67 @@ make_small_button (gboolean is_toggle, const gchar *label, const gchar *stock_id
return button;
}
+static void
+history_changed_cb (QueryEditor *history, QueryConsole *tconsole)
+{
+ gboolean act = FALSE;
+ QueryEditor *qe;
+
+ qe = tconsole->priv->history;
+ if (query_editor_get_current_history_item (qe) ||
+ query_editor_get_current_history_batch (qe))
+ act = TRUE;
+ gtk_widget_set_sensitive (tconsole->priv->history_del_button, act);
+ gtk_widget_set_sensitive (tconsole->priv->history_copy_button, act);
+}
+
+static void
+history_delete_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);
+ }
+}
+
+static void
+history_copy_clicked_cb (GtkButton *button, QueryConsole *tconsole)
+{
+ QueryEditorHistoryItem *qih;
+ QueryEditor *qe;
+ GString *string;
+
+ string = g_string_new ("");
+ qe = tconsole->priv->history;
+ qih = query_editor_get_current_history_item (qe);
+ if (qih)
+ g_string_append (string, qih->sql);
+ else {
+ QueryEditorHistoryBatch *qib;
+ qib = query_editor_get_current_history_batch (qe);
+ if (qib) {
+ GSList *list;
+ for (list = qib->hist_items; list; list = list->next) {
+ if (list != qib->hist_items)
+ g_string_append (string, "\n\n");
+ g_string_append (string, ((QueryEditorHistoryItem*) list->data)->sql);
+ }
+ }
+ }
+
+ query_editor_set_text (tconsole->priv->editor, string->str);
+ g_string_free (string, TRUE);
+}
+
static gboolean
compute_params (QueryConsole *tconsole)
{
diff --git a/tools/browser/query-exec/query-editor.c b/tools/browser/query-exec/query-editor.c
index 897a5ff..fc91ec9 100644
--- a/tools/browser/query-exec/query-editor.c
+++ b/tools/browser/query-exec/query-editor.c
@@ -828,6 +828,9 @@ query_editor_add_history_item (QueryEditor *editor, QueryEditorHistoryItem *hist
hdata->item = query_editor_history_item_ref (hist_item);
g_hash_table_insert (editor->priv->hash, hist_item, hdata);
+ /* remove leading and trailing spaces */
+ g_strstrip (hist_item->sql);
+
if (!editor->priv->insert_into_batch)
query_editor_start_history_batch (editor, NULL);
@@ -1008,8 +1011,8 @@ query_editor_del_history_batch (QueryEditor *editor, QueryEditorHistoryBatch *ba
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->priv->text));
/* compute new focus */
+ focus = NULL;
if (i > 0) {
- focus = NULL;
list = g_slist_nth (editor->priv->batches_list, i - 1);
focus = g_hash_table_lookup (editor->priv->hash, list->data);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]