[dia/dia-next: 44/59] Make OperationRow generic so it can later be used for attributes



commit f0d1ace8d0cfa04de10294a90fa69cf280f6276b
Author: Zander Brown <zbrown gnome org>
Date:   Wed Jan 2 01:34:01 2019 +0000

    Make OperationRow generic so it can later be used for attributes

 objects/UML/Makefile.am                    |   3 +-
 objects/UML/class_dialog.c                 |   1 -
 objects/UML/class_dialog.h                 |  24 -----
 objects/UML/dia-uml-operation.c            |  54 +++++-----
 objects/UML/dia-uml-parameter.c            |  37 ++++---
 objects/UML/editor/dia-uml-class-editor.c  |  20 ++--
 objects/UML/editor/dia-uml-list-data.c     |  47 +++++++++
 objects/UML/editor/dia-uml-list-data.h     |  18 ++++
 objects/UML/editor/dia-uml-list-row.c      | 158 +++++++++++++++++++++++++++++
 objects/UML/editor/dia-uml-list-row.h      |  20 ++++
 objects/UML/editor/dia-uml-operation-row.c | 158 -----------------------------
 objects/UML/editor/dia-uml-operation-row.h |  20 ----
 12 files changed, 303 insertions(+), 257 deletions(-)
---
diff --git a/objects/UML/Makefile.am b/objects/UML/Makefile.am
index 1c96fe20..38774681 100644
--- a/objects/UML/Makefile.am
+++ b/objects/UML/Makefile.am
@@ -12,8 +12,9 @@ libuml_objects_la_SOURCES = \
                        class_dialog.h \
                        class_dialog.c \
                        class_attributes_dialog.c \
+                       editor/dia-uml-list-data.c \
+                       editor/dia-uml-list-row.c \
                        editor/dia-uml-class-editor.c \
-                       editor/dia-uml-operation-row.c \
                        editor/dia-uml-operation-dialog.c \
                        editor/dia-uml-operation-parameter-row.c \
                        class_operations_dialog.c \
diff --git a/objects/UML/class_dialog.c b/objects/UML/class_dialog.c
index 834b1e81..89fbce5a 100644
--- a/objects/UML/class_dialog.c
+++ b/objects/UML/class_dialog.c
@@ -691,7 +691,6 @@ umlclass_get_properties(UMLClass *umlclass, gboolean is_default)
     prop_dialog->dialog = vbox;
 
     prop_dialog->current_attr = NULL;
-    prop_dialog->current_op = NULL;
     prop_dialog->current_templ = NULL;
     prop_dialog->deleted_connections = NULL;
     prop_dialog->added_connections = NULL;
