]> saetta.ns0.it Git - solipa/organigramma/commitdiff
Gestione ad albero dei nodi.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 12 Aug 2010 14:27:42 +0000 (16:27 +0200)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 12 Aug 2010 14:27:42 +0000 (16:27 +0200)
data/organigramma/gui/organigramma.gui
src/nodi.c
src/nodo.c

index 53049b53d7990d7d40cdeef3e83323f7ff50ad03..7090abdbde891747d27735d04e06a3fac0ea8cdd 100644 (file)
                     <property name="can_focus">True</property>
                     <property name="editable">False</property>
                     <property name="invisible_char">&#x25CF;</property>
+                    <property name="secondary_icon_stock">gtk-clear</property>
+                    <property name="secondary_icon_activatable">True</property>
+                    <property name="secondary_icon_sensitive">True</property>
                   </object>
                   <packing>
                     <property name="position">0</property>
             </child>
             <child>
               <object class="GtkLabel" id="label6">
+                <property name="visible">True</property>
                 <property name="xalign">0</property>
                 <property name="label" translatable="yes">lbl_id</property>
               </object>
index d6a5101b563637dde0bd4352478b0f332b3b33a5..edae1f8d82b8bc5b9d155e77bcc1fcc6d8855ef3 100644 (file)
@@ -199,20 +199,56 @@ GtkWidget
 
 /* PRIVATE */
 static void
-nodi_carica (Nodi *nodi)
+nodi_carica_figli (Nodi *nodi, const gchar *sql_where, GtkTreeIter *iter_parent, guint id_nodi)
 {
        GtkTreeIter iter;
        GdaDataModel *dm;
 
-       gchar *sql_where;
        gchar *sql;
 
+       guint rows;
+       guint row;
+       guint id;
+
+       NodiPrivate *priv = NODI_GET_PRIVATE (nodi);
+
+       sql = g_strdup_printf ("SELECT c.id, c.nome"
+                         " FROM nodi c"
+                         " WHERE c.status <> 'E'"
+                         " AND %s"
+                         "%s"
+                         " ORDER BY c.nome",
+                         (id_nodi == 0 ? "(id_nodi IS NULL OR id_nodi = 0)" : g_strdup_printf ("id_nodi = %d", id_nodi)),
+                         sql_where);
+       dm = gdaex_query (priv->commons->gdaex, sql);
+       if (dm != NULL)
+               {
+                       rows = gda_data_model_get_n_rows (dm);
+                       for (row = 0; row < rows; row++)
+                               {
+                                       gtk_tree_store_append (priv->tstore_nodi, &iter, iter_parent);
+
+                                       id = gdaex_data_model_get_field_value_integer_at (dm, row, "id");
+                                       gtk_tree_store_set (priv->tstore_nodi, &iter,
+                                                           COL_ID, id,
+                                                           COL_NOME, gdaex_data_model_get_field_value_stringify_at (dm, row, "nome"),
+                                                           -1);
+
+                                       nodi_carica_figli (nodi, sql_where, &iter, id);
+                               }
+
+                       g_object_unref (dm);
+               }
+}
+
+static void
+nodi_carica (Nodi *nodi)
+{
+       gchar *sql_where;
+
        gchar *gcval;
        gint ival;
 
-       gint rows;
-       gint row;
-
        NodiPrivate *priv = NODI_GET_PRIVATE (nodi);
 
        gtk_tree_store_clear (priv->tstore_nodi);
@@ -254,27 +290,7 @@ nodi_carica (Nodi *nodi)
                                }
                }*/
 
-       sql = g_strdup_printf ("SELECT c.id, c.nome"
-                         " FROM nodi c"
-                         " WHERE c.status <> 'E'"
-                         "%s"
-                         " ORDER BY c.nome", sql_where);
-       dm = gdaex_query (priv->commons->gdaex, sql);
-       if (dm != NULL)
-               {
-                       rows = gda_data_model_get_n_rows (dm);
-                       for (row = 0; row < rows; row++)
-                               {
-                                       gtk_tree_store_append (priv->tstore_nodi, &iter, NULL);
-
-                                       gtk_tree_store_set (priv->tstore_nodi, &iter,
-                                                           COL_ID, gdaex_data_model_get_field_value_integer_at (dm, row, "id"),
-                                                           COL_NOME, gdaex_data_model_get_field_value_stringify_at (dm, row, "nome"),
-                                                           -1);
-                               }
-
-                       g_object_unref (dm);
-               }
+       nodi_carica_figli (nodi, sql_where, NULL, 0);
 }
 
 static void
