From 147cf2977ab29d1ab9b9d776ceff5b73a10ac297 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Sat, 4 Dec 2010 14:23:55 +0100
Subject: Initial LdDocument implementation.
The document maintains a list of LdDocumentObject objects.
---
CMakeLists.txt | 4 +
src/ld-canvas.c | 1 +
src/ld-document-object.c | 183 ++++++++++++++++++++++++++++++
src/ld-document-object.h | 65 +++++++++++
src/ld-document-symbol.c | 108 ++++++++++++++++++
src/ld-document-symbol.h | 64 +++++++++++
src/ld-document.c | 287 +++++++++++++++++++++++++++++++++++++++++++++++
src/ld-document.h | 71 +++++-------
src/ld-window-main.c | 3 +
9 files changed, 743 insertions(+), 43 deletions(-)
create mode 100644 src/ld-document-object.c
create mode 100644 src/ld-document-object.h
create mode 100644 src/ld-document-symbol.c
create mode 100644 src/ld-document-symbol.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 01c276f..aac2c9e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -87,6 +87,8 @@ set (logdiag_SOURCES
src/ld-marshal.c
src/ld-window-main.c
src/ld-document.c
+ src/ld-document-object.c
+ src/ld-document-symbol.c
src/ld-canvas.c
src/ld-library.c
src/ld-symbol-category.c
@@ -98,6 +100,8 @@ set (logdiag_HEADERS
src/ld-marshal.h
src/ld-window-main.h
src/ld-document.h
+ src/ld-document-object.h
+ src/ld-document-symbol.h
src/ld-canvas.h
src/ld-library.h
src/ld-symbol-category.h
diff --git a/src/ld-canvas.c b/src/ld-canvas.c
index 3457038..3414ae6 100644
--- a/src/ld-canvas.c
+++ b/src/ld-canvas.c
@@ -13,6 +13,7 @@
#include "config.h"
#include "ld-marshal.h"
+#include "ld-document-object.h"
#include "ld-document.h"
#include "ld-symbol.h"
#include "ld-library.h"
diff --git a/src/ld-document-object.c b/src/ld-document-object.c
new file mode 100644
index 0000000..e82b3a6
--- /dev/null
+++ b/src/ld-document-object.c
@@ -0,0 +1,183 @@
+/*
+ * ld-document-object.c
+ *
+ * This file is a part of logdiag.
+ * Copyright Přemysl Janouch 2010. All rights reserved.
+ *
+ * See the file LICENSE for licensing information.
+ *
+ */
+
+#include
+
+#include "config.h"
+
+#include "ld-document-object.h"
+
+
+/**
+ * SECTION:ld-document-object
+ * @short_description: A document object.
+ * @see_also: #LdDocument, #LdCanvas
+ *
+ * #LdDocumentObject represents an object in an #LdDocument.
+ */
+
+/*
+ * LdDocumentObjectPrivate:
+ * @x: The X coordinate of this object.
+ * @y: The Y coordinate of this object.
+ */
+struct _LdDocumentObjectPrivate
+{
+ gdouble x;
+ gdouble y;
+};
+
+G_DEFINE_ABSTRACT_TYPE (LdDocumentObject, ld_document_object, G_TYPE_OBJECT);
+
+enum
+{
+ PROP_0,
+ PROP_X,
+ PROP_Y
+};
+
+static void ld_document_object_get_property (GObject *object, guint property_id,
+ GValue *value, GParamSpec *pspec);
+static void ld_document_object_set_property (GObject *object, guint property_id,
+ const GValue *value, GParamSpec *pspec);
+
+
+static void
+ld_document_object_class_init (LdDocumentObjectClass *klass)
+{
+ GObjectClass *object_class;
+ GParamSpec *pspec;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->get_property = ld_document_object_get_property;
+ object_class->set_property = ld_document_object_set_property;
+
+/**
+ * LdDocumentObject:x:
+ *
+ * The X coordinate of the object.
+ */
+ pspec = g_param_spec_double ("x", "X",
+ "The X coordinate of this object.",
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0, G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_X, pspec);
+
+/**
+ * LdDocumentObject:y:
+ *
+ * The Y coordinate of the object.
+ */
+ pspec = g_param_spec_double ("y", "Y",
+ "The Y coordinate of this object.",
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0, G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_Y, pspec);
+
+ g_type_class_add_private (klass, sizeof (LdDocumentObjectPrivate));
+}
+
+static void
+ld_document_object_init (LdDocumentObject *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE
+ (self, LD_TYPE_DOCUMENT_OBJECT, LdDocumentObjectPrivate);
+}
+
+static void
+ld_document_object_get_property (GObject *object, guint property_id,
+ GValue *value, GParamSpec *pspec)
+{
+ LdDocumentObject *self;
+
+ self = LD_DOCUMENT_OBJECT (object);
+ switch (property_id)
+ {
+ case PROP_X:
+ g_value_set_double (value, ld_document_object_get_x (self));
+ break;
+ case PROP_Y:
+ g_value_set_double (value, ld_document_object_get_y (self));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+ld_document_object_set_property (GObject *object, guint property_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ LdDocumentObject *self;
+
+ self = LD_DOCUMENT_OBJECT (object);
+ switch (property_id)
+ {
+ case PROP_X:
+ ld_document_object_set_x (self, g_value_get_double (value));
+ break;
+ case PROP_Y:
+ ld_document_object_set_y (self, g_value_get_double (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+
+/**
+ * ld_document_object_get_x:
+ * @self: An #LdDocumentObject object.
+ *
+ * Return value: The X coordinate of the object.
+ */
+gdouble
+ld_document_object_get_x (LdDocumentObject *self)
+{
+ g_return_val_if_fail (LD_IS_DOCUMENT_OBJECT (self), 0);
+ return self->priv->x;
+}
+
+/**
+ * ld_document_object_get_y:
+ * @self: An #LdDocumentObject object.
+ *
+ * Return value: The Y coordinate of the object.
+ */
+gdouble
+ld_document_object_get_y (LdDocumentObject *self)
+{
+ g_return_val_if_fail (LD_IS_DOCUMENT_OBJECT (self), 0);
+ return self->priv->y;
+}
+
+/**
+ * ld_document_object_get_x:
+ * @self: An #LdDocumentObject object.
+ *
+ * Set the X coordinate of the object.
+ */
+void
+ld_document_object_set_x (LdDocumentObject *self, gdouble x)
+{
+ g_return_if_fail (LD_IS_DOCUMENT_OBJECT (self));
+ self->priv->x = x;
+}
+
+/**
+ * ld_document_object_get_x:
+ * @self: An #LdDocumentObject object.
+ *
+ * Set the Y coordinate of the object.
+ */
+void
+ld_document_object_set_y (LdDocumentObject *self, gdouble y)
+{
+ g_return_if_fail (LD_IS_DOCUMENT_OBJECT (self));
+ self->priv->y = y;
+}
diff --git a/src/ld-document-object.h b/src/ld-document-object.h
new file mode 100644
index 0000000..0333878
--- /dev/null
+++ b/src/ld-document-object.h
@@ -0,0 +1,65 @@
+/*
+ * ld-document-object.h
+ *
+ * This file is a part of logdiag.
+ * Copyright Přemysl Janouch 2010. All rights reserved.
+ *
+ * See the file LICENSE for licensing information.
+ *
+ */
+
+#ifndef __LD_DOCUMENT_OBJECT_H__
+#define __LD_DOCUMENT_OBJECT_H__
+
+G_BEGIN_DECLS
+
+
+#define LD_TYPE_DOCUMENT_OBJECT (ld_document_object_get_type ())
+#define LD_DOCUMENT_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), LD_TYPE_DOCUMENT_OBJECT, LdDocumentObject))
+#define LD_DOCUMENT_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
+ ((klass), LD_TYPE_DOCUMENT_OBJECT, LdDocumentObjectClass))
+#define LD_IS_DOCUMENT_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), LD_TYPE_DOCUMENT_OBJECT))
+#define LD_IS_DOCUMENT_OBJECT_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((klass), LD_TYPE_DOCUMENT_OBJECT))
+#define LD_DOCUMENT_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), LD_DOCUMENT_OBJECT, LdDocumentObjectClass))
+
+typedef struct _LdDocumentObject LdDocumentObject;
+typedef struct _LdDocumentObjectPrivate LdDocumentObjectPrivate;
+typedef struct _LdDocumentObjectClass LdDocumentObjectClass;
+
+
+/**
+ * LdDocumentObject:
+ */
+struct _LdDocumentObject
+{
+/*< private >*/
+ GObject parent_instance;
+ LdDocumentObjectPrivate *priv;
+};
+
+/**
+ * LdDocumentObjectClass:
+ */
+struct _LdDocumentObjectClass
+{
+/*< private >*/
+ GObjectClass parent_class;
+};
+
+
+GType ld_document_object_get_type (void) G_GNUC_CONST;
+
+gdouble ld_document_object_get_x (LdDocumentObject *self);
+gdouble ld_document_object_get_y (LdDocumentObject *self);
+void ld_document_object_set_x (LdDocumentObject *self, gdouble x);
+void ld_document_object_set_y (LdDocumentObject *self, gdouble y);
+
+
+G_END_DECLS
+
+#endif /* ! __LD_DOCUMENT_OBJECT_H__ */
+
diff --git a/src/ld-document-symbol.c b/src/ld-document-symbol.c
new file mode 100644
index 0000000..b415d54
--- /dev/null
+++ b/src/ld-document-symbol.c
@@ -0,0 +1,108 @@
+/*
+ * ld-document-symbol.c
+ *
+ * This file is a part of logdiag.
+ * Copyright Přemysl Janouch 2010. All rights reserved.
+ *
+ * See the file LICENSE for licensing information.
+ *
+ */
+
+#include
+
+#include "config.h"
+
+#include "ld-document-object.h"
+#include "ld-document-symbol.h"
+
+
+/**
+ * SECTION:ld-document-symbol
+ * @short_description: A symbol object.
+ * @see_also: #LdDocumentObject
+ *
+ * #LdDocumentSymbol is an implementation of #LdDocumentObject.
+ */
+
+/*
+ * LdDocumentSymbolPrivate:
+ * @klass: The class of this symbol.
+ */
+struct _LdDocumentSymbolPrivate
+{
+ gchar *klass;
+};
+
+G_DEFINE_TYPE (LdDocumentSymbol, ld_document_symbol, LD_TYPE_DOCUMENT_OBJECT);
+
+static void ld_document_symbol_finalize (GObject *gobject);
+
+
+static void
+ld_document_symbol_class_init (LdDocumentSymbolClass *klass)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = ld_document_symbol_finalize;
+
+ /* TODO: A property for the class. */
+
+ g_type_class_add_private (klass, sizeof (LdDocumentSymbolPrivate));
+}
+
+static void
+ld_document_symbol_init (LdDocumentSymbol *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE
+ (self, LD_TYPE_DOCUMENT_SYMBOL, LdDocumentSymbolPrivate);
+}
+
+static void
+ld_document_symbol_finalize (GObject *gobject)
+{
+ LdDocumentSymbol *self;
+
+ self = LD_DOCUMENT_SYMBOL (gobject);
+
+ if (self->priv->klass)
+ g_free (self->priv->klass);
+
+ /* Chain up to the parent class. */
+ G_OBJECT_CLASS (ld_document_symbol_parent_class)->finalize (gobject);
+}
+
+
+/**
+ * ld_document_symbol_new:
+ * @klass: The class of the symbol (symbol identifier).
+ *
+ * Return value: A new #LdDocumentSymbol object.
+ */
+LdDocumentSymbol *
+ld_document_symbol_new (const gchar *klass)
+{
+ LdDocumentSymbol *self;
+
+ self = g_object_new (LD_TYPE_DOCUMENT_SYMBOL, NULL);
+ ld_document_symbol_set_class (self, klass);
+ return self;
+}
+
+
+const gchar *
+ld_document_symbol_get_class (LdDocumentSymbol *self)
+{
+ g_return_val_if_fail (LD_IS_DOCUMENT_SYMBOL (self), NULL);
+ return self->priv->klass;
+}
+
+void
+ld_document_symbol_set_class (LdDocumentSymbol *self, const gchar *klass)
+{
+ g_return_if_fail (LD_IS_DOCUMENT_SYMBOL (self));
+
+ if (self->priv->klass)
+ g_free (self->priv->klass);
+ self->priv->klass = g_strdup (klass);
+}
diff --git a/src/ld-document-symbol.h b/src/ld-document-symbol.h
new file mode 100644
index 0000000..87e132c
--- /dev/null
+++ b/src/ld-document-symbol.h
@@ -0,0 +1,64 @@
+/*
+ * ld-document-symbol.h
+ *
+ * This file is a part of logdiag.
+ * Copyright Přemysl Janouch 2010. All rights reserved.
+ *
+ * See the file LICENSE for licensing information.
+ *
+ */
+
+#ifndef __LD_DOCUMENT_SYMBOL_H__
+#define __LD_DOCUMENT_SYMBOL_H__
+
+G_BEGIN_DECLS
+
+
+#define LD_TYPE_DOCUMENT_SYMBOL (ld_document_symbol_get_type ())
+#define LD_DOCUMENT_SYMBOL(obj) (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), LD_TYPE_DOCUMENT_SYMBOL, LdDocumentSymbol))
+#define LD_DOCUMENT_SYMBOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
+ ((klass), LD_TYPE_DOCUMENT_SYMBOL, LdDocumentSymbolClass))
+#define LD_IS_DOCUMENT_SYMBOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), LD_TYPE_DOCUMENT_SYMBOL))
+#define LD_IS_DOCUMENT_SYMBOL_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((klass), LD_TYPE_DOCUMENT_SYMBOL))
+#define LD_DOCUMENT_SYMBOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), LD_DOCUMENT_SYMBOL, LdDocumentSymbolClass))
+
+typedef struct _LdDocumentSymbol LdDocumentSymbol;
+typedef struct _LdDocumentSymbolPrivate LdDocumentSymbolPrivate;
+typedef struct _LdDocumentSymbolClass LdDocumentSymbolClass;
+
+
+/**
+ * LdDocumentSymbol:
+ */
+struct _LdDocumentSymbol
+{
+/*< private >*/
+ LdDocumentObject parent_instance;
+ LdDocumentSymbolPrivate *priv;
+};
+
+/**
+ * LdDocumentSymbolClass:
+ */
+struct _LdDocumentSymbolClass
+{
+/*< private >*/
+ LdDocumentObjectClass parent_class;
+};
+
+
+GType ld_document_symbol_get_type (void) G_GNUC_CONST;
+
+LdDocumentSymbol *ld_document_symbol_new (const gchar *klass);
+const gchar *ld_document_symbol_get_class (LdDocumentSymbol *self);
+void ld_document_symbol_set_class (LdDocumentSymbol *self, const gchar *klass);
+
+
+G_END_DECLS
+
+#endif /* ! __LD_DOCUMENT_SYMBOL_H__ */
+
diff --git a/src/ld-document.c b/src/ld-document.c
index e69de29..64e1536 100644
--- a/src/ld-document.c
+++ b/src/ld-document.c
@@ -0,0 +1,287 @@
+/*
+ * ld-document.c
+ *
+ * This file is a part of logdiag.
+ * Copyright Přemysl Janouch 2010. All rights reserved.
+ *
+ * See the file LICENSE for licensing information.
+ *
+ */
+
+#include
+
+#include "config.h"
+
+#include "ld-document-object.h"
+#include "ld-document.h"
+
+
+/**
+ * SECTION:ld-document
+ * @short_description: A document object.
+ * @see_also: #LdCanvas
+ *
+ * #LdDocument is a model for storing documents.
+ */
+
+/*
+ * LdDocumentPrivate:
+ * @objects: All the objects in the document.
+ * @selection: All currently selected objects.
+ * @connections: Connections between objects.
+ */
+struct _LdDocumentPrivate
+{
+ GSList *objects;
+ GSList *selection;
+ GSList *connections;
+};
+
+G_DEFINE_TYPE (LdDocument, ld_document, G_TYPE_OBJECT);
+
+static void
+ld_document_finalize (GObject *gobject);
+
+
+static void
+ld_document_class_init (LdDocumentClass *klass)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = ld_document_finalize;
+
+/**
+ * LdDocument::changed:
+ * @document: The document object.
+ *
+ * Contents of the document have changed.
+ */
+ klass->changed_signal = g_signal_new
+ ("changed", G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
+ 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+ g_type_class_add_private (klass, sizeof (LdDocumentPrivate));
+}
+
+static void
+ld_document_init (LdDocument *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE
+ (self, LD_TYPE_DOCUMENT, LdDocumentPrivate);
+}
+
+static void
+ld_document_finalize (GObject *gobject)
+{
+ LdDocument *self;
+
+ self = LD_DOCUMENT (gobject);
+ ld_document_clear (self);
+
+ /* Chain up to the parent class. */
+ G_OBJECT_CLASS (ld_document_parent_class)->finalize (gobject);
+}
+
+/**
+ * ld_document_new:
+ *
+ * Create an instance.
+ */
+LdDocument *
+ld_document_new (void)
+{
+ return g_object_new (LD_TYPE_DOCUMENT, NULL);
+}
+
+/**
+ * ld_document_clear:
+ * @self: An #LdDocument object.
+ *
+ * Clear the whole document with it's objects and selection.
+ */
+void
+ld_document_clear (LdDocument *self)
+{
+ g_return_if_fail (LD_IS_DOCUMENT (self));
+
+ g_slist_free (self->priv->connections);
+ self->priv->connections = NULL;
+
+ g_slist_foreach (self->priv->selection, (GFunc) g_object_unref, NULL);
+ g_slist_free (self->priv->selection);
+ self->priv->selection = NULL;
+
+ g_slist_foreach (self->priv->objects, (GFunc) g_object_unref, NULL);
+ g_slist_free (self->priv->objects);
+ self->priv->objects = NULL;
+
+ g_signal_emit (self,
+ LD_DOCUMENT_GET_CLASS (self)->changed_signal, 0);
+}
+
+/**
+ * ld_document_load_from_file:
+ * @self: An #LdDocument object.
+ * @filename: A filename.
+ * @error: Return location for a GError, or NULL.
+ *
+ * Load a file into the document.
+ *
+ * Return value: TRUE if the file could be loaded, FALSE otherwise.
+ */
+gboolean
+ld_document_load_from_file (LdDocument *self,
+ const gchar *filename, GError *error)
+{
+ g_return_val_if_fail (LD_IS_DOCUMENT (self), FALSE);
+
+ /* TODO */
+ return FALSE;
+}
+
+/**
+ * ld_document_save_to_file:
+ * @self: An #LdDocument object.
+ * @filename: A filename.
+ * @error: Return location for a GError, or NULL.
+ *
+ * Save the document into a file.
+ *
+ * Return value: TRUE if the document could be saved, FALSE otherwise.
+ */
+gboolean
+ld_document_save_to_file (LdDocument *self,
+ const gchar *filename, GError *error)
+{
+ g_return_val_if_fail (LD_IS_DOCUMENT (self), FALSE);
+
+ /* TODO */
+ return FALSE;
+}
+
+/**
+ * ld_document_get_objects:
+ * @self: An #LdDocument object.
+ *
+ * Get a list of objects in the document.
+ * You mustn't make any changes to the list.
+ */
+GSList *
+ld_document_get_objects (LdDocument *self)
+{
+ g_return_val_if_fail (LD_IS_DOCUMENT (self), NULL);
+ return self->priv->objects;
+}
+
+/**
+ * ld_document_insert_object:
+ * @self: An #LdDocument object.
+ * @object: The object to be inserted.
+ * @pos: The position at which the object is to be inserted.
+ * Negative values will append to the end.
+ *
+ * Insert an object into the document.
+ */
+void
+ld_document_insert_object (LdDocument *self, LdDocumentObject *object, gint pos)
+{
+ g_return_if_fail (LD_IS_DOCUMENT (self));
+ g_return_if_fail (LD_IS_DOCUMENT_OBJECT (object));
+
+ if (!g_slist_find (self->priv->objects, object))
+ {
+ self->priv->objects =
+ g_slist_insert (self->priv->objects, object, pos);
+ g_object_ref (object);
+ }
+ g_signal_emit (self,
+ LD_DOCUMENT_GET_CLASS (self)->changed_signal, 0);
+}
+
+/**
+ * ld_document_remove_object:
+ * @self: An #LdDocument object.
+ * @object: The object to be removed.
+ *
+ * Remove an object from the document.
+ */
+void
+ld_document_remove_object (LdDocument *self, LdDocumentObject *object)
+{
+ g_return_if_fail (LD_IS_DOCUMENT (self));
+ g_return_if_fail (LD_IS_DOCUMENT_OBJECT (object));
+
+ if (g_slist_find (self->priv->objects, object))
+ {
+ ld_document_selection_remove (self, object);
+
+ self->priv->objects = g_slist_remove (self->priv->objects, object);
+ g_object_unref (object);
+ }
+ g_signal_emit (self,
+ LD_DOCUMENT_GET_CLASS (self)->changed_signal, 0);
+}
+
+/**
+ * ld_document_get_selection:
+ * @self: An #LdDocument object.
+ *
+ * Get a list of objects that are currently selected in the document.
+ * You mustn't make any changes to the list.
+ */
+GSList *
+ld_document_get_selection (LdDocument *self)
+{
+ g_return_val_if_fail (LD_IS_DOCUMENT (self), NULL);
+ return self->priv->selection;
+}
+
+/**
+ * ld_document_selection_add:
+ * @self: An #LdDocument object.
+ * @object: The object to be added to the selection.
+ * @pos: The position at which the object is to be inserted.
+ * Negative values will append to the end.
+ *
+ * Add an object to selection.
+ */
+void
+ld_document_selection_add (LdDocument *self, LdDocumentObject *object, gint pos)
+{
+ g_return_if_fail (LD_IS_DOCUMENT (self));
+ g_return_if_fail (LD_IS_DOCUMENT_OBJECT (object));
+
+ if (!g_slist_find (self->priv->selection, object)
+ && g_slist_find (self->priv->objects, object))
+ {
+ self->priv->selection =
+ g_slist_insert (self->priv->selection, object, pos);
+ g_object_ref (object);
+ }
+ g_signal_emit (self,
+ LD_DOCUMENT_GET_CLASS (self)->changed_signal, 0);
+}
+
+/**
+ * ld_document_selection_remove:
+ * @self: An #LdDocument object.
+ * @object: The object to be removed from the selection.
+ *
+ * Remove an object from the selection.
+ */
+void
+ld_document_selection_remove (LdDocument *self, LdDocumentObject *object)
+{
+ g_return_if_fail (LD_IS_DOCUMENT (self));
+ g_return_if_fail (LD_IS_DOCUMENT_OBJECT (object));
+
+ if (g_slist_find (self->priv->selection, object))
+ {
+ self->priv->selection = g_slist_remove (self->priv->selection, object);
+ g_object_unref (object);
+ }
+ g_signal_emit (self,
+ LD_DOCUMENT_GET_CLASS (self)->changed_signal, 0);
+}
diff --git a/src/ld-document.h b/src/ld-document.h
index 32eb0c4..12d59cb 100644
--- a/src/ld-document.h
+++ b/src/ld-document.h
@@ -14,7 +14,7 @@
G_BEGIN_DECLS
-#define LD_TYPE_DOCUMENT (ld_library_get_type ())
+#define LD_TYPE_DOCUMENT (ld_document_get_type ())
#define LD_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST \
((obj), LD_TYPE_DOCUMENT, LdDocument))
#define LD_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
@@ -28,6 +28,7 @@ G_BEGIN_DECLS
typedef struct _LdDocument LdDocument;
typedef struct _LdDocumentClass LdDocumentClass;
+typedef struct _LdDocumentPrivate LdDocumentPrivate;
/**
@@ -39,62 +40,46 @@ struct _LdDocument
{
/*< private >*/
GObject parent_instance;
+ LdDocumentPrivate *priv;
};
struct _LdDocumentClass
{
/*< private >*/
GObjectClass parent_class;
+
+ guint changed_signal;
};
GType ld_document_get_type (void) G_GNUC_CONST;
LdDocument *ld_document_new (void);
-gboolean ld_document_new_from_file (const char *file_name, GError *error);
-gboolean ld_document_save_to_file (const char *file_name, GError *error);
-
-#if 0
-/* ===== Data proposal ===================================================== */
-typedef struct _LdDocumentPrivate LdDocumentPrivate;
+void ld_document_clear (LdDocument *self);
+gboolean ld_document_load_from_file (LdDocument *self,
+ const gchar *filename, GError *error);
+gboolean ld_document_save_to_file (LdDocument *self,
+ const gchar *filename, GError *error);
+
+GSList *ld_document_get_objects (LdDocument *self);
+void ld_document_insert_object (LdDocument *self,
+ LdDocumentObject *object, gint pos);
+void ld_document_remove_object (LdDocument *self,
+ LdDocumentObject *object);
+
+GSList *ld_document_get_selection (LdDocument *self);
+void ld_document_selection_add (LdDocument *self,
+ LdDocumentObject *object, gint pos);
+void ld_document_selection_remove (LdDocument *self,
+ LdDocumentObject *object);
/*
- * LdDocumentPrivate:
- * @objects: All the objects in the document.
- * @selection: All currently selected objects.
- */
-struct _LdDocumentPrivate
-{
- GSList *objects;
- GSList *selection;
-};
-
-/* ===== Interface proposal ================================================ */
-/* The contents of the document have changed. */
-signal document-changed (...)
-
-/* Add a symbol to the document at specified coordinates. */
-/* TODO: Should the coordinates be double or int? */
-void
-ld_document_add_symbol (LdSymbol *symbol, x, y);
-
-/* Parse a document in JSON and insert it into the document. */
-gboolean
-ld_document_insert_json (LdDocument *self, GError *error);
-
-/* TODO: Create an interface for a list of this object: */
-/* NOTE: In the future, labels will be also supported. */
-LdDocumentSymbol
-
-/* TODO: Create an interface for wires between pins of various symbols. */
-
-/* TODO: Create an interface for object selection. */
-ld_document_selection_...
-
-gchar *
-ld_document_selection_get_json (LdDocument *self);
-
-#endif /* 0 */
+GSList *ld_document_get_connections (LdDocument *self);
+void ld_document_connection_add (LdDocument *self,
+ LdConnection *connection, gint pos);
+void ld_document_connection_remove (LdDocument *self,
+ LdConnection *connection);
+*/
G_END_DECLS
diff --git a/src/ld-window-main.c b/src/ld-window-main.c
index c44c7fe..0597d33 100644
--- a/src/ld-window-main.c
+++ b/src/ld-window-main.c
@@ -18,7 +18,10 @@
#include "ld-symbol-category.h"
#include "ld-library.h"
+#include "ld-document-object.h"
+#include "ld-document-symbol.h"
#include "ld-document.h"
+
#include "ld-canvas.h"
--
cgit v1.2.3-70-g09d2