diff --git a/objects/UML/class_dialog.h b/objects/UML/class_dialog.h
index 6374d83d..5d6fe033 100644
--- a/objects/UML/class_dialog.h
+++ b/objects/UML/class_dialog.h
@@ -58,32 +58,8 @@ struct _UMLClassDialog {
   GtkWidget *attr_visible;
   GtkToggleButton *attr_class_scope;
 
-  /* ------------------------------------- */
-  /* ------------------------------------- */
-  /* <<<<<<<<<<<<<<<<< Old operator dialog */
-  /* ------------------------------------- */
-  /* ------------------------------------- */
-
-  DiaListItem *current_op;
-  GtkEntry *op_name;
-  GtkEntry *op_type;
-  GtkEntry *op_stereotype;
-  GtkTextView *op_comment;
-
-  GtkWidget *op_visible;
-  GtkToggleButton *op_class_scope;
-  GtkWidget *op_inheritance_type;
-  GtkToggleButton *op_query;  
-  
-  /* ------------------------------------- */
-  /* ------------------------------------- */
-  /* Old operator dialog >>>>>>>>>>>>>>>>> */
-  /* ------------------------------------- */
-  /* ------------------------------------- */
-
   GtkWidget *editor;
 
-
   DiaList *templates_list;
   DiaListItem *current_templ;
   GtkToggleButton *templ_template;
diff --git a/objects/UML/dia-uml-operation.c b/objects/UML/dia-uml-operation.c
index 579868c5..bcee16ea 100644
--- a/objects/UML/dia-uml-operation.c
+++ b/objects/UML/dia-uml-operation.c
@@ -54,8 +54,14 @@ for c in theClasses :
 #include "uml.h"
 #include "properties.h"
 #include "dia-uml-operation.h"
+#include "editor/dia-uml-list-data.h"
 
-G_DEFINE_TYPE (DiaUmlOperation, dia_uml_operation, G_TYPE_OBJECT)
+static void
+dia_uml_operation_list_data_init (DiaUmlListDataInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (DiaUmlOperation, dia_uml_operation, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (DIA_UML_TYPE_LIST_DATA,
+                                                dia_uml_operation_list_data_init))
 
 enum {
   UML_OP_NAME = 1,
@@ -70,12 +76,6 @@ enum {
 };
 static GParamSpec* uml_op_properties[UML_OP_N_PROPS];
 
-enum {
-  OP_CHANGED,
-  OP_LAST_SIGNAL
-};
-static guint uml_op_signals[OP_LAST_SIGNAL] = { 0 };
-
 extern PropEnumData _uml_visibilities[];
 extern PropEnumData _uml_inheritances[];
 
@@ -450,42 +450,42 @@ dia_uml_operation_set_property (GObject      *object,
     case UML_OP_NAME:
       self->name = g_value_dup_string (value);
       g_object_notify_by_pspec (object, uml_op_properties[UML_OP_NAME]);
-      g_signal_emit (G_OBJECT (self), uml_op_signals[OP_CHANGED], 0);
+      dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
       break;
     case UML_OP_TYPE:
       self->type = g_value_dup_string (value);
       g_object_notify_by_pspec (object, uml_op_properties[UML_OP_TYPE]);
-      g_signal_emit (G_OBJECT (self), uml_op_signals[OP_CHANGED], 0);
+      dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
       break;
     case UML_OP_COMMENT:
       self->comment = g_value_dup_string (value);
       g_object_notify_by_pspec (object, uml_op_properties[UML_OP_COMMENT]);
-      g_signal_emit (G_OBJECT (self), uml_op_signals[OP_CHANGED], 0);
+      dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
       break;
     case UML_OP_STEREOTYPE:
       self->stereotype = g_value_dup_string (value);
       g_object_notify_by_pspec (object, uml_op_properties[UML_OP_STEREOTYPE]);
-      g_signal_emit (G_OBJECT (self), uml_op_signals[OP_CHANGED], 0);
+      dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
       break;
     case UML_OP_VISIBILITY:
       self->visibility = g_value_get_int (value);
       g_object_notify_by_pspec (object, uml_op_properties[UML_OP_VISIBILITY]);
-      g_signal_emit (G_OBJECT (self), uml_op_signals[OP_CHANGED], 0);
+      dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
       break;
     case UML_OP_INHERITANCE_TYPE:
       self->inheritance_type = g_value_get_int (value);
       g_object_notify_by_pspec (object, uml_op_properties[UML_OP_INHERITANCE_TYPE]);
-      g_signal_emit (G_OBJECT (self), uml_op_signals[OP_CHANGED], 0);
+      dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
       break;
     case UML_OP_QUERY:
       self->query = g_value_get_boolean (value);
       g_object_notify_by_pspec (object, uml_op_properties[UML_OP_QUERY]);
-      g_signal_emit (G_OBJECT (self), uml_op_signals[OP_CHANGED], 0);
+      dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
       break;
     case UML_OP_CLASS_SCOPE:
       self->class_scope = g_value_get_boolean (value);
       g_object_notify_by_pspec (object, uml_op_properties[UML_OP_CLASS_SCOPE]);
-      g_signal_emit (G_OBJECT (self), uml_op_signals[OP_CHANGED], 0);
+      dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -532,6 +532,18 @@ dia_uml_operation_get_property (GObject    *object,
   }
 }
 
+static const gchar *
+format (DiaUmlListData *self)
+{
+  return dia_uml_operation_format (DIA_UML_OPERATION (self));
+}
+
+static void
+dia_uml_operation_list_data_init (DiaUmlListDataInterface *iface)
+{
+  iface->format = format;
+}
+
 static void
 dia_uml_operation_class_init (DiaUmlOperationClass *klass)
 {
@@ -589,12 +601,6 @@ dia_uml_operation_class_init (DiaUmlOperationClass *klass)
   g_object_class_install_properties (object_class,
                                      UML_OP_N_PROPS,
                                      uml_op_properties);
-
-  uml_op_signals[OP_CHANGED] = g_signal_new ("changed",
-                                             G_TYPE_FROM_CLASS (klass),
-                                             G_SIGNAL_RUN_FIRST,
-                                             0, NULL, NULL, NULL,
-                                             G_TYPE_NONE, 0);
 }
 
 static void
@@ -622,7 +628,7 @@ static void
 bubble (DiaUmlParameter *para,
         DiaUmlOperation *self)
 {
-  g_signal_emit (G_OBJECT (self), uml_op_signals[OP_CHANGED], 0);
+  dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
 }
 
 void
@@ -634,7 +640,7 @@ dia_uml_operation_insert_parameter (DiaUmlOperation *self,
                                     g_object_ref (parameter),
                                     index);
   g_signal_connect (G_OBJECT (parameter), "changed", G_CALLBACK (bubble), self);
-  g_signal_emit (G_OBJECT (self), uml_op_signals[OP_CHANGED], 0);
+  dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
 }
 
 void
@@ -644,7 +650,7 @@ dia_uml_operation_remove_parameter (DiaUmlOperation *self,
   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);
-  g_signal_emit (G_OBJECT (self), uml_op_signals[OP_CHANGED], 0);
+  dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
 }
 
 GList *
diff --git a/objects/UML/dia-uml-parameter.c b/objects/UML/dia-uml-parameter.c
index 04113c5e..c105e283 100644
--- a/objects/UML/dia-uml-parameter.c
+++ b/objects/UML/dia-uml-parameter.c
@@ -28,9 +28,15 @@
 #include <string.h>
 
 #include "dia-uml-parameter.h"
+#include "editor/dia-uml-list-data.h"
 #include "properties.h"
 
-G_DEFINE_TYPE (DiaUmlParameter, dia_uml_parameter, G_TYPE_OBJECT)
+static void
+dia_uml_parameter_list_data_init (DiaUmlListDataInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (DiaUmlParameter, dia_uml_parameter, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (DIA_UML_TYPE_LIST_DATA,
+                                                dia_uml_parameter_list_data_init))
 
 enum {
   UML_PARA_NAME = 1,
@@ -42,12 +48,6 @@ enum {
 };
 static GParamSpec* uml_para_properties[UML_PARA_N_PROPS];
 
-enum {
-  PARAM_CHANGED,
-  PARAM_LAST_SIGNAL
-};
-static guint uml_param_signals[PARAM_LAST_SIGNAL] = { 0 };
-
 static PropEnumData _uml_parameter_kinds[] = {
   { N_("Undefined"), UML_UNDEF_KIND} ,
   { N_("In"), UML_IN },
@@ -172,27 +172,27 @@ dia_uml_parameter_set_property (GObject      *object,
     case UML_PARA_NAME:
       self->name = g_value_dup_string (value);
       g_object_notify_by_pspec (object, uml_para_properties[UML_PARA_NAME]);
-      g_signal_emit (G_OBJECT (self), uml_param_signals[PARAM_CHANGED], 0);
+      dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
       break;
     case UML_PARA_TYPE:
       self->type = g_value_dup_string (value);
       g_object_notify_by_pspec (object, uml_para_properties[UML_PARA_TYPE]);
-      g_signal_emit (G_OBJECT (self), uml_param_signals[PARAM_CHANGED], 0);
+      dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
       break;
     case UML_PARA_VALUE:
       self->value = g_value_dup_string (value);
       g_object_notify_by_pspec (object, uml_para_properties[UML_PARA_VALUE]);
-      g_signal_emit (G_OBJECT (self), uml_param_signals[PARAM_CHANGED], 0);
+      dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
       break;
     case UML_PARA_COMMENT:
       self->comment = g_value_dup_string (value);
       g_object_notify_by_pspec (object, uml_para_properties[UML_PARA_COMMENT]);
-      g_signal_emit (G_OBJECT (self), uml_param_signals[PARAM_CHANGED], 0);
+      dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
       break;
     case UML_PARA_KIND:
       self->kind = g_value_get_int (value);
       g_object_notify_by_pspec (object, uml_para_properties[UML_PARA_KIND]);
-      g_signal_emit (G_OBJECT (self), uml_param_signals[PARAM_CHANGED], 0);
+      dia_uml_list_data_changed (DIA_UML_LIST_DATA (self));
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -230,6 +230,12 @@ dia_uml_parameter_get_property (GObject    *object,
   }
 }
 
+static void
+dia_uml_parameter_list_data_init (DiaUmlListDataInterface *iface)
+{
+
+}
+
 static void
 dia_uml_parameter_class_init (DiaUmlParameterClass *klass)
 {
@@ -270,13 +276,6 @@ dia_uml_parameter_class_init (DiaUmlParameterClass *klass)
   g_object_class_install_properties (object_class,
                                      UML_PARA_N_PROPS,
                                      uml_para_properties);
-
-
-  uml_param_signals[PARAM_CHANGED] = g_signal_new ("changed",
-                                                   G_TYPE_FROM_CLASS (klass),
-                                                   G_SIGNAL_RUN_FIRST,
-                                                   0, NULL, NULL, NULL,
-                                                   G_TYPE_NONE, 0);
 }
 
 static void
diff --git a/objects/UML/editor/dia-uml-class-editor.c b/objects/UML/editor/dia-uml-class-editor.c
index 4dd2cf13..d0cfee3b 100644
--- a/objects/UML/editor/dia-uml-class-editor.c
+++ b/objects/UML/editor/dia-uml-class-editor.c
@@ -1,5 +1,5 @@
 #include "dia-uml-class-editor.h"
-#include "dia-uml-operation-row.h"
+#include "dia-uml-list-row.h"
 #include "dia-uml-operation-dialog.h"
 #include "dia_dirs.h"
 
@@ -23,7 +23,7 @@ build_list (DiaUmlClassEditor *self)
   self->building_ops = TRUE;
   while (list != NULL) {
     DiaUmlOperation *op = (DiaUmlOperation *)list->data;
-    item = dia_uml_operation_row_new (op);
+    item = dia_uml_list_row_new (DIA_UML_LIST_DATA (op));
     gtk_widget_show (item);
     gtk_container_add (GTK_CONTAINER (self->operations), item);
     
@@ -38,7 +38,7 @@ remove_op_row (GtkWidget       *row,
 {
   DiaUmlOperation *curr_row;
 
-  curr_row = dia_uml_operation_row_get_operation (DIA_UML_OPERATION_ROW (row));
+  curr_row = DIA_UML_OPERATION (dia_uml_list_row_get_data (DIA_UML_LIST_ROW (row)));
 
   if (op == curr_row)
     gtk_widget_destroy (row);
@@ -65,7 +65,7 @@ add_operation (DiaUmlClassEditor *self)
   GtkWidget *parent;
 
   op = dia_uml_operation_new ();
-  row = dia_uml_operation_row_new (op);
+  row = dia_uml_list_row_new (DIA_UML_LIST_DATA (op));
 
   gtk_widget_show (row);
   gtk_container_add (GTK_CONTAINER (self->operations), row);
@@ -85,11 +85,11 @@ edit_operation (DiaUmlClassEditor *self,
   GtkWidget *parent;
   DiaUmlOperation *op;
 
-  if (!DIA_UML_IS_OPERATION_ROW (row))
+  if (!DIA_UML_IS_LIST_ROW (row))
     return;
   
   parent = gtk_widget_get_toplevel (GTK_WIDGET (self));
-  op = dia_uml_operation_row_get_operation (DIA_UML_OPERATION_ROW (row));
+  op = DIA_UML_OPERATION (dia_uml_list_row_get_data (DIA_UML_LIST_ROW (row)));
   dlg = dia_uml_operation_dialog_new (GTK_WINDOW (parent), op);
   g_signal_connect (dlg, "operation-deleted", G_CALLBACK (remove_op), self);
   gtk_widget_show (dlg);
@@ -103,10 +103,10 @@ operation_added (DiaUmlClassEditor *self,
   DiaUmlOperation *op;
   int index;
 
-  if (self->building_ops || !DIA_UML_IS_OPERATION_ROW (row))
+  if (self->building_ops || !DIA_UML_IS_LIST_ROW (row))
     return;
 
-  op = dia_uml_operation_row_get_operation (DIA_UML_OPERATION_ROW (row));
+  op = DIA_UML_OPERATION (dia_uml_list_row_get_data (DIA_UML_LIST_ROW (row)));
   index = gtk_list_box_row_get_index (row);
 
   dia_uml_class_insert_operation (self->klass, op, index);
@@ -119,10 +119,10 @@ operation_removed (DiaUmlClassEditor *self,
 {
   DiaUmlOperation *op;
 
-  if (!DIA_UML_IS_OPERATION_ROW (row) || gtk_widget_in_destruction (GTK_WIDGET (row)))
+  if (!DIA_UML_IS_LIST_ROW (row) || gtk_widget_in_destruction (GTK_WIDGET (row)))
     return;
   
-  op = dia_uml_operation_row_get_operation (DIA_UML_OPERATION_ROW (row));
+  op = DIA_UML_OPERATION (dia_uml_list_row_get_data (DIA_UML_LIST_ROW (row)));
 
   dia_uml_class_remove_operation (self->klass, op);
   /* Don't unref op, we might be being moved so must give it the change to survive */
diff --git a/objects/UML/editor/dia-uml-list-data.c b/objects/UML/editor/dia-uml-list-data.c
new file mode 100644
index 00000000..0e908a89
--- /dev/null
+++ b/objects/UML/editor/dia-uml-list-data.c
@@ -0,0 +1,47 @@
+#include <glib-object.h>
+#include "dia-uml-list-data.h"
+
+G_DEFINE_INTERFACE (DiaUmlListData, dia_uml_list_data, G_TYPE_OBJECT)
+
+enum {
+  CHANGED,
+  LAST_SIGNAL
+};
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static const gchar *
+dia_uml_list_data_default_format (DiaUmlListData *self)
+{
+  return G_OBJECT_TYPE_NAME (self);
+}
+
+static void
+dia_uml_list_data_default_init (DiaUmlListDataInterface *iface)
+{
+  iface->format = dia_uml_list_data_default_format;
+
+  signals[CHANGED] = g_signal_new ("changed",
+                                   G_TYPE_FROM_CLASS (iface),
+                                   G_SIGNAL_RUN_FIRST,
+                                   0, NULL, NULL, NULL,
+                                   G_TYPE_NONE, 0);
+}
+
+void
+dia_uml_list_data_changed (DiaUmlListData *self)
+{
+  g_signal_emit (G_OBJECT (self), signals[CHANGED], 0);
+}
+
+const gchar *
+dia_uml_list_data_format (DiaUmlListData *self)
+{
+  DiaUmlListDataInterface *iface;
+  
+  g_return_val_if_fail (DIA_UML_IS_LIST_DATA (self), NULL);
+  
+  iface = DIA_UML_LIST_DATA_GET_IFACE (self);
+  g_return_val_if_fail (iface->format != NULL, NULL);
+  
+  return iface->format (self);
+}
diff --git a/objects/UML/editor/dia-uml-list-data.h b/objects/UML/editor/dia-uml-list-data.h
new file mode 100644
index 00000000..caaf9a81
--- /dev/null
+++ b/objects/UML/editor/dia-uml-list-data.h
@@ -0,0 +1,18 @@
+#include <glib-object.h>
+
+#ifndef UML_LIST_DATA_H
+#define UML_LIST_DATA_H
+
+#define DIA_UML_TYPE_LIST_DATA (dia_uml_list_data_get_type ())
+G_DECLARE_INTERFACE (DiaUmlListData, dia_uml_list_data, DIA_UML, LIST_DATA, GObject)
+
+struct _DiaUmlListDataInterface {
+  GTypeInterface parent_iface;
+  
+  const gchar * (* format) (DiaUmlListData *self);
+};
+
+void         dia_uml_list_data_changed (DiaUmlListData *self);
+const gchar *dia_uml_list_data_format  (DiaUmlListData *self);
+
+#endif
diff --git a/objects/UML/editor/dia-uml-list-row.c b/objects/UML/editor/dia-uml-list-row.c
new file mode 100644
index 00000000..477a0750
--- /dev/null
+++ b/objects/UML/editor/dia-uml-list-row.c
@@ -0,0 +1,158 @@
+#include "dia-uml-list-data.h"
+#include "dia-uml-list-row.h"
+#include "dia_dirs.h"
+
+G_DEFINE_TYPE (DiaUmlListRow, dia_uml_list_row, GTK_TYPE_LIST_BOX_ROW)
+
+enum {
+  PROP_DATA = 1,
+  N_PROPS
+};
+static GParamSpec* properties[N_PROPS];
+
+static void
+dia_uml_list_row_finalize (GObject *object)
+{
+  DiaUmlListRow *self = DIA_UML_LIST_ROW (object);
+
+  g_clear_object (&self->data);
+}
+
+static void
+display_op (DiaUmlListData *op,
+            DiaUmlListRow  *row)
+{
+  gtk_label_set_label (GTK_LABEL (row->title),
+                       dia_uml_list_data_format (op));
+}
+
+static void
+dia_uml_list_row_set_property (GObject      *object,
+                               guint         property_id,
+                               const GValue *value,
+                               GParamSpec   *pspec)
+{
+  DiaUmlListRow *self = DIA_UML_LIST_ROW (object);
+  switch (property_id) {
+    case PROP_DATA:
+      self->data = g_value_dup_object (value);
+      g_signal_connect (G_OBJECT (self->data), "changed",
+                        G_CALLBACK (display_op), self);
+      display_op (self->data, self);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+  }
+}
+
+static void
+dia_uml_list_row_get_property (GObject    *object,
+                               guint       property_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
+{
+  DiaUmlListRow *self = DIA_UML_LIST_ROW (object);
+  switch (property_id) {
+    case PROP_DATA:
+      g_value_set_object (value, self->data);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+  }
+}
+
+static void
+move_up (DiaUmlListRow *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);
+}
+
+static void
+move_down (DiaUmlListRow *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);
+}
+
+static void
+dia_uml_list_row_class_init (DiaUmlListRowClass *klass)
+{
+  GFile *template_file;
+  GBytes *template;
+  GError *err = NULL;
+  GObjectClass   *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->finalize = dia_uml_list_row_finalize;
+  object_class->set_property = dia_uml_list_row_set_property;
+  object_class->get_property = dia_uml_list_row_get_property;
+
+  properties[PROP_DATA] =
+    g_param_spec_object ("data",
+                         "Data",
+                         "Data this row represents",
+                         DIA_UML_TYPE_LIST_DATA,
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
+  g_object_class_install_properties (object_class,
+                                     N_PROPS,
+                                     properties);
+
+  /* TODO: Use GResource */
+  template_file = g_file_new_for_path (build_ui_filename ("ui/dia-uml-list-row.ui"));
+  template = g_file_load_bytes (template_file, NULL, NULL, &err);
+
+  if (err)
+    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, DiaUmlListRow, title);
+  gtk_widget_class_bind_template_callback (widget_class, move_up);
+  gtk_widget_class_bind_template_callback (widget_class, move_down);
+
+  g_object_unref (template_file);
+}
+
+static void
+dia_uml_list_row_init (DiaUmlListRow *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+GtkWidget *
+dia_uml_list_row_new (DiaUmlListData *data)
+{
+  return g_object_new (DIA_UML_TYPE_LIST_ROW,
+                       "data", data, 
+                       NULL);
+}
+
+DiaUmlListData *
+dia_uml_list_row_get_data (DiaUmlListRow *self)
+{
+  return g_object_ref (self->data);
+}
diff --git a/objects/UML/editor/dia-uml-list-row.h b/objects/UML/editor/dia-uml-list-row.h
new file mode 100644
index 00000000..3105c3bd
--- /dev/null
+++ b/objects/UML/editor/dia-uml-list-row.h
@@ -0,0 +1,20 @@
+#include <gtk/gtk.h>
+#include "dia-uml-list-data.h"
+
+G_BEGIN_DECLS
+
+#define DIA_UML_TYPE_LIST_ROW (dia_uml_list_row_get_type ())
+G_DECLARE_FINAL_TYPE (DiaUmlListRow, dia_uml_list_row, DIA_UML, LIST_ROW, GtkListBoxRow)
+
+struct _DiaUmlListRow {
+  GtkListBoxRow parent;
+
+  GtkWidget *title;
+
+  DiaUmlListData *data;
+};
+
+GtkWidget      *dia_uml_list_row_new      (DiaUmlListData *data);
+DiaUmlListData *dia_uml_list_row_get_data (DiaUmlListRow  *self);
+
+G_END_DECLS


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