]> saetta.ns0.it Git - zakform/libzakform/commitdiff
Added function ZakForm::remove_element_by_id (refs #1104).
authorAndrea Zagli <azagli@libero.it>
Wed, 9 Aug 2017 13:39:57 +0000 (15:39 +0200)
committerAndrea Zagli <azagli@libero.it>
Wed, 9 Aug 2017 13:39:57 +0000 (15:39 +0200)
src/form.c
src/form.h

index 7fd21a0c249a92b0b528f570e771972b2532aca0..a4135fefcab17485ba35c4d6317132a3298ca6cd 100644 (file)
@@ -305,6 +305,41 @@ zak_form_form_add_element (ZakFormForm *zakform, ZakFormElement *element)
        return ret;
 }
 
+/**
+ * zak_form_form_remove_element_by_id:
+ * @zakform:
+ * @id:
+ *
+ * Returns: #TRUE if @element is removed; FALSE otherwise.
+ */
+gboolean
+zak_form_form_remove_element_by_id (ZakFormForm *zakform, const gchar *id)
+{
+       gboolean ret;
+
+       ZakFormFormPrivate *priv;
+
+       guint i;
+
+       priv = zak_form_form_get_instance_private (zakform);
+
+       ret = FALSE;
+
+       for (i = 0; i < priv->ar_elements->len; i++)
+               {
+                       ZakFormElement *element = (ZakFormElement *)g_ptr_array_index (priv->ar_elements, i);
+
+                       if (g_strcmp0 (zak_form_element_get_name (element), id) == 0)
+                               {
+                                       g_ptr_array_remove_index (priv->ar_elements, i);
+                                       ret = TRUE;
+                                       break;
+                               }
+               }
+
+       return ret;
+}
+
 /**
  * zak_form_form_get_element_by_id:
  * @zakform:
index dacd822a542e6a6f9a1b3da09f23224aa4c34be4..2ccc2ca16444c073e716c4678e57f77af4c2ce6a 100644 (file)
@@ -49,6 +49,7 @@ gboolean zak_form_form_load_from_xml (ZakFormForm *zakform, xmlDoc *xmldoc);
 gboolean zak_form_form_load_from_file (ZakFormForm *zakform, const gchar *filename);
 
 gboolean zak_form_form_add_element (ZakFormForm *zakform, ZakFormElement *element);
+gboolean zak_form_form_remove_element_by_id (ZakFormForm *zakform, const gchar *id);
 ZakFormElement *zak_form_form_get_element_by_id (ZakFormForm *zakform, const gchar *id);
 GPtrArray *zak_form_form_get_elements (ZakFormForm *zakform);
 GPtrArray *zak_form_form_get_elements_by_type (ZakFormForm *zakform, GType type);