[libgda] Separated XML and UI spec. editors in GdaBrowser's DataManager perspective
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Separated XML and UI spec. editors in GdaBrowser's DataManager perspective
- Date: Sun, 1 Aug 2010 15:52:52 +0000 (UTC)
commit 4af285000e1bf6fea9f85de53356bdc55ef9b377
Author: Vivien Malerba <malerba gnome-db org>
Date: Sun Aug 1 10:35:30 2010 +0200
Separated XML and UI spec. editors in GdaBrowser's DataManager perspective
tools/browser/data-manager/Makefile.am | 6 +-
tools/browser/data-manager/data-console.c | 89 ++++++-----
tools/browser/data-manager/spec-editor.h | 68 --------
tools/browser/data-manager/ui-spec-editor.c | 139 +++++++++++++++
tools/browser/data-manager/ui-spec-editor.h | 57 ++++++
.../{spec-editor.c => xml-spec-editor.c} | 179 +++++++++-----------
tools/browser/data-manager/xml-spec-editor.h | 60 +++++++
7 files changed, 386 insertions(+), 212 deletions(-)
---
diff --git a/tools/browser/data-manager/Makefile.am b/tools/browser/data-manager/Makefile.am
index 208ed9c..7548c98 100644
--- a/tools/browser/data-manager/Makefile.am
+++ b/tools/browser/data-manager/Makefile.am
@@ -28,8 +28,10 @@ libperspective_la_SOURCES = \
data-favorite-selector.h \
perspective-main.c \
perspective-main.h \
- spec-editor.c \
- spec-editor.h \
+ xml-spec-editor.c \
+ xml-spec-editor.h \
+ ui-spec-editor.c \
+ ui-spec-editor.h \
data-manager-perspective.h \
data-manager-perspective.c \
data-source-manager.h \
diff --git a/tools/browser/data-manager/data-console.c b/tools/browser/data-manager/data-console.c
index 19b42a0..5ba0ac1 100644
--- a/tools/browser/data-manager/data-console.c
+++ b/tools/browser/data-manager/data-console.c
@@ -24,7 +24,8 @@
#include <string.h>
#include "data-console.h"
#include "data-widget.h"
-#include "spec-editor.h"
+#include "xml-spec-editor.h"
+#include "ui-spec-editor.h"
#include "../dnd.h"
#include "../support.h"
#include "../cc-gray-bar.h"
@@ -36,8 +37,11 @@
#include <libgda-ui/libgda-ui.h>
#include "data-source-manager.h"
-#define PAGE_XML 0
-#define PAGE_DATA 1
+#define MAIN_PAGE_EDITORS 0
+#define MAIN_PAGE_DATA 1
+
+#define EDITOR_PAGE_XML 0
+#define EDITOR_PAGE_UI 1
typedef enum {
LAYOUT_HORIZ,
@@ -49,10 +53,16 @@ struct _DataConsolePrivate {
LayoutType layout_type;
BrowserConnection *bcnc;
- GtkWidget *notebook;
- SpecEditor *sped;
- GtkWidget *data_box; /* in notebook */
+
+ GtkWidget *main_notebook; /* 2 pages: MAIN_PAGE_EDITORS & MAIN_PAGE_DATA */
+ GtkWidget *editors_notebook; /* 2 pages: EDITOR_PAGE_XML & EDITOR_PAGE_UI */
+
+ GtkWidget *data_box; /* in main_notebook */
GtkWidget *data;
+
+ GtkWidget *xml_sped; /* in editors_notebook */
+ GtkWidget *ui_sped; /* in editors_notebook */
+
GtkActionGroup *agroup;
gboolean toggling;
@@ -60,6 +70,7 @@ struct _DataConsolePrivate {
GtkWidget *params_top;
GtkWidget *params_form_box;
GtkWidget *params_form;
+
};
static void data_console_class_init (DataConsoleClass *klass);
@@ -242,29 +253,29 @@ data_console_new (BrowserConnection *bcnc)
gtk_container_add (GTK_CONTAINER (dconsole->priv->params_form_box), label);
dconsole->priv->params_form = label;
- /* main contents */
+ /* main contents: 1 page for editors and 1 for execution widget */
nb = gtk_notebook_new ();
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nb), FALSE);
gtk_paned_pack2 (GTK_PANED (hpaned), nb, TRUE, FALSE);
- dconsole->priv->notebook = nb;
+ dconsole->priv->main_notebook = nb;
- /* editor page */
+ /* editors page */
GtkWidget *hbox;
vbox = gtk_vbox_new (FALSE, 0);
- gtk_notebook_append_page (GTK_NOTEBOOK (nb), vbox, NULL);
-
- label = gtk_label_new ("");
- str = g_strdup_printf ("<b>%s</b>", _("SQL code to execute:"));
- gtk_label_set_markup (GTK_LABEL (label), str);
- g_free (str);
- gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
- gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+ gtk_notebook_append_page (GTK_NOTEBOOK (dconsole->priv->main_notebook), vbox, NULL);
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
- dconsole->priv->sped = spec_editor_new (dconsole->priv->mgr);
- gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (dconsole->priv->sped), TRUE, TRUE, 0);
+ nb = gtk_notebook_new ();
+ gtk_box_pack_start (GTK_BOX (hbox), nb, TRUE, TRUE, 0);
+ gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nb), FALSE);
+ gtk_notebook_set_show_border (GTK_NOTEBOOK (nb), FALSE);
+ dconsole->priv->editors_notebook = nb;
+
+ dconsole->priv->xml_sped = xml_spec_editor_new (dconsole->priv->mgr);
+ gtk_notebook_append_page (GTK_NOTEBOOK (dconsole->priv->editors_notebook),
+ dconsole->priv->xml_sped, NULL);
#define DEFAULT_XML \
"<data>\n" \
@@ -290,7 +301,11 @@ data_console_new (BrowserConnection *bcnc)
" </query>\n" \
"</data>"
- //spec_editor_set_xml_text (dconsole->priv->sped, DEFAULT_XML);
+ xml_spec_editor_set_xml_text (XML_SPEC_EDITOR (dconsole->priv->xml_sped), DEFAULT_XML);
+
+ dconsole->priv->ui_sped = ui_spec_editor_new (dconsole->priv->mgr);
+ gtk_notebook_append_page (GTK_NOTEBOOK (dconsole->priv->editors_notebook),
+ dconsole->priv->ui_sped, NULL);
/* buttons */
GtkWidget *bbox, *button;
@@ -318,9 +333,7 @@ data_console_new (BrowserConnection *bcnc)
button = browser_make_small_button (TRUE, _("View XML"), NULL, _("View specifications\n"
"as XML (advanced)"));
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
- spec_editor_get_mode (dconsole->priv->sped) == SPEC_EDITOR_XML ?
- TRUE : FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
g_signal_connect (button, "toggled",
G_CALLBACK (spec_editor_toggled_cb), dconsole);
@@ -337,7 +350,7 @@ data_console_new (BrowserConnection *bcnc)
vbox = gtk_vbox_new (FALSE, 0);
dconsole->priv->data_box = vbox;
- gtk_notebook_append_page (GTK_NOTEBOOK (nb), vbox, NULL);
+ gtk_notebook_append_page (GTK_NOTEBOOK (dconsole->priv->main_notebook), vbox, NULL);
wid = gtk_label_new ("");
str = g_strdup_printf ("<b>%s</b>", _("BBB:"));
@@ -382,10 +395,8 @@ variables_clicked_cb (GtkToggleButton *button, DataConsole *dconsole)
static void
spec_editor_toggled_cb (GtkToggleButton *button, DataConsole *dconsole)
{
- if (gtk_toggle_button_get_active (button))
- spec_editor_set_mode (dconsole->priv->sped, SPEC_EDITOR_XML);
- else
- spec_editor_set_mode (dconsole->priv->sped, SPEC_EDITOR_UI);
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (dconsole->priv->editors_notebook),
+ (gtk_toggle_button_get_active (button) ? EDITOR_PAGE_XML : EDITOR_PAGE_UI));
}
static void
@@ -420,8 +431,8 @@ data_source_mgr_changed_cb (DataSourceManager *mgr, DataConsole *dconsole)
static void
editor_clear_clicked_cb (GtkButton *button, DataConsole *dconsole)
{
- spec_editor_set_xml_text (dconsole->priv->sped, "");
- gtk_widget_grab_focus (GTK_WIDGET (dconsole->priv->sped));
+ xml_spec_editor_set_xml_text (XML_SPEC_EDITOR (dconsole->priv->xml_sped), "");
+ gtk_widget_grab_focus (dconsole->priv->xml_sped);
}
static GtkWidget *
@@ -464,8 +475,8 @@ compose_mode_toggled_cb (GtkToggleAction *action, DataConsole *dconsole)
return;
}
- pagenb = gtk_notebook_get_current_page (GTK_NOTEBOOK (dconsole->priv->notebook));
- if (pagenb == PAGE_XML) {
+ pagenb = gtk_notebook_get_current_page (GTK_NOTEBOOK (dconsole->priv->main_notebook));
+ if (pagenb == MAIN_PAGE_EDITORS) {
/* Get Data sources */
GArray *sources_array;
GError *lerror = NULL;
@@ -484,7 +495,7 @@ compose_mode_toggled_cb (GtkToggleAction *action, DataConsole *dconsole)
dconsole->priv->data = wid;
gtk_box_pack_start (GTK_BOX (dconsole->priv->data_box), wid, TRUE, TRUE, 0);
gtk_widget_show (wid);
- pagenb = PAGE_DATA;
+ pagenb = MAIN_PAGE_DATA;
}
}
if (lerror) {
@@ -493,17 +504,17 @@ compose_mode_toggled_cb (GtkToggleAction *action, DataConsole *dconsole)
_("Error parsing XML specifications"));
g_clear_error (&lerror);
}
- if (pagenb == PAGE_XML) {
+ if (pagenb == MAIN_PAGE_EDITORS) {
dconsole->priv->toggling = TRUE;
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
}
}
else {
/* simply change the current page */
- pagenb = PAGE_XML;
+ pagenb = MAIN_PAGE_EDITORS;
}
- gtk_notebook_set_current_page (GTK_NOTEBOOK (dconsole->priv->notebook), pagenb);
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (dconsole->priv->main_notebook), pagenb);
}
static GtkToggleActionEntry ui_actions[] = {
@@ -565,8 +576,8 @@ data_console_set_text (DataConsole *console, const gchar *text)
{
g_return_if_fail (IS_DATA_CONSOLE (console));
- spec_editor_set_xml_text (console->priv->sped, text);
- gtk_notebook_set_current_page (GTK_NOTEBOOK (console->priv->notebook), PAGE_XML);
+ xml_spec_editor_set_xml_text (XML_SPEC_EDITOR (console->priv->xml_sped), text);
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (console->priv->main_notebook), MAIN_PAGE_EDITORS);
}
/**
@@ -577,7 +588,7 @@ data_console_get_text (DataConsole *console)
{
g_return_val_if_fail (IS_DATA_CONSOLE (console), NULL);
- return spec_editor_get_xml_text (console->priv->sped);
+ return xml_spec_editor_get_xml_text (XML_SPEC_EDITOR (console->priv->xml_sped));
}
/**
diff --git a/tools/browser/data-manager/ui-spec-editor.c b/tools/browser/data-manager/ui-spec-editor.c
new file mode 100644
index 0000000..2e43b09
--- /dev/null
+++ b/tools/browser/data-manager/ui-spec-editor.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2010 The GNOME Foundation.
+ *
+ * AUTHORS:
+ * Vivien Malerba <malerba gnome-db org>
+ *
+ * This Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This Library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this Library; see the file COPYING.LIB. If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <glib/gi18n-lib.h>
+#include <string.h>
+#include "ui-spec-editor.h"
+#include "data-source.h"
+#include <libgda/libgda.h>
+#include "../support.h"
+
+#ifdef HAVE_GTKSOURCEVIEW
+#ifdef GTK_DISABLE_SINGLE_INCLUDES
+#undef GTK_DISABLE_SINGLE_INCLUDES
+#endif
+
+#include <gtksourceview/gtksourceview.h>
+#include <gtksourceview/gtksourcelanguagemanager.h>
+#include <gtksourceview/gtksourcebuffer.h>
+#include <gtksourceview/gtksourcestyleschememanager.h>
+#include <gtksourceview/gtksourcestylescheme.h>
+#endif
+
+struct _UiSpecEditorPrivate {
+ DataSourceManager *mgr;
+
+ /* warnings */
+ GtkWidget *info;
+};
+
+static void ui_spec_editor_class_init (UiSpecEditorClass *klass);
+static void ui_spec_editor_init (UiSpecEditor *sped, UiSpecEditorClass *klass);
+static void ui_spec_editor_dispose (GObject *object);
+
+static GObjectClass *parent_class = NULL;
+
+/*
+ * UiSpecEditor class implementation
+ */
+static void
+ui_spec_editor_class_init (UiSpecEditorClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ object_class->dispose = ui_spec_editor_dispose;
+}
+
+
+static void
+ui_spec_editor_init (UiSpecEditor *sped, UiSpecEditorClass *klass)
+{
+ g_return_if_fail (IS_UI_SPEC_EDITOR (sped));
+
+ /* allocate private structure */
+ sped->priv = g_new0 (UiSpecEditorPrivate, 1);
+}
+
+GType
+ui_spec_editor_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0)) {
+ static const GTypeInfo info = {
+ sizeof (UiSpecEditorClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) ui_spec_editor_class_init,
+ NULL,
+ NULL,
+ sizeof (UiSpecEditor),
+ 0,
+ (GInstanceInitFunc) ui_spec_editor_init
+ };
+ type = g_type_register_static (GTK_TYPE_VBOX, "UiSpecEditor", &info, 0);
+ }
+ return type;
+}
+
+static void
+ui_spec_editor_dispose (GObject *object)
+{
+ UiSpecEditor *sped = (UiSpecEditor*) object;
+ if (sped->priv) {
+ if (sped->priv->mgr)
+ g_object_unref (sped->priv->mgr);
+
+ g_free (sped->priv);
+ sped->priv = NULL;
+ }
+ parent_class->dispose (object);
+}
+
+
+/**
+ * ui_spec_editor_new
+ *
+ * Returns: the newly created editor.
+ */
+GtkWidget *
+ui_spec_editor_new (DataSourceManager *mgr)
+{
+ UiSpecEditor *sped;
+ GtkWidget *label;
+
+ g_return_val_if_fail (IS_DATA_SOURCE_MANAGER (mgr), NULL);
+
+ sped = g_object_new (UI_SPEC_EDITOR_TYPE, NULL);
+ sped->priv->mgr = g_object_ref (mgr);
+
+ label = gtk_label_new ("TODO");
+ gtk_box_pack_start (GTK_BOX (sped), label, TRUE, TRUE, 0);
+ gtk_widget_show (label);
+
+ /* warning */
+ sped->priv->info = NULL;
+
+ return (GtkWidget*) sped;
+}
diff --git a/tools/browser/data-manager/ui-spec-editor.h b/tools/browser/data-manager/ui-spec-editor.h
new file mode 100644
index 0000000..0c4bc37
--- /dev/null
+++ b/tools/browser/data-manager/ui-spec-editor.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2010 The GNOME Foundation.
+ *
+ * AUTHORS:
+ * Vivien Malerba <malerba gnome-db org>
+ *
+ * This Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This Library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this Library; see the file COPYING.LIB. If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __UI_SPEC_EDITOR_H__
+#define __UI_SPEC_EDITOR_H__
+
+#include <gtk/gtk.h>
+#include "../browser-connection.h"
+#include "data-source-manager.h"
+
+G_BEGIN_DECLS
+
+#define UI_SPEC_EDITOR_TYPE (ui_spec_editor_get_type())
+#define UI_SPEC_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, UI_SPEC_EDITOR_TYPE, UiSpecEditor))
+#define UI_SPEC_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, UI_SPEC_EDITOR_TYPE, UiSpecEditorClass))
+#define IS_UI_SPEC_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, UI_SPEC_EDITOR_TYPE))
+#define IS_UI_SPEC_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UI_SPEC_EDITOR_TYPE))
+
+
+typedef struct _UiSpecEditor UiSpecEditor;
+typedef struct _UiSpecEditorClass UiSpecEditorClass;
+typedef struct _UiSpecEditorPrivate UiSpecEditorPrivate;
+
+struct _UiSpecEditor {
+ GtkVBox parent;
+ UiSpecEditorPrivate *priv;
+};
+
+struct _UiSpecEditorClass {
+ GtkVBoxClass parent_class;
+};
+
+GType ui_spec_editor_get_type (void) G_GNUC_CONST;
+GtkWidget *ui_spec_editor_new (DataSourceManager *mgr);
+
+G_END_DECLS
+
+#endif
diff --git a/tools/browser/data-manager/spec-editor.c b/tools/browser/data-manager/xml-spec-editor.c
similarity index 63%
rename from tools/browser/data-manager/spec-editor.c
rename to tools/browser/data-manager/xml-spec-editor.c
index d5192c6..0bb15e4 100644
--- a/tools/browser/data-manager/spec-editor.c
+++ b/tools/browser/data-manager/xml-spec-editor.c
@@ -22,31 +22,29 @@
#include <glib/gi18n-lib.h>
#include <string.h>
-#include "spec-editor.h"
+#include "xml-spec-editor.h"
#include "data-source.h"
#include <libgda/libgda.h>
#include "../support.h"
#ifdef HAVE_GTKSOURCEVIEW
- #ifdef GTK_DISABLE_SINGLE_INCLUDES
- #undef GTK_DISABLE_SINGLE_INCLUDES
- #endif
-
- #include <gtksourceview/gtksourceview.h>
- #include <gtksourceview/gtksourcelanguagemanager.h>
- #include <gtksourceview/gtksourcebuffer.h>
- #include <gtksourceview/gtksourcestyleschememanager.h>
- #include <gtksourceview/gtksourcestylescheme.h>
+#ifdef GTK_DISABLE_SINGLE_INCLUDES
+#undef GTK_DISABLE_SINGLE_INCLUDES
#endif
-struct _SpecEditorPrivate {
- DataSourceManager *mgr;
-
- SpecEditorMode mode;
- GtkNotebook *notebook;
+#include <gtksourceview/gtksourceview.h>
+#include <gtksourceview/gtksourcelanguagemanager.h>
+#include <gtksourceview/gtksourcebuffer.h>
+#include <gtksourceview/gtksourcestyleschememanager.h>
+#include <gtksourceview/gtksourcestylescheme.h>
+#endif
- /* reference for all views */
- xmlDocPtr doc;
+struct _XmlSpecEditorPrivate {
+ DataSourceManager *mgr;
+
+ /* warnings */
+ GtkWidget *info;
+ GtkWidget *info_label;
/* XML view */
gboolean xml_view_up_to_date;
@@ -54,76 +52,70 @@ struct _SpecEditorPrivate {
GtkWidget *text;
GtkTextBuffer *buffer;
GtkWidget *help;
-
- /* UI view */
- gboolean ui_view_up_to_date;
};
-static void spec_editor_class_init (SpecEditorClass *klass);
-static void spec_editor_init (SpecEditor *sped, SpecEditorClass *klass);
-static void spec_editor_dispose (GObject *object);
+static void xml_spec_editor_class_init (XmlSpecEditorClass *klass);
+static void xml_spec_editor_init (XmlSpecEditor *sped, XmlSpecEditorClass *klass);
+static void xml_spec_editor_dispose (GObject *object);
static GObjectClass *parent_class = NULL;
/*
- * SpecEditor class implementation
+ * XmlSpecEditor class implementation
*/
static void
-spec_editor_class_init (SpecEditorClass *klass)
+xml_spec_editor_class_init (XmlSpecEditorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
- object_class->dispose = spec_editor_dispose;
+ object_class->dispose = xml_spec_editor_dispose;
}
static void
-spec_editor_init (SpecEditor *sped, SpecEditorClass *klass)
+xml_spec_editor_init (XmlSpecEditor *sped, XmlSpecEditorClass *klass)
{
- g_return_if_fail (IS_SPEC_EDITOR (sped));
+ g_return_if_fail (IS_XML_SPEC_EDITOR (sped));
/* allocate private structure */
- sped->priv = g_new0 (SpecEditorPrivate, 1);
+ sped->priv = g_new0 (XmlSpecEditorPrivate, 1);
sped->priv->signal_editor_changed_id = 0;
- sped->priv->mode = SPEC_EDITOR_XML;
}
GType
-spec_editor_get_type (void)
+xml_spec_editor_get_type (void)
{
static GType type = 0;
if (G_UNLIKELY (type == 0)) {
static const GTypeInfo info = {
- sizeof (SpecEditorClass),
+ sizeof (XmlSpecEditorClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
- (GClassInitFunc) spec_editor_class_init,
+ (GClassInitFunc) xml_spec_editor_class_init,
NULL,
NULL,
- sizeof (SpecEditor),
+ sizeof (XmlSpecEditor),
0,
- (GInstanceInitFunc) spec_editor_init
+ (GInstanceInitFunc) xml_spec_editor_init
};
- type = g_type_register_static (GTK_TYPE_VBOX, "SpecEditor", &info, 0);
+ type = g_type_register_static (GTK_TYPE_VBOX, "XmlSpecEditor", &info, 0);
}
return type;
}
static void
-spec_editor_dispose (GObject *object)
+xml_spec_editor_dispose (GObject *object)
{
- SpecEditor *sped = (SpecEditor*) object;
+ XmlSpecEditor *sped = (XmlSpecEditor*) object;
if (sped->priv) {
if (sped->priv->signal_editor_changed_id)
g_source_remove (sped->priv->signal_editor_changed_id);
if (sped->priv->mgr)
g_object_unref (sped->priv->mgr);
- if (sped->priv->doc)
- xmlFreeDoc (sped->priv->doc);
g_free (sped->priv);
sped->priv = NULL;
}
@@ -131,7 +123,7 @@ spec_editor_dispose (GObject *object)
}
static gboolean
-signal_editor_changed (SpecEditor *sped)
+signal_editor_changed (XmlSpecEditor *sped)
{
/* modify the DataSourceManager */
data_source_manager_remove_all (sped->priv->mgr);
@@ -189,16 +181,32 @@ signal_editor_changed (SpecEditor *sped)
out:
if (lerror) {
- TO_IMPLEMENT;
+ if (! sped->priv->info) {
+ sped->priv->info = gtk_info_bar_new ();
+ gtk_box_pack_start (GTK_BOX (sped), sped->priv->info, FALSE, FALSE, 0);
+ sped->priv->info_label = gtk_label_new ("");
+ gtk_misc_set_alignment (GTK_MISC (sped->priv->info_label), 0., -1);
+ gtk_label_set_ellipsize (GTK_LABEL (sped->priv->info_label), PANGO_ELLIPSIZE_END);
+ gtk_container_add (GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (sped->priv->info))),
+ sped->priv->info_label);
+ }
+ gchar *str;
+ str = g_strdup_printf (_("Error: %s"), lerror->message);
g_clear_error (&lerror);
+ gtk_label_set_text (GTK_LABEL (sped->priv->info_label), str);
+ g_free (str);
+ }
+ else if (sped->priv->info) {
+ gtk_widget_hide (sped->priv->info);
}
+
/* remove timeout */
sped->priv->signal_editor_changed_id = 0;
return FALSE;
}
static void
-editor_changed_cb (GtkTextBuffer *buffer, SpecEditor *sped)
+editor_changed_cb (GtkTextBuffer *buffer, XmlSpecEditor *sped)
{
if (sped->priv->signal_editor_changed_id)
g_source_remove (sped->priv->signal_editor_changed_id);
@@ -206,37 +214,36 @@ editor_changed_cb (GtkTextBuffer *buffer, SpecEditor *sped)
}
/**
- * spec_editor_new
+ * xml_spec_editor_new
*
* Returns: the newly created editor.
*/
-SpecEditor *
-spec_editor_new (DataSourceManager *mgr)
+GtkWidget *
+xml_spec_editor_new (DataSourceManager *mgr)
{
- SpecEditor *sped;
- GtkWidget *sw, *nb, *vbox;
+ XmlSpecEditor *sped;
+ GtkWidget *sw, *label;
+ gchar *str;
g_return_val_if_fail (IS_DATA_SOURCE_MANAGER (mgr), NULL);
- sped = g_object_new (SPEC_EDITOR_TYPE, NULL);
+ sped = g_object_new (XML_SPEC_EDITOR_TYPE, NULL);
sped->priv->mgr = g_object_ref (mgr);
- nb = gtk_notebook_new ();
- gtk_box_pack_start (GTK_BOX (sped), nb, TRUE, TRUE, 0);
- gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nb), FALSE);
- gtk_notebook_set_show_border (GTK_NOTEBOOK (nb), FALSE);
- sped->priv->notebook = (GtkNotebook*) nb;
-
- /* XML editor page */
- vbox = gtk_vbox_new (FALSE, 0);
- gtk_notebook_append_page (GTK_NOTEBOOK (nb), vbox, NULL);
+ /* XML editor */
+ label = gtk_label_new ("");
+ str = g_strdup_printf ("<b>%s</b>", _("SQL code to execute:"));
+ gtk_label_set_markup (GTK_LABEL (label), str);
+ g_free (str);
+ gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
+ gtk_box_pack_start (GTK_BOX (sped), label, FALSE, FALSE, 0);
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_OUT);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (sped), sw, TRUE, TRUE, 0);
#ifdef HAVE_GTKSOURCEVIEW
sped->priv->text = gtk_source_view_new ();
@@ -254,70 +261,36 @@ spec_editor_new (DataSourceManager *mgr)
g_signal_connect (sped->priv->buffer, "changed",
G_CALLBACK (editor_changed_cb), sped);
+ gtk_widget_show_all (sw);
- /* UI page */
- GtkWidget *wid;
- wid = gtk_label_new ("TODO");
- gtk_notebook_append_page (GTK_NOTEBOOK (nb), wid, NULL);
-
- gtk_widget_show_all (nb);
+ /* warning, not shown */
+ sped->priv->info = NULL;
- return SPEC_EDITOR (sped);
+ return (GtkWidget*) sped;
}
/**
- * spec_editor_set_xml_text
+ * xml_spec_editor_set_xml_text
*/
void
-spec_editor_set_xml_text (SpecEditor *sped, const gchar *xml)
+xml_spec_editor_set_xml_text (XmlSpecEditor *sped, const gchar *xml)
{
- g_return_if_fail (IS_SPEC_EDITOR (sped));
+ g_return_if_fail (IS_XML_SPEC_EDITOR (sped));
gtk_text_buffer_set_text (sped->priv->buffer, xml, -1);
signal_editor_changed (sped);
}
/**
- * spec_editor_get_xml_text
+ * xml_spec_editor_get_xml_text
*/
gchar *
-spec_editor_get_xml_text (SpecEditor *sped)
+xml_spec_editor_get_xml_text (XmlSpecEditor *sped)
{
GtkTextIter start, end;
- g_return_val_if_fail (IS_SPEC_EDITOR (sped), NULL);
+ g_return_val_if_fail (IS_XML_SPEC_EDITOR (sped), NULL);
gtk_text_buffer_get_start_iter (sped->priv->buffer, &start);
gtk_text_buffer_get_end_iter (sped->priv->buffer, &end);
return gtk_text_buffer_get_text (sped->priv->buffer, &start, &end, FALSE);
}
-
-/**
- * spec_editor_set_mode
- */
-void
-spec_editor_set_mode (SpecEditor *sped, SpecEditorMode mode)
-{
- g_return_if_fail (IS_SPEC_EDITOR (sped));
- switch (mode) {
- case SPEC_EDITOR_XML:
- gtk_notebook_set_current_page (sped->priv->notebook, 0);
- break;
- case SPEC_EDITOR_UI:
- gtk_notebook_set_current_page (sped->priv->notebook, 1);
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-}
-
-/**
- * spec_editor_get_mode
- */
-SpecEditorMode
-spec_editor_get_mode (SpecEditor *sped)
-{
- g_return_val_if_fail (IS_SPEC_EDITOR (sped), SPEC_EDITOR_UI);
- return sped->priv->mode;
-}
-
diff --git a/tools/browser/data-manager/xml-spec-editor.h b/tools/browser/data-manager/xml-spec-editor.h
new file mode 100644
index 0000000..0bf3726
--- /dev/null
+++ b/tools/browser/data-manager/xml-spec-editor.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2010 The GNOME Foundation.
+ *
+ * AUTHORS:
+ * Vivien Malerba <malerba gnome-db org>
+ *
+ * This Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This Library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this Library; see the file COPYING.LIB. If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __XML_SPEC_EDITOR_H__
+#define __XML_SPEC_EDITOR_H__
+
+#include <gtk/gtk.h>
+#include "../browser-connection.h"
+#include "data-source-manager.h"
+
+G_BEGIN_DECLS
+
+#define XML_SPEC_EDITOR_TYPE (xml_spec_editor_get_type())
+#define XML_SPEC_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, XML_SPEC_EDITOR_TYPE, XmlSpecEditor))
+#define XML_SPEC_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, XML_SPEC_EDITOR_TYPE, XmlSpecEditorClass))
+#define IS_XML_SPEC_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, XML_SPEC_EDITOR_TYPE))
+#define IS_XML_SPEC_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XML_SPEC_EDITOR_TYPE))
+
+
+typedef struct _XmlSpecEditor XmlSpecEditor;
+typedef struct _XmlSpecEditorClass XmlSpecEditorClass;
+typedef struct _XmlSpecEditorPrivate XmlSpecEditorPrivate;
+
+struct _XmlSpecEditor {
+ GtkVBox parent;
+ XmlSpecEditorPrivate *priv;
+};
+
+struct _XmlSpecEditorClass {
+ GtkVBoxClass parent_class;
+};
+
+GType xml_spec_editor_get_type (void) G_GNUC_CONST;
+GtkWidget *xml_spec_editor_new (DataSourceManager *mgr);
+
+void xml_spec_editor_set_xml_text (XmlSpecEditor *sped, const gchar *xml);
+gchar *xml_spec_editor_get_xml_text (XmlSpecEditor *sped);
+
+G_END_DECLS
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]