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

index bc3000b0cc6cf7b4f489499466788d81bf1cd1e0..2ca08098dca5762fbd955a4dcdfdb0ae7ef4c2bd 100644 (file)
@@ -390,6 +390,39 @@ ZakFormElement
        return ret;
 }
 
+/**
+ * zak_form_form_get_element_idx_by_id:
+ * @zakform:
+ * @id:
+ *
+ * Returns: the index of the #ZakFormElement with id @id.
+ */
+guint
+zak_form_form_get_element_idx_by_id (ZakFormForm *zakform, const gchar *id)
+{
+       guint ret;
+
+       ZakFormFormPrivate *priv;
+
+       guint i;
+
+       priv = zak_form_form_get_instance_private (zakform);
+
+       ret = -1;
+       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)
+                               {
+                                       ret = i;
+                                       break;
+                               }
+               }
+
+       return ret;
+}
+
 /**
  * zak_form_form_get_elements:
  * @zakform:
index f860fa7b5437ccb5c3a674bc88db2d6f0561e575..e141b5f4a239ae0c82ca94676f206e76975cc6d5 100644 (file)
@@ -52,6 +52,7 @@ gboolean zak_form_form_add_element (ZakFormForm *zakform, ZakFormElement *elemen
 gboolean zak_form_form_remove_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);
+guint zak_form_form_get_element_idx_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);