[dia/dia-next: 46/59] Fix parameters



commit 65bed9b9b9ca520041c924a6c9fe3aa116d02a54
Author: Zander Brown <zbrown gnome org>
Date:   Wed Jan 2 15:24:58 2019 +0000

    Fix parameters
    
    Parameters are now invisible to PyDia but PyDia is going to been binned sooner or later anyway

 data/dia-uml-operation-dialog.ui                   |   2 -
 data/dia-uml-operation-parameter-row.ui            |  63 +++++-----
 objects/UML/class_operations_dialog.c              |   2 +-
 objects/UML/dia-uml-class.c                        |   4 +-
 objects/UML/dia-uml-operation.c                    | 134 ++++++++++++---------
 objects/UML/dia-uml-operation.h                    |   7 +-
 objects/UML/dia-uml-parameter.c                    |  28 +++--
 objects/UML/editor/dia-uml-list-store.c            |  33 ++++-
 objects/UML/editor/dia-uml-operation-dialog.c      |  55 ++-------
 .../UML/editor/dia-uml-operation-parameter-row.c   |  91 ++++++++++----
 .../UML/editor/dia-uml-operation-parameter-row.h   |  15 +--
 11 files changed, 246 insertions(+), 188 deletions(-)
---
diff --git a/data/dia-uml-operation-dialog.ui b/data/dia-uml-operation-dialog.ui
index 99c531cb..9875896c 100644
--- a/data/dia-uml-operation-dialog.ui
+++ b/data/dia-uml-operation-dialog.ui
@@ -341,8 +341,6 @@
                             <property name="can_focus">False</property>
                             <property name="selection_mode">none</property>
                             <property name="activate_on_single_click">False</property>
-                            <signal name="add" handler="parameter_added" object="DiaUmlOperationDialog" 
swapped="yes"/>
-                            <signal name="remove" handler="parameter_removed" object="DiaUmlOperationDialog" 
swapped="yes"/>
                           </object>
                         </child>
                         <child type="label_item">
diff --git a/data/dia-uml-operation-parameter-row.ui b/data/dia-uml-operation-parameter-row.ui
index 34bfe435..a110608e 100644
--- a/data/dia-uml-operation-parameter-row.ui
+++ b/data/dia-uml-operation-parameter-row.ui
@@ -174,26 +174,6 @@
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="spacing">16</property>
-            <child>
-              <object class="GtkButton">
-                <property name="label" translatable="yes">Delete</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="halign">end</property>
-                <property name="valign">center</property>
-                <signal name="clicked" handler="gtk_widget_destroy" object="DiaUmlOperationParameterRow" 
swapped="yes"/>
-                <style>
-                  <class name="destructive-action"/>
-                </style>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="pack_type">end</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
             <child>
               <object class="GtkBox">
                 <property name="visible">True</property>
@@ -236,7 +216,27 @@
                 <property name="expand">False</property>
                 <property name="fill">True</property>
                 <property name="pack_type">end</property>
-                <property name="position">2</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton">
+                <property name="label" translatable="yes">Delete</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="halign">end</property>
+                <property name="valign">center</property>
+                <signal name="clicked" handler="remove_param" object="DiaUmlOperationParameterRow" 
swapped="yes"/>
+                <style>
+                  <class name="destructive-action"/>
+                </style>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="pack_type">end</property>
+                <property name="position">1</property>
               </packing>
             </child>
           </object>
@@ -246,13 +246,20 @@
           </packing>
         </child>
         <child>
-          <placeholder/>
-        </child>
-        <child>
-          <placeholder/>
-        </child>
-        <child>
-          <placeholder/>
+          <object class="GtkLabel" id="title">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">Parameter</property>
+            <property name="xalign">0</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">3</property>
+            <property name="width">3</property>
+          </packing>
         </child>
         <child>
           <placeholder/>
