[libgda] GdaBrowser: added shortcuts to query editor
- From: Vivien Malerba <vivien src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgda] GdaBrowser: added shortcuts to query editor
- Date: Fri, 18 Sep 2009 18:39:02 +0000 (UTC)
commit ba2aaca58ad3959381295d9dfc52b493e11ac224
Author: Vivien Malerba <malerba gnome-db org>
Date: Tue Sep 15 20:16:12 2009 +0200
GdaBrowser: added shortcuts to query editor
CTRL+L => clear editor
CTRL+Enter => execute query
tools/browser/query-exec/query-console.c | 14 ++++++++--
tools/browser/query-exec/query-editor.c | 38 +++++++++++++++++++++++------
tools/browser/query-exec/query-editor.h | 7 +++++
3 files changed, 48 insertions(+), 11 deletions(-)
---
diff --git a/tools/browser/query-exec/query-console.c b/tools/browser/query-exec/query-console.c
index c2c87d6..2787def 100644
--- a/tools/browser/query-exec/query-console.c
+++ b/tools/browser/query-exec/query-console.c
@@ -263,6 +263,7 @@ static GtkWidget *make_small_button (gboolean is_toggle,
const gchar *label, const gchar *stock_id, const gchar *tooltip);
static void editor_changed_cb (QueryEditor *editor, QueryConsole *tconsole);
+static void editor_execute_request_cb (QueryEditor *editor, QueryConsole *tconsole);
static void sql_clear_clicked_cb (GtkButton *button, QueryConsole *tconsole);
static void sql_variables_clicked_cb (GtkToggleButton *button, QueryConsole *tconsole);
static void sql_execute_clicked_cb (GtkButton *button, QueryConsole *tconsole);
@@ -320,8 +321,7 @@ query_console_new (BrowserConnection *bcnc)
gtk_label_set_markup (GTK_LABEL (wid), str);
g_free (str);
gtk_misc_set_alignment (GTK_MISC (wid), 0., -1);
- gtk_widget_set_tooltip_text (wid, _("Enter SQL code to execute\n(must be understood by the database to\n"
- "which the connection is opened, except for the variables definition)"));
+ gtk_widget_set_tooltip_markup (wid, QUERY_EDITOR_TOOLTIP);
gtk_box_pack_start (GTK_BOX (vbox), wid, FALSE, FALSE, 0);
wid = query_editor_new ();
@@ -329,6 +329,8 @@ query_console_new (BrowserConnection *bcnc)
gtk_box_pack_start (GTK_BOX (vbox), wid, TRUE, TRUE, 0);
g_signal_connect (wid, "changed",
G_CALLBACK (editor_changed_cb), tconsole);
+ g_signal_connect (wid, "execute-request",
+ G_CALLBACK (editor_execute_request_cb), tconsole);
gtk_widget_set_size_request (wid, -1, 200);
vbox = gtk_vbox_new (FALSE, 0);
@@ -663,7 +665,13 @@ editor_changed_cb (QueryEditor *editor, QueryConsole *tconsole)
g_source_remove (tconsole->priv->params_compute_id);
tconsole->priv->params_compute_id = g_timeout_add_seconds (1, (GSourceFunc) compute_params, tconsole);
}
-
+
+static void
+editor_execute_request_cb (QueryEditor *editor, QueryConsole *tconsole)
+{
+ sql_execute_clicked_cb (NULL, tconsole);
+}
+
static void
sql_variables_clicked_cb (GtkToggleButton *button, QueryConsole *tconsole)
{
diff --git a/tools/browser/query-exec/query-editor.c b/tools/browser/query-exec/query-editor.c
index 6735354..a681606 100644
--- a/tools/browser/query-exec/query-editor.c
+++ b/tools/browser/query-exec/query-editor.c
@@ -103,10 +103,11 @@ enum
{
CHANGED,
HISTORY_ITEM_REMOVED,
+ EXECUTE_REQUEST,
LAST_SIGNAL
};
-static gint query_editor_signals[LAST_SIGNAL] = { 0, 0 };
+static gint query_editor_signals[LAST_SIGNAL] = { 0, 0, 0 };
/*
@@ -185,6 +186,14 @@ query_editor_class_init (QueryEditorClass *klass)
NULL, NULL,
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+ query_editor_signals[EXECUTE_REQUEST] =
+ g_signal_new ("execute-request",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (QueryEditorClass, execute_request),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
query_editor_signals[HISTORY_ITEM_REMOVED] =
g_signal_new ("history-item-removed",
G_TYPE_FROM_CLASS (object_class),
@@ -216,11 +225,9 @@ event_after (GtkWidget *text_view, GdkEvent *ev, QueryEditor *editor)
GdkEventButton *event;
gint x, y;
- if (editor->priv->mode != QUERY_EDITOR_HISTORY)
- return FALSE;
-
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
- if (ev->type == GDK_BUTTON_RELEASE) {
+ if ((editor->priv->mode == QUERY_EDITOR_HISTORY) &&
+ (ev->type == GDK_BUTTON_RELEASE)) {
event = (GdkEventButton *)ev;
if (event->button != 1)
@@ -253,7 +260,8 @@ event_after (GtkWidget *text_view, GdkEvent *ev, QueryEditor *editor)
}
else if (ev->type == GDK_KEY_PRESS) {
GdkEventKey *evkey = ((GdkEventKey*) ev);
- if ((evkey->keyval == GDK_Up) || (evkey->keyval == GDK_Down)) {
+ if ((editor->priv->mode == QUERY_EDITOR_HISTORY) &&
+ ((evkey->keyval == GDK_Up) || (evkey->keyval == GDK_Down))) {
HistItemData *nfocus = NULL;
if (editor->priv->hist_focus) {
if (((GdkEventKey*) ev)->keyval == GDK_Up)
@@ -267,13 +275,27 @@ event_after (GtkWidget *text_view, GdkEvent *ev, QueryEditor *editor)
focus_on_hist_data (editor, nfocus);
return TRUE;
}
- else if ((evkey->keyval == GDK_Delete) && editor->priv->hist_focus) {
+ else if ((editor->priv->mode == QUERY_EDITOR_HISTORY) &&
+ ((evkey->keyval == GDK_Delete) && editor->priv->hist_focus)) {
if (editor->priv->hist_focus->item)
query_editor_del_current_history_item (editor);
else if (editor->priv->hist_focus->batch)
query_editor_del_history_batch (editor, editor->priv->hist_focus->batch);
return TRUE;
}
+ else if ((editor->priv->mode == QUERY_EDITOR_READWRITE) &&
+ (evkey->state & GDK_CONTROL_MASK) &&
+ ((evkey->keyval == GDK_L) || (evkey->keyval == GDK_l))) {
+ GtkTextIter start, end;
+ gtk_text_buffer_get_start_iter (buffer, &start);
+ gtk_text_buffer_get_end_iter (buffer, &end);
+ gtk_text_buffer_delete (buffer, &start, &end);
+ }
+ else if ((editor->priv->mode == QUERY_EDITOR_READWRITE) &&
+ (evkey->state & GDK_CONTROL_MASK) &&
+ (evkey->keyval == GDK_Return)) {
+ g_signal_emit (editor, query_editor_signals[EXECUTE_REQUEST], 0);
+ }
}
else
return FALSE;
@@ -386,7 +408,7 @@ query_editor_init (QueryEditor *editor, QueryEditorClass *klass)
#endif
gtk_container_add (GTK_CONTAINER (editor->priv->scrolled_window), editor->priv->text);
-
+ gtk_widget_set_tooltip_markup (editor->priv->text, QUERY_EDITOR_TOOLTIP);
g_signal_connect (editor->priv->text, "event-after",
G_CALLBACK (event_after), editor);
g_signal_connect (gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->priv->text)), "changed",
diff --git a/tools/browser/query-exec/query-editor.h b/tools/browser/query-exec/query-editor.h
index d18e703..fd07d9c 100644
--- a/tools/browser/query-exec/query-editor.h
+++ b/tools/browser/query-exec/query-editor.h
@@ -35,6 +35,12 @@ G_BEGIN_DECLS
#define QUERY_IS_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, QUERY_TYPE_EDITOR))
#define QUERY_IS_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), QUERY_TYPE_EDITOR))
+#define QUERY_EDITOR_TOOLTIP _("Enter SQL code to execute\n(must be understood by the database to\n" \
+ "which the connection is opened, except for the variables definition)\n" \
+ "The following shortcuts are allowed:\n" \
+ " <small><b>CTRL - l</b></small> to clear the editor\n" \
+ " <small><b>CTRL - ENTER</b></small> to execute SQL")
+
typedef struct _QueryEditor QueryEditor;
typedef struct _QueryEditorClass QueryEditorClass;
typedef struct _QueryEditorPrivate QueryEditorPrivate;
@@ -82,6 +88,7 @@ struct _QueryEditorClass {
/* signals */
void (* changed) (QueryEditor *editor);
void (* history_item_removed) (QueryEditor *editor, QueryEditorHistoryItem *item);
+ void (* execute_request) (QueryEditor *editor);
};
/*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]