[gnome-db] Patch for Replacing Text with GnomeDbSqlEditor in SQL WIndow.(Gnome2)
- From: Daniel Morgan <danmorg sc rr com>
- To: Rodrigo Moya <rodrigo gnome-db org>
- Cc: GDA <gnome-db-list gnome org>
- Subject: [gnome-db] Patch for Replacing Text with GnomeDbSqlEditor in SQL WIndow.(Gnome2)
- Date: 26 Mar 2002 01:41:52 -0500
I have included a cvs patch to gnome-db that replaces the gnome_db_text
widget with the GnomeDbSqlEditor widget within the SQL Window.
GnomeDbSqlEditor has syntax hi-lighting for SQL statements.
Index: components/database/components-sql-view.c
===================================================================
RCS file: /cvs/gnome/gnome-db/components/database/components-sql-view.c,v
retrieving revision 1.3
diff -u -r1.3 components-sql-view.c
--- components/database/components-sql-view.c 19 Mar 2002 23:51:54 -0000 1.3
+++ components/database/components-sql-view.c 26 Mar 2002 06:33:39 -0000
@@ -25,6 +25,8 @@
#include <gtk/gtkvpaned.h>
#include <libgnomedb/gnome-db-grid.h>
#include <libgnomedb/gnome-db-util.h>
+#include <libgnomedb/gnome-db-sqleditor.h>
+#include <string.h>
#include "command-dialog.h"
#include "components-connection.h"
#include "components-sql-view.h"
@@ -47,92 +49,11 @@
static void components_sql_view_finalize (GObject *object);
static GObjectClass *parent_class = NULL;
-static gchar *sql_keywords[] = {
- " BY ",
- " CREATE DATABASE ",
- " CREATE TABLE ",
- " DELETE ",
- " FROM ",
- " ORDER ",
- " SELECT ",
- " UPDATE ",
- NULL
-};
/*
* Callbacks
*/
-static void
-parse_chars (gchar *text, gchar **end_ptr, gchar **tag, gboolean start)
-{
- gint i;
- gchar *next_token;
-
- *tag = NULL;
- *end_ptr = NULL;
-
- /* SQL keywords */
- for (i = 0; sql_keywords[i] != NULL; i++) {
- if (!g_ascii_strncasecmp (text, sql_keywords[i], strlen (sql_keywords[i]))) {
- *end_ptr = text + strlen (sql_keywords[i]);
- *tag = "sql";
- return;
- }
- }
-
- /* not at the start of a TAG, find the next one */
- for (i = 0; sql_keywords[i] != NULL; i++) {
- next_token = strstr (text, sql_keywords[i]);
- if (next_token) {
- if (*end_ptr)
- *end_ptr = (*end_ptr < next_token) ? *end_ptr : next_token;
- else
- *end_ptr = next_token;
- }
- }
-}
-
-static void
-text_changed_cb (GtkTextBuffer *buffer, gpointer user_data)
-{
- GtkTextIter start_iter, next_iter, tmp_iter;
- gchar *text, *start_ptr, *end_ptr, *tag;
- ComponentsSqlView *sql_view = (ComponentsSqlView *) user_data;
-
- g_return_if_fail (COMPONENTS_IS_SQL_VIEW (sql_view));
-
- /* parse the text buffer to higlight SQL keywords */
- gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, 0);
- next_iter = start_iter;
- while (gtk_text_iter_forward_line (&next_iter)) {
- gboolean start = TRUE;
-
- start_ptr = text = gtk_text_iter_get_text (&start_iter, &next_iter);
- do {
- parse_chars (start_ptr, &end_ptr, &tag, start);
- start = FALSE;
- if (end_ptr) {
- tmp_iter = start_iter;
- gtk_text_iter_forward_chars (&tmp_iter, end_ptr - start_ptr);
- }
- else
- tmp_iter = next_iter;
-
- if (tag) {
- gtk_text_buffer_apply_tag_by_name (
- buffer, tag, &start_iter, &tmp_iter);
- }
-
- start_iter = tmp_iter;
- start_ptr = end_ptr;
- } while (end_ptr);
-
- g_free (text);
- start_iter = next_iter;
- }
-}
-
/*
* ComponentsSqlView class implementation
*/
@@ -150,7 +71,6 @@
static void
components_sql_view_init (ComponentsSqlView *sql_view, ComponentsSqlViewClass *klass)
{
- GtkWidget *scroll;
GtkWidget *frame;
/* allocate our private structure */
@@ -159,24 +79,17 @@
frame = gnome_db_new_frame_widget (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
+ gtk_widget_show(frame);
gtk_box_pack_start (GTK_BOX (sql_view), frame, 1, 1, 0);
sql_view->priv->paned = gnome_db_new_vpaned_widget ();
+ gtk_widget_show (sql_view->priv->paned);
gtk_container_add (GTK_CONTAINER (frame), sql_view->priv->paned);
/* create the SQL buffer */
- scroll = gnome_db_new_scrolled_window_widget ();
- gtk_container_set_border_width (GTK_CONTAINER (scroll), 3);
-
- sql_view->priv->text = gnome_db_new_text_widget (NULL);
- gtk_text_buffer_create_tag (gtk_text_view_get_buffer (sql_view->priv->text), "sql",
- "foreground", "blue",
- "weight", PANGO_WEIGHT_BOLD,
- NULL);
- g_signal_connect (G_OBJECT (gtk_text_view_get_buffer (sql_view->priv->text)),
- "changed", G_CALLBACK (text_changed_cb), sql_view);
- gtk_container_add (GTK_CONTAINER (scroll), sql_view->priv->text);
- gtk_paned_add1 (GTK_PANED (sql_view->priv->paned), scroll);
+ sql_view->priv->text = gnome_db_sql_editor_new ();
+ gtk_widget_show (sql_view->priv->text);
+ gtk_paned_add1 (GTK_PANED (sql_view->priv->paned), sql_view->priv->text);
/* create the grid widget */
sql_view->priv->grid = gnome_db_grid_new ();
@@ -184,6 +97,8 @@
gtk_paned_add2 (GTK_PANED (sql_view->priv->paned), sql_view->priv->grid);
+ gtk_widget_show_all (sql_view->priv->paned);
+
/* initialize private data */
sql_view->priv->current_recsets = NULL;
}
@@ -264,27 +179,32 @@
/* we unref the connection, since we internally ref it in
components_sql_view_set_connection */
g_object_unref (G_OBJECT (cnc));
+
+ return sql_view;
}
void
components_sql_view_cut_clipboard (ComponentsSqlView *sql_view)
{
g_return_if_fail (COMPONENTS_IS_SQL_VIEW (sql_view));
- gnome_db_text_cut_clipboard (GTK_TEXT_VIEW (sql_view->priv->text));
+ gnome_db_text_cut_clipboard (gnome_db_sql_editor_get_text_view(
+ GNOME_DB_SQL_EDITOR(sql_view->priv->text)));
}
void
components_sql_view_copy_clipboard (ComponentsSqlView *sql_view)
{
g_return_if_fail (COMPONENTS_IS_SQL_VIEW (sql_view));
- gnome_db_text_copy_clipboard (GTK_TEXT_VIEW (sql_view->priv->text));
+ gnome_db_text_copy_clipboard (gnome_db_sql_editor_get_text_view(
+ GNOME_DB_SQL_EDITOR(sql_view->priv->text)));
}
void
components_sql_view_paste_clipboard (ComponentsSqlView *sql_view)
{
g_return_if_fail (COMPONENTS_IS_SQL_VIEW (sql_view));
- gnome_db_text_paste_clipboard (GTK_TEXT_VIEW (sql_view->priv->text));
+ gnome_db_text_paste_clipboard (gnome_db_sql_editor_get_text_view(
+ GNOME_DB_SQL_EDITOR(sql_view->priv->text)));
}
GdaConnection *
@@ -306,7 +226,8 @@
sql_view->priv->cnc = cnc;
- gnome_db_text_clear (GTK_TEXT_VIEW (sql_view->priv->text));
+ /* gnome_db_text_clear (gnome_db_sql_editor_get_text_view(
+ GNOME_DB_SQL_EDITOR(sql_view->priv->text))); */
gnome_db_grid_set_model (GNOME_DB_GRID (sql_view->priv->grid), NULL);
}
@@ -317,7 +238,8 @@
cmd = command_dialog_open ();
if (cmd) {
- gnome_db_text_set_text (GTK_TEXT_VIEW (sql_view->priv->text),
+ gnome_db_text_set_text (gnome_db_sql_editor_get_text_view(
+ GNOME_DB_SQL_EDITOR(sql_view->priv->text)),
cmd, strlen (cmd));
g_free (cmd);
}
@@ -335,7 +257,8 @@
if (!GDA_IS_CONNECTION (sql_view->priv->cnc))
return;
- sql_txt = gnome_db_text_get_text (GTK_TEXT_VIEW (sql_view->priv->text));
+ sql_txt = gnome_db_sql_editor_get_all_text (
+ GNOME_DB_SQL_EDITOR(sql_view->priv->text));
if (!sql_txt || strlen (sql_txt) <= 0)
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]