diff --git a/objects/UML/class_operations_dialog.c b/objects/UML/class_operations_dialog.c
index f8d38e6a..4cd89a34 100644
--- a/objects/UML/class_operations_dialog.c
+++ b/objects/UML/class_operations_dialog.c
@@ -36,7 +36,7 @@ _operations_read_from_dialog (UMLClass *umlclass,
                               UMLClassDialog *prop_dialog,
                               int connection_index)
 {
-  DiaUmlListStore *list_store;
+  GListModel *list_store;
   DiaUmlListData *itm;
   DiaObject *obj;
   DiaUmlClass *editor_state;
diff --git a/objects/UML/dia-uml-class.c b/objects/UML/dia-uml-class.c
index 3d8be33e..fc537b9d 100644
--- a/objects/UML/dia-uml-class.c
+++ b/objects/UML/dia-uml-class.c
@@ -186,9 +186,7 @@ dia_uml_class_load (DiaUmlClass *self,
     DiaUmlOperation *op = (DiaUmlOperation *)list->data;
     DiaUmlOperation *copy = dia_uml_operation_copy (op);
 
-    /* Looks wrong but is required for the complicate connections memory management */
-    copy->l_connection = op->l_connection;
-    copy->r_connection = op->r_connection;
+    dia_uml_operation_connection_thing (copy, op);
 
     dia_uml_list_store_add (self->operations, DIA_UML_LIST_DATA (copy));
     list = g_list_next(list);
diff --git a/objects/UML/dia-uml-operation.c b/objects/UML/dia-uml-operation.c
index bcee16ea..60efad0d 100644
--- a/objects/UML/dia-uml-operation.c
+++ b/objects/UML/dia-uml-operation.c
@@ -55,6 +55,7 @@ for c in theClasses :
 #include "properties.h"
 #include "dia-uml-operation.h"
 #include "editor/dia-uml-list-data.h"
+#include "editor/dia-uml-list-store.h"
 
 static void
 dia_uml_operation_list_data_init (DiaUmlListDataInterface *iface);
@@ -97,8 +98,10 @@ static PropDescription umloperation_props[] = {
   N_("Query"), NULL, N_("C++ const method") },
   { "class_scope", PROP_TYPE_BOOL, PROP_FLAG_VISIBLE | PROP_FLAG_OPTIONAL,
   N_("Scope"), NULL, N_("Class scope (C++ static method)") },
+  /* It'a a ListModel not List now :-(
   { "parameters", PROP_TYPE_DARRAY, PROP_FLAG_VISIBLE | PROP_FLAG_OPTIONAL,
   N_("Parameters"), NULL, NULL },
+  */
 
   PROP_DESC_END
 };
@@ -112,7 +115,7 @@ static PropOffset umloperation_offsets[] = {
   { "inheritance_type", PROP_TYPE_ENUM, offsetof(DiaUmlOperation, inheritance_type) },
   { "query", PROP_TYPE_BOOL, offsetof(DiaUmlOperation, query) },
   { "class_scope", PROP_TYPE_BOOL, offsetof(DiaUmlOperation, class_scope) },
-  { "parameters", PROP_TYPE_DARRAY, offsetof(DiaUmlOperation, parameters) },
+  /*{ "parameters", PROP_TYPE_DARRAY, offsetof(DiaUmlOperation, parameters) },*/
   { NULL, 0, 0 },
 };
 
@@ -126,9 +129,9 @@ DiaUmlOperation *
 dia_uml_operation_copy (DiaUmlOperation *srcop)
 {
   DiaUmlOperation *destop;
-  DiaUmlParameter *param;
   DiaUmlParameter *newparam;
-  GList *list;
+  DiaUmlListData *itm;
+  int i = 0;
   
   destop = g_object_new (DIA_UML_TYPE_OPERATION, NULL);
 
@@ -171,16 +174,8 @@ dia_uml_operation_copy (DiaUmlOperation *srcop)
   destop->inheritance_type = srcop->inheritance_type;
   destop->query = srcop->query;
 
-  list = destop->parameters;
-  while (list != NULL) {
-    param = (DiaUmlParameter *)list->data;
-    dia_uml_operation_remove_parameter (destop, param);
-    list = g_list_next (list);
-  }
-  destop->parameters = NULL;
-  list = srcop->parameters;
-  while (list != NULL) {
-    param = (DiaUmlParameter *)list->data;
+  while ((itm = g_list_model_get_item (G_LIST_MODEL (srcop->parameters), i))) {
+    DiaUmlParameter *param = DIA_UML_PARAMETER (itm);
 
     newparam = dia_uml_parameter_new ();
     newparam->name = g_strdup(param->name);
@@ -189,9 +184,9 @@ dia_uml_operation_copy (DiaUmlOperation *srcop)
     newparam->value = g_strdup(param->value);
     newparam->kind = param->kind;
 
-    dia_uml_operation_insert_parameter (destop, newparam, -1);
+    dia_uml_operation_insert_parameter (destop, newparam, i);
     
-    list = g_list_next(list);
+    i++;
   }
 
   return destop;
@@ -210,11 +205,12 @@ dia_uml_operation_copy (DiaUmlOperation *srcop)
 void
 uml_operation_write(AttributeNode attr_node, DiaUmlOperation *op, DiaContext *ctx)
 {
-  GList *list;
   DiaUmlParameter *param;
   DataNode composite;
   DataNode composite2;
   AttributeNode attr_node2;
+  DiaUmlListData *itm;
+  int i = 0;
 
   composite = data_add_composite(attr_node, "umloperation", ctx);
 
@@ -240,9 +236,8 @@ uml_operation_write(AttributeNode attr_node, DiaUmlOperation *op, DiaContext *ct
   
   attr_node2 = composite_add_attribute(composite, "parameters");
   
-  list = op->parameters;
-  while (list != NULL) {
-    param = (DiaUmlParameter *) list->data;
+  while ((itm = g_list_model_get_item (G_LIST_MODEL (op->parameters), i))) {
+    param = DIA_UML_PARAMETER (itm);
 
     composite2 = data_add_composite(attr_node2, "umlparameter", ctx);
 
@@ -256,7 +251,7 @@ uml_operation_write(AttributeNode attr_node, DiaUmlOperation *op, DiaContext *ct
                    param->comment, ctx);
     data_add_enum(composite_add_attribute(composite2, "kind"),
                  param->kind, ctx);
-    list = g_list_next(list);
+    i++;
   }
 }
 
@@ -267,20 +262,26 @@ dia_uml_operation_format (DiaUmlOperation *operation)
 {
   int len;
   char *str;
-  GList *list;
-  DiaUmlParameter *param;
+  DiaUmlListData *itm;
+  int i = 0;
+  gboolean first = TRUE;
 
   /* Calculate length: */
   len = 1 + (operation->name ? strlen (operation->name) : 0) + 1;
   if(operation->stereotype != NULL && operation->stereotype[0] != '\0') {
     len += 5 + strlen (operation->stereotype);
-  }   
+  }
   
-  list = operation->parameters;
-  while (list != NULL) {
-    param = (DiaUmlParameter  *) list->data;
-    list = g_list_next (list);
+  first = TRUE;
+  while ((itm = g_list_model_get_item (G_LIST_MODEL (operation->parameters), i))) {
+    DiaUmlParameter *param = DIA_UML_PARAMETER (itm);
+    i++;
     
+    if (!first) {
+      len += 1; /* ',' */
+    }
+    first = FALSE;
+
     switch(param->kind)
       {
       case UML_UNDEF_KIND:
@@ -305,10 +306,6 @@ dia_uml_operation_format (DiaUmlOperation *operation)
     if (param->value != NULL && param->value[0] != '\0') {
       len += 1 + strlen (param->value);
     }
-    
-    if (list != NULL) {
-      len += 1; /* ',' */
-    }
   }
 
   len += 1; /* ')' */
@@ -335,11 +332,17 @@ dia_uml_operation_format (DiaUmlOperation *operation)
   strcat (str, operation->name ? operation->name : "");
   strcat (str, "(");
   
-  list = operation->parameters;
-  while (list != NULL) {
-    param = (DiaUmlParameter  *) list->data;
-    list = g_list_next (list);
+  i = 0;
+  first = TRUE;
+  while ((itm = g_list_model_get_item (G_LIST_MODEL (operation->parameters), i))) {
+    DiaUmlParameter *param = DIA_UML_PARAMETER (itm);
+    i++;
     
+    if (!first) {
+      strcat (str, ",");
+    }
+    first = FALSE;
+
     switch(param->kind)
       {
       case UML_UNDEF_KIND:
@@ -367,10 +370,6 @@ dia_uml_operation_format (DiaUmlOperation *operation)
       strcat (str, "=");
       strcat (str, param->value);
     }
-
-    if (list != NULL) {
-      strcat (str, ",");
-    }
   }
   strcat (str, ")");
 
@@ -415,6 +414,16 @@ dia_uml_operation_ensure_connection_points (DiaUmlOperation* op, DiaObject* obj)
   op->r_connection->object = obj;
 }
 
+/* No idea why this is needed */
+void
+dia_uml_operation_connection_thing (DiaUmlOperation *self,
+                                    DiaUmlOperation *from)
+{
+  /* Looks wrong but is required for the complicate connections memory management */
+  self->l_connection = from->l_connection;
+  self->r_connection = from->r_connection;
+}
+
 static void
 dia_uml_operation_finalize (GObject *object)
 {
@@ -425,7 +434,7 @@ dia_uml_operation_finalize (GObject *object)
   g_free (self->stereotype);
   g_free (self->comment);
 
-  g_list_free_full (self->parameters, g_object_unref);
+  g_clear_object (&self->parameters);
   if (self->wrappos) {
     g_list_free (self->wrappos);
   }
@@ -603,6 +612,24 @@ dia_uml_operation_class_init (DiaUmlOperationClass *klass)
                                      uml_op_properties);
 }
 
+static void
+bubble (DiaUmlListStore *store,
+        DiaUmlListData  *itm,
+        DiaUmlOperation *self)
+{
+  dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
+}
+
+static void
+items_changed (GListModel      *list,
+               guint            position,
+               guint            removed,
+               guint            added,
+               DiaUmlOperation *self)
+{
+  dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
+}
+
 static void
 dia_uml_operation_init (DiaUmlOperation *self)
 {
@@ -616,6 +643,11 @@ dia_uml_operation_init (DiaUmlOperation *self)
   self->stereotype = g_strdup("");
   self->visibility = UML_PUBLIC;
   self->inheritance_type = UML_LEAF;
+  self->parameters = dia_uml_list_store_new ();
+  g_signal_connect (self->parameters, "changed",
+                    G_CALLBACK (bubble), self);
+  g_signal_connect (self->parameters, "items-changed",
+                    G_CALLBACK (items_changed), self);
 }
 
 DiaUmlOperation *
@@ -624,37 +656,23 @@ dia_uml_operation_new ()
   return g_object_new (DIA_UML_TYPE_OPERATION, NULL);
 }
 
-static void
-bubble (DiaUmlParameter *para,
-        DiaUmlOperation *self)
-{
-  dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
-}
-
 void
 dia_uml_operation_insert_parameter (DiaUmlOperation *self,
                                     DiaUmlParameter *parameter,
                                     int              index)
 {
-  self->parameters = g_list_insert (self->parameters,
-                                    g_object_ref (parameter),
-                                    index);
-  g_signal_connect (G_OBJECT (parameter), "changed", G_CALLBACK (bubble), self);
-  dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
+  dia_uml_list_store_insert (self->parameters, DIA_UML_LIST_DATA (parameter), index);
 }
 
 void
 dia_uml_operation_remove_parameter (DiaUmlOperation *self,
                                     DiaUmlParameter *parameter)
 {
-  self->parameters = g_list_remove (self->parameters, parameter);
-  g_signal_handlers_disconnect_by_func (G_OBJECT (parameter), G_CALLBACK (bubble), self);
-  g_object_unref (parameter);
-  dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
+  dia_uml_list_store_remove (self->parameters, DIA_UML_LIST_DATA (parameter));
 }
 
-GList *
+GListModel *
 dia_uml_operation_get_parameters (DiaUmlOperation *self)
 {
-  return self->parameters;
+  return G_LIST_MODEL (self->parameters);
 }
diff --git a/objects/UML/dia-uml-operation.h b/objects/UML/dia-uml-operation.h
index 5fe448fd..79df9337 100644
--- a/objects/UML/dia-uml-operation.h
+++ b/objects/UML/dia-uml-operation.h
@@ -1,6 +1,7 @@
 #include <glib-object.h>
 #include "uml.h"
 #include "dia-uml-parameter.h"
+#include "editor/dia-uml-list-store.h"
 
 #ifndef UML_OP_H
 #define UML_OP_H
@@ -41,7 +42,7 @@ struct _DiaUmlOperation {
   UMLInheritanceType inheritance_type;
   int query; /**< Do not modify the object, in C++ this is a const function */
   int class_scope;
-  GList *parameters; /**< List of DiaUmlParameter */
+  DiaUmlListStore *parameters; /**< List of DiaUmlParameter */
 
   ConnectionPoint* l_connection; /**< left */
   ConnectionPoint* r_connection; /**< right */
@@ -59,11 +60,13 @@ gchar           *dia_uml_operation_format                   (DiaUmlOperation *op
 DiaUmlOperation *dia_uml_operation_copy                     (DiaUmlOperation *op);
 void             dia_uml_operation_ensure_connection_points (DiaUmlOperation *oper,
                                                              DiaObject       *obj);
+void             dia_uml_operation_connection_thing         (DiaUmlOperation *self,
+                                                             DiaUmlOperation *from);
 void             dia_uml_operation_insert_parameter         (DiaUmlOperation *self,
                                                              DiaUmlParameter *parameter,
                                                              int              index);
 void             dia_uml_operation_remove_parameter         (DiaUmlOperation *self,
                                                              DiaUmlParameter *parameter);
-GList           *dia_uml_operation_get_parameters           (DiaUmlOperation *self);
+GListModel      *dia_uml_operation_get_parameters           (DiaUmlOperation *self);
 
 #endif
\ No newline at end of file
diff --git a/objects/UML/dia-uml-parameter.c b/objects/UML/dia-uml-parameter.c
index c105e283..11f4752f 100644
--- a/objects/UML/dia-uml-parameter.c
+++ b/objects/UML/dia-uml-parameter.c
@@ -93,9 +93,13 @@ dia_uml_parameter_format (DiaUmlParameter *param)
   char *str;
 
   /* Calculate length: */
-  len = strlen (param->name) + 1 + strlen (param->type);
-  
-  if (param->value != NULL) {
+  len = strlen (param->name);
+
+  if (strlen (param->type) > 0) {
+    len += 1 + strlen (param->type) ;
+  }
+
+  if (strlen (param->value) > 0) {
     len += 1 + strlen (param->value) ;
   }
 
@@ -136,9 +140,13 @@ dia_uml_parameter_format (DiaUmlParameter *param)
   
 
   strcat (str, param->name);
-  strcat (str, ":");
-  strcat (str, param->type);
-  if (param->value != NULL) {
+
+  if (strlen (param->type) > 0) {
+    strcat (str, ":");
+    strcat (str, param->type);
+  }
+
+  if (strlen (param->value) > 0) {
     strcat (str, "=");
     strcat (str, param->value);
   }
@@ -230,10 +238,16 @@ dia_uml_parameter_get_property (GObject    *object,
   }
 }
 
+static const gchar *
+format (DiaUmlListData *self)
+{
+  return dia_uml_parameter_format (DIA_UML_PARAMETER (self));
+}
+
 static void
 dia_uml_parameter_list_data_init (DiaUmlListDataInterface *iface)
 {
-
+  iface->format = format;
 }
 
 static void
diff --git a/objects/UML/editor/dia-uml-list-store.c b/objects/UML/editor/dia-uml-list-store.c
index d547a1a8..ce4b0ab1 100644
--- a/objects/UML/editor/dia-uml-list-store.c
+++ b/objects/UML/editor/dia-uml-list-store.c
@@ -16,6 +16,12 @@ enum
   N_PROPERTIES
 };
 
+enum {
+  CHANGED,
+  LAST_SIGNAL
+};
+static guint signals[LAST_SIGNAL] = { 0 };
+
 static void dia_uml_list_store_iface_init (GListModelInterface *iface);
 
 G_DEFINE_TYPE_WITH_CODE (DiaUmlListStore, dia_uml_list_store, G_TYPE_OBJECT,
@@ -57,6 +63,14 @@ dia_uml_list_store_class_init (DiaUmlListStoreClass *klass)
   g_object_class_install_property (object_class, PROP_ITEM_TYPE,
     g_param_spec_gtype ("item-type", "", "", DIA_UML_TYPE_LIST_DATA,
                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+
+  signals[CHANGED] = g_signal_new ("changed",
+                                   G_TYPE_FROM_CLASS (klass),
+                                   G_SIGNAL_RUN_FIRST,
+                                   0, NULL, NULL, NULL,
+                                   G_TYPE_NONE, 1,
+                                   DIA_UML_TYPE_LIST_DATA);
 }
 
 static GType
@@ -108,6 +122,13 @@ dia_uml_list_store_new ()
   return g_object_new (DIA_UML_TYPE_LIST_STORE, NULL);
 }
 
+static void
+bubble_change (DiaUmlListData  *itm,
+               DiaUmlListStore *self)
+{
+  g_signal_emit (self, signals[CHANGED], 0, itm);
+}
+
 void
 dia_uml_list_store_insert (DiaUmlListStore *store,
                            DiaUmlListData  *item,
@@ -121,6 +142,7 @@ dia_uml_list_store_insert (DiaUmlListStore *store,
   }
 
   store->data = g_list_insert (store->data, g_object_ref (item), index);
+  g_signal_connect (G_OBJECT (item), "changed", G_CALLBACK (bubble_change), store);
 
   g_list_model_items_changed (G_LIST_MODEL (store), index, 0, 1);
 }
@@ -135,6 +157,7 @@ dia_uml_list_store_add (DiaUmlListStore *store,
 
   n_items = g_list_length (store->data);
   store->data = g_list_append (store->data, g_object_ref (item));
+  g_signal_connect (G_OBJECT (item), "changed", G_CALLBACK (bubble_change), store);
 
   g_list_model_items_changed (G_LIST_MODEL (store), n_items, 0, 1);
 }
@@ -149,6 +172,7 @@ dia_uml_list_store_remove (DiaUmlListStore *store,
 
   index = g_list_index (store->data, item);
   store->data = g_list_remove (store->data, item);
+  g_signal_handlers_disconnect_by_func (G_OBJECT (item), G_CALLBACK (bubble_change), store);
   g_object_unref (item);
 
   g_list_model_items_changed (G_LIST_MODEL (store), index, 1, 0);
@@ -158,11 +182,18 @@ void
 dia_uml_list_store_empty (DiaUmlListStore *store)
 {
   guint n_items;
+  GList *list;
 
   g_return_if_fail (DIA_UML_IS_LIST_STORE (store));
 
   n_items = g_list_length (store->data);
-  g_list_free_full (store->data, g_object_unref);
+  list = store->data;
+  while (list) {
+    g_signal_handlers_disconnect_by_func (G_OBJECT (list->data), G_CALLBACK (bubble_change), store);
+    g_object_unref (list->data);
+    list = g_list_next (list);
+  }
+  g_list_free (store->data);
   store->data = NULL;
 
   g_list_model_items_changed (G_LIST_MODEL (store), 0, n_items, 0);
diff --git a/objects/UML/editor/dia-uml-operation-dialog.c b/objects/UML/editor/dia-uml-operation-dialog.c
index 3bc919bf..b64cf4be 100644
--- a/objects/UML/editor/dia-uml-operation-dialog.c
+++ b/objects/UML/editor/dia-uml-operation-dialog.c
@@ -1,5 +1,6 @@
 #include "dia-uml-operation-dialog.h"
 #include "dia-uml-operation-parameter-row.h"
+#include "dia-uml-list-store.h"
 #include "dia_dirs.h"
 
 G_DEFINE_TYPE (DiaUmlOperationDialog, dia_uml_operation_dialog, GTK_TYPE_DIALOG)
@@ -111,8 +112,7 @@ dia_uml_operation_dialog_set_property (GObject      *object,
                                        GParamSpec   *pspec)
 {
   DiaUmlOperationDialog *self = DIA_UML_OPERATION_DIALOG (object);
-  GList *paras;
-  GtkWidget *row;
+  GListModel *paras;
 
   switch (property_id) {
     case UML_OP_DLG_PROP_OPERATION:
@@ -153,12 +153,9 @@ dia_uml_operation_dialog_set_property (GObject      *object,
 
       self->building = TRUE;
       paras = dia_uml_operation_get_parameters (self->operation);
-      for (; paras != NULL; paras = g_list_next (paras)) {
-        // do something with l->data
-        row = dia_uml_operation_parameter_row_new (DIA_UML_PARAMETER (paras->data));
-        gtk_widget_show (row);
-        gtk_container_add (GTK_CONTAINER (self->list), row);
-      }
+      gtk_list_box_bind_model (GTK_LIST_BOX (self->list), paras,
+                              (GtkListBoxCreateWidgetFunc) dia_uml_operation_parameter_row_new,
+                              paras, NULL);
       self->building = FALSE;
       break;
     default:
@@ -187,45 +184,9 @@ dia_uml_operation_dialog_get_property (GObject    *object,
 static void
 dlg_add_parameter (DiaUmlOperationDialog *self)
 {
-  GtkWidget *row = dia_uml_operation_parameter_row_new (dia_uml_parameter_new ());
+  DiaUmlParameter *para = dia_uml_parameter_new ();
 
-  g_assert (DIA_UML_IS_OPERATION_DIALOG (self));
-  gtk_widget_show (row);
-  gtk_container_add (GTK_CONTAINER (self->list), row);
-}
-
-static void
-parameter_added (DiaUmlOperationDialog *self,
-                 GtkWidget             *row)
-{
-  DiaUmlParameter *para = NULL;
-  int index;
-
-  if (!DIA_UML_IS_OPERATION_PARAMETER_ROW (row) || self->building)
-    return;
-
-  g_object_get (G_OBJECT (row),
-                "parameter", &para,
-                NULL);
-  index = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (row));
-
-  dia_uml_operation_insert_parameter (self->operation, para, index);
-}
-
-static void
-parameter_removed (DiaUmlOperationDialog *self,
-                   GtkWidget             *row)
-{
-  DiaUmlParameter *para = NULL;
-
-  if (!DIA_UML_IS_OPERATION_PARAMETER_ROW (row) || gtk_widget_in_destruction (GTK_WIDGET (self)))
-    return;
-
-  g_object_get (G_OBJECT (row),
-                "parameter", &para,
-                NULL);
-
-  dia_uml_operation_remove_parameter (self->operation, para);
+  dia_uml_operation_insert_parameter (self->operation, para, -1);
 }
 
 static void
@@ -286,8 +247,6 @@ dia_uml_operation_dialog_class_init (DiaUmlOperationDialogClass *klass)
   gtk_widget_class_bind_template_child (widget_class, DiaUmlOperationDialog, comment);
   gtk_widget_class_bind_template_child (widget_class, DiaUmlOperationDialog, list);
   gtk_widget_class_bind_template_callback (widget_class, dlg_add_parameter);
-  gtk_widget_class_bind_template_callback (widget_class, parameter_added);
-  gtk_widget_class_bind_template_callback (widget_class, parameter_removed);
   gtk_widget_class_bind_template_callback (widget_class, remove_operation);
 
   g_object_unref (template_file);
diff --git a/objects/UML/editor/dia-uml-operation-parameter-row.c 
b/objects/UML/editor/dia-uml-operation-parameter-row.c
index 15ed7881..157a51a5 100644
--- a/objects/UML/editor/dia-uml-operation-parameter-row.c
+++ b/objects/UML/editor/dia-uml-operation-parameter-row.c
@@ -1,11 +1,27 @@
 #include "dia-uml-parameter.h"
 #include "dia-uml-operation-parameter-row.h"
+#include "dia-uml-list-store.h"
 #include "dia_dirs.h"
 
+struct _DiaUmlOperationParameterRow {
+  GtkListBoxRow parent;
+
+  GtkWidget *title;
+  GtkWidget *name;
+  GtkWidget *type;
+  GtkWidget *value;
+  GtkWidget *direction;
+  GtkTextBuffer *comment;
+
+  DiaUmlParameter *parameter;
+  DiaUmlListStore *model;
+};
+
 G_DEFINE_TYPE (DiaUmlOperationParameterRow, dia_uml_operation_parameter_row, GTK_TYPE_LIST_BOX_ROW)
 
 enum {
   UML_OP_PROW_PROP_PARAMETER = 1,
+  UML_OP_PROW_PROP_MODEL,
   UML_OP_PROW_N_PROPS
 };
 static GParamSpec* uml_op_prow_properties[UML_OP_PROW_N_PROPS];
@@ -15,7 +31,8 @@ dia_uml_operation_parameter_row_finalize (GObject *object)
 {
   DiaUmlOperationParameterRow *self = DIA_UML_OPERATION_PARAMETER_ROW (object);
 
-  g_object_unref (self->parameter);
+  g_clear_object (&self->parameter);
+  g_clear_object (&self->model);
 }
 
 static gboolean
@@ -60,11 +77,19 @@ direction_from (GBinding *binding,
   return TRUE;
 }
 
+static void
+display_op (DiaUmlListData               *op,
+            DiaUmlOperationParameterRow  *row)
+{
+  gtk_label_set_label (GTK_LABEL (row->title),
+                       dia_uml_list_data_format (op));
+}
+
 static void
 dia_uml_operation_parameter_row_set_property (GObject      *object,
-                                       guint         property_id,
-                                       const GValue *value,
-                                       GParamSpec   *pspec)
+                                              guint         property_id,
+                                              const GValue *value,
+                                              GParamSpec   *pspec)
 {
   DiaUmlOperationParameterRow *self = DIA_UML_OPERATION_PARAMETER_ROW (object);
   switch (property_id) {
@@ -90,7 +115,12 @@ dia_uml_operation_parameter_row_set_property (GObject      *object,
       g_object_bind_property (G_OBJECT (self->parameter), "comment",
                               G_OBJECT (self->comment), "text",
                               G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
-
+      g_signal_connect (G_OBJECT (self->parameter), "changed",
+                        G_CALLBACK (display_op), self);
+      display_op (DIA_UML_LIST_DATA (self->parameter), self);
+      break;
+    case UML_OP_PROW_PROP_MODEL:
+      self->model = g_value_dup_object (value);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -109,6 +139,9 @@ dia_uml_operation_parameter_row_get_property (GObject    *object,
     case UML_OP_PROW_PROP_PARAMETER:
       g_value_set_object (value, self->parameter);
       break;
+    case UML_OP_PROW_PROP_MODEL:
+      g_value_set_object (value, self->model);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -118,36 +151,33 @@ dia_uml_operation_parameter_row_get_property (GObject    *object,
 static void
 move_up (DiaUmlOperationParameterRow *self)
 {
-  GtkWidget *list;
   int index;
 
-  /*
-   * If we ever find ourselves in something other than GtkListBox we are
-   * in trouble but as a GtkListBoxRow that shouldn't happen, storing the
-   * new state is left to the GtkListBox or it's owner
-   */
-  list = gtk_widget_get_parent (GTK_WIDGET (self));
   index = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (self));
 
-  g_object_ref (self);
-  gtk_container_remove (GTK_CONTAINER (list), GTK_WIDGET (self));
-  gtk_list_box_insert (GTK_LIST_BOX (list), GTK_WIDGET (self), index - 1);
-  g_object_unref (self);
+  g_object_ref (self->parameter);
+  dia_uml_list_store_remove (self->model, DIA_UML_LIST_DATA (self->parameter));
+  dia_uml_list_store_insert (self->model, DIA_UML_LIST_DATA (self->parameter), index - 1);
+  g_object_unref (self->parameter);
 }
 
 static void
 move_down (DiaUmlOperationParameterRow *self)
 {
-  GtkWidget *list;
   int index;
-  
-  list = gtk_widget_get_parent (GTK_WIDGET (self));
+
   index = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (self));
 
-  g_object_ref (self);
-  gtk_container_remove (GTK_CONTAINER (list), GTK_WIDGET (self));
-  gtk_list_box_insert (GTK_LIST_BOX (list), GTK_WIDGET (self), index + 1);
-  g_object_unref (self);
+  g_object_ref (self->parameter);
+  dia_uml_list_store_remove (self->model, DIA_UML_LIST_DATA (self->parameter));
+  dia_uml_list_store_insert (self->model, DIA_UML_LIST_DATA (self->parameter), index + 1);
+  g_object_unref (self->parameter);
+}
+
+static void
+remove_param (DiaUmlOperationParameterRow *self)
+{
+  dia_uml_list_store_remove (self->model, DIA_UML_LIST_DATA (self->parameter));
 }
 
 static void
@@ -170,6 +200,13 @@ dia_uml_operation_parameter_row_class_init (DiaUmlOperationParameterRowClass *kl
                          DIA_UML_TYPE_PARAMETER,
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
 
+  uml_op_prow_properties[UML_OP_PROW_PROP_MODEL] =
+    g_param_spec_object ("model",
+                         "Model",
+                         "Model this for is for",
+                         DIA_UML_TYPE_LIST_STORE,
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
   g_object_class_install_properties (object_class,
                                      UML_OP_PROW_N_PROPS,
                                      uml_op_prow_properties);
@@ -182,6 +219,7 @@ dia_uml_operation_parameter_row_class_init (DiaUmlOperationParameterRowClass *kl
     g_critical ("Failed to load template: %s", err->message);
 
   gtk_widget_class_set_template (widget_class, template);
+  gtk_widget_class_bind_template_child (widget_class, DiaUmlOperationParameterRow, title);
   gtk_widget_class_bind_template_child (widget_class, DiaUmlOperationParameterRow, name);
   gtk_widget_class_bind_template_child (widget_class, DiaUmlOperationParameterRow, type);
   gtk_widget_class_bind_template_child (widget_class, DiaUmlOperationParameterRow, value);
@@ -189,6 +227,7 @@ dia_uml_operation_parameter_row_class_init (DiaUmlOperationParameterRowClass *kl
   gtk_widget_class_bind_template_child (widget_class, DiaUmlOperationParameterRow, comment);
   gtk_widget_class_bind_template_callback (widget_class, move_up);
   gtk_widget_class_bind_template_callback (widget_class, move_down);
+  gtk_widget_class_bind_template_callback (widget_class, remove_param);
 
   g_object_unref (template_file);
 }
@@ -200,9 +239,11 @@ dia_uml_operation_parameter_row_init (DiaUmlOperationParameterRow *self)
 }
 
 GtkWidget *
-dia_uml_operation_parameter_row_new (DiaUmlParameter *op)
+dia_uml_operation_parameter_row_new (DiaUmlParameter *op,
+                                     DiaUmlListStore *model)
 {
   return g_object_new (DIA_UML_TYPE_OPERATION_PARAMETER_ROW,
-                       "parameter", op, 
+                       "parameter", op,
+                       "model", model,
                        NULL);
 }
diff --git a/objects/UML/editor/dia-uml-operation-parameter-row.h 
b/objects/UML/editor/dia-uml-operation-parameter-row.h
index b766e8a1..255b3460 100644
--- a/objects/UML/editor/dia-uml-operation-parameter-row.h
+++ b/objects/UML/editor/dia-uml-operation-parameter-row.h
@@ -6,19 +6,8 @@ G_BEGIN_DECLS
 #define DIA_UML_TYPE_OPERATION_PARAMETER_ROW (dia_uml_operation_parameter_row_get_type ())
 G_DECLARE_FINAL_TYPE (DiaUmlOperationParameterRow, dia_uml_operation_parameter_row, DIA_UML, 
OPERATION_PARAMETER_ROW, GtkListBoxRow)
 
-struct _DiaUmlOperationParameterRow {
-  GtkListBoxRow parent;
-
-  GtkWidget *name;
-  GtkWidget *type;
-  GtkWidget *value;
-  GtkWidget *direction;
-  GtkTextBuffer *comment;
-
-  DiaUmlParameter *parameter;
-};
-
-GtkWidget       *dia_uml_operation_parameter_row_new           (DiaUmlParameter             *parameter);
+GtkWidget       *dia_uml_operation_parameter_row_new           (DiaUmlParameter             *parameter,
+                                                                DiaUmlListStore             *model);
 DiaUmlParameter *dia_uml_operation_parameter_row_get_parameter (DiaUmlOperationParameterRow *self);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]