]> saetta.ns0.it Git - libgdaex/commitdiff
Added save to xml and load from xml buttons to query editor test.
authorAndrea Zagli <azagli@libero.it>
Mon, 7 Mar 2011 15:26:37 +0000 (16:26 +0100)
committerAndrea Zagli <azagli@libero.it>
Mon, 7 Mar 2011 15:26:37 +0000 (16:26 +0100)
Bugfixes on buttons remove.

src/queryeditor.c
tests/query_editor.c

index f0eb6ee0dcadcc08b618fdaa0ad200ababfc80a3..139b89b69f9cd09df9fbaa35d8b46b87ea3382a5 100644 (file)
@@ -1732,6 +1732,9 @@ gdaex_query_editor_on_sel_where_changed (GtkTreeSelection *treeselection,
        GdaExQueryEditor *qe = (GdaExQueryEditor *)user_data;
        GdaExQueryEditorPrivate *priv = GDAEX_QUERY_EDITOR_GET_PRIVATE (qe);
 
+       gtk_widget_hide (priv->vbx_values_container);
+       gdaex_query_editor_remove_child_from_vbx_values (qe);
+
        if (gtk_tree_selection_get_selected (priv->sel_where, NULL, &iter))
                {
                        priv->where_value = TRUE;
@@ -1751,8 +1754,6 @@ gdaex_query_editor_on_sel_where_changed (GtkTreeSelection *treeselection,
                        table = g_hash_table_lookup (priv->tables, table_name);
                        field = g_hash_table_lookup (table->fields, field_name);
 
-                       gdaex_query_editor_remove_child_from_vbx_values (qe);
-
                        priv->hbox = gtk_hbox_new (TRUE, 0);
 
                        tbl = gtk_table_new (2, 6, FALSE);
@@ -2054,6 +2055,9 @@ gdaex_query_editor_on_sel_order_changed (GtkTreeSelection *treeselection,
        GdaExQueryEditor *qe = (GdaExQueryEditor *)user_data;
        GdaExQueryEditorPrivate *priv = GDAEX_QUERY_EDITOR_GET_PRIVATE (qe);
 
+       gtk_widget_hide (priv->vbx_values_container);
+       gdaex_query_editor_remove_child_from_vbx_values (qe);
+
        if (gtk_tree_selection_get_selected (priv->sel_order, NULL, &iter))
                {
                        priv->where_value = FALSE;
@@ -2066,8 +2070,6 @@ gdaex_query_editor_on_sel_order_changed (GtkTreeSelection *treeselection,
                                            COL_ORDER_ORDER, &order,
                                            -1);
 
-                       gdaex_query_editor_remove_child_from_vbx_values (qe);
-
                        priv->hbox = gtk_hbox_new (TRUE, 5);
 
                        lbl = gtk_label_new (field_name);
index 60a0d89995ec0ab7dc5781a524d92c2dffe2ae3d..8ae312115161be2c98f919b69c38f76e1d7e3626 100644 (file)
 
 GtkWidget *w;
 
+static void
 on_btn_clean_clicked (GtkButton *button,
                       gpointer user_data)
 {
        gdaex_query_editor_clean_choices ((GdaExQueryEditor *)user_data);
 }
 
+static void
+on_btn_save_xml_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+       xmlDoc *doc;
+       xmlNode *node;
+       GtkWidget *dialog;
+
+       doc = xmlNewDoc ("1.0");
+       node = gdaex_query_editor_get_sql_as_xml ((GdaExQueryEditor *)user_data);
+       xmlDocSetRootElement (doc, node);
+
+       dialog = gtk_file_chooser_dialog_new ("Save xml to...",
+                                             GTK_WINDOW (w),
+                                             GTK_FILE_CHOOSER_ACTION_SAVE,
+                                             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                             GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+                                             NULL);
+       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+               {
+                       gchar *filename;
+                       filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+                       xmlSaveFormatFile (filename, doc, 2);
+                       g_free (filename);
+               }
+       gtk_widget_destroy (dialog);
+}
+
+static void
+on_btn_load_xml_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+       GtkWidget *dialog;
+       xmlDoc *doc;
+       xmlNode *node;
+
+       dialog = gtk_file_chooser_dialog_new ("Load xml from...",
+                                             GTK_WINDOW (w),
+                                             GTK_FILE_CHOOSER_ACTION_OPEN,
+                                             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                             GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+                                             NULL);
+       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+               {
+                       gchar *filename;
+                       filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+                       doc = xmlParseDoc (filename);
+                       node = xmlDocGetRootElement (doc);
+                       gdaex_query_editor_load_choices_from_xml ((GdaExQueryEditor *)user_data, node, TRUE);
+                       g_free (filename);
+               }
+       gtk_widget_destroy (dialog);
+}
+
+static void
 on_btn_get_sql_clicked (GtkButton *button,
                       gpointer user_data)
 {
@@ -74,6 +130,8 @@ main (int argc, char *argv[])
        GtkWidget *hbtnbox;
        GtkWidget *btn_clean;
        GtkWidget *btn_get_sql;
+       GtkWidget *btn_save_xml;
+       GtkWidget *btn_load_xml;
        GtkWidget *btn_ok;
 
        gtk_init (&argc, &argv);
@@ -194,6 +252,16 @@ main (int argc, char *argv[])
        g_signal_connect (G_OBJECT (btn_get_sql), "clicked",
                          G_CALLBACK (on_btn_get_sql_clicked), qe);
 
+       btn_save_xml = gtk_button_new_from_stock ("gtk-save");
+       gtk_box_pack_start (GTK_BOX (hbtnbox), btn_save_xml, TRUE, TRUE, 5);
+       g_signal_connect (G_OBJECT (btn_save_xml), "clicked",
+                         G_CALLBACK (on_btn_save_xml_clicked), qe);
+
+       btn_load_xml = gtk_button_new_from_stock ("gtk-open");
+       gtk_box_pack_start (GTK_BOX (hbtnbox), btn_load_xml, TRUE, TRUE, 5);
+       g_signal_connect (G_OBJECT (btn_load_xml), "clicked",
+                         G_CALLBACK (on_btn_load_xml_clicked), qe);
+
        btn_ok = gtk_button_new_from_stock ("gtk-close");
        gtk_box_pack_start (GTK_BOX (hbtnbox), btn_ok, TRUE, TRUE, 5);
        g_signal_connect (G_OBJECT (btn_ok), "clicked",