@@ -308,7 +324,7 @@ nodi_modifica (Nodi *nodi)
                                                                                         GTK_DIALOG_DESTROY_WITH_PARENT,
                                                                                         GTK_MESSAGE_WARNING,
                                                                                         GTK_BUTTONS_OK,
-                                                                                        "Occorre prima selezionare un tipo nodo");
+                                                                                        "Occorre prima selezionare un nodo");
                        gtk_dialog_run (GTK_DIALOG (dialog));
                        gtk_widget_destroy (dialog);
                }
@@ -340,7 +356,7 @@ nodi_selezionato (Nodi *nodi)
                                                                                         GTK_DIALOG_DESTROY_WITH_PARENT,
                                                                                         GTK_MESSAGE_WARNING,
                                                                                         GTK_BUTTONS_OK,
-                                                                                        "Occorre prima selezionare un tipo nodo");
+                                                                                        "Occorre prima selezionare un nodo");
                        gtk_dialog_run (GTK_DIALOG (dialog));
                        gtk_widget_destroy (dialog);
                }
@@ -428,7 +444,8 @@ nodi_on_btn_elimina_clicked (GtkButton *button,
                                                         GTK_DIALOG_DESTROY_WITH_PARENT,
                                                         GTK_MESSAGE_QUESTION,
                                                         GTK_BUTTONS_YES_NO,
-                                                        "Sicuro di voler eliminare il tipo nodo selezionato?");
+                                                        "Sicuro di voler eliminare il nodo selezionato?\n\n"
+                                                        "ATTENZIONE: i nodi figli non saranno piĆ¹ visibili; se occorre, spostarli prima.");
                        risp = gtk_dialog_run (GTK_DIALOG (dialog));
                        if (risp == GTK_RESPONSE_YES)
                                {
@@ -449,7 +466,7 @@ nodi_on_btn_elimina_clicked (GtkButton *button,
                                                         GTK_DIALOG_DESTROY_WITH_PARENT,
                                                         GTK_MESSAGE_WARNING,
                                                         GTK_BUTTONS_OK,
-                                                        "Occorre prima selezionare un tipo nodo");
+                                                        "Occorre prima selezionare un nodo");
                        gtk_dialog_run (GTK_DIALOG (dialog));
                        gtk_widget_destroy (dialog);
                }
index 0ba1dbb2099bb1b270fdfafe8e2d5951d1e2d47d..2acd031809a4f9ff1229e1fe9be131c03093a691 100644 (file)
@@ -41,6 +41,10 @@ static void nodo_get_property (GObject *object,
 
 static void nodo_on_nodo_selezionato (gpointer instance, guint id, gpointer user_data);
 
+static void nodo_on_nodo_pulisci (GtkEntry *entry,
+                          GtkEntryIconPosition icon_pos,
+                          GdkEvent *event,
+                          gpointer user_data);
 static void nodo_on_btn_nodo_clicked (GtkButton *button,
                       gpointer user_data);
 
@@ -151,6 +155,8 @@ Nodo
        g_signal_connect (priv->w,
                          "delete-event", G_CALLBACK (nodo_on_w_nodo_delete_event), (gpointer *)a);
 
+       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "entry2"),
+                         "icon-press", G_CALLBACK (nodo_on_nodo_pulisci), (gpointer *)a);
        g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button6"),
                          "clicked", G_CALLBACK (nodo_on_btn_nodo_clicked), (gpointer *)a);
 
@@ -331,6 +337,19 @@ nodo_on_nodo_selezionato (gpointer instance, guint id, gpointer user_data)
        gtk_form_widget_set_value_stringify (gtk_form_get_form_widget_from_name (priv->form, "label5"), g_strdup_printf ("%d", id));
 }
 
+static void
+nodo_on_nodo_pulisci (GtkEntry *entry,
+                          GtkEntryIconPosition icon_pos,
+                          GdkEvent *event,
+                          gpointer user_data)
+{
+       Nodo *f = (Nodo *)user_data;
+       NodoPrivate *priv = NODO_GET_PRIVATE (f);
+
+       gtk_label_set_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label5")), "");
+       gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (priv->commons->gtkbuilder, "entry2")), "");
+}
+
 static void
 nodo_on_btn_nodo_clicked (GtkButton *button,
                       gpointer user_data)