[dia/zbrown/object-change: 16/16] lib: drop ObjectChange, DiaObjectChangeLegacy
- From: Zander Brown <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia/zbrown/object-change: 16/16] lib: drop ObjectChange, DiaObjectChangeLegacy
- Date: Sat, 10 Oct 2020 22:05:56 +0000 (UTC)
commit 87ebff0e03ca8ce6b0a71a592a4ff5619933eb8d
Author: Zander Brown <zbrown gnome org>
Date: Sat Oct 10 22:42:37 2020 +0100
lib: drop ObjectChange, DiaObjectChangeLegacy
We've now ported all usage to DiaObjectChange direct
docs/dia/dia-docs.xml | 4 +-
lib/dia-object-change-legacy.c | 75 -----------------
lib/dia-object-change-legacy.h | 39 ---------
lib/dia-object-change.c | 18 ++++
lib/dia-object-change.h | 10 +++
lib/{objchange.c => dia-state-object-change.c} | 15 +++-
lib/dia-state-object-change.h | 80 ++++++++++++++++++
lib/dummy_dep.h | 2 +-
lib/meson.build | 6 +-
lib/objchange.h | 109 -------------------------
lib/object.c | 23 ++++--
objects/ER/attribute.c | 2 +-
objects/UML/association.c | 2 +-
objects/UML/class.c | 2 +-
14 files changed, 144 insertions(+), 243 deletions(-)
---
diff --git a/docs/dia/dia-docs.xml b/docs/dia/dia-docs.xml
index ec3e4c5e1..028b02f20 100644
--- a/docs/dia/dia-docs.xml
+++ b/docs/dia/dia-docs.xml
@@ -69,10 +69,10 @@
<xi:include href="xml/connection.xml"/>
<xi:include href="xml/connpoint_line.xml"/>
<xi:include href="xml/dia_svg.xml"/>
- <xi:include href="xml/objchange.xml"/>
<xi:include href="xml/dia-change.xml" />
<xi:include href="xml/dia-object-change.xml" />
- <xi:include href="xml/dia-object-change-legacy.xml" />
+ <xi:include href="xml/obj-state-object-change.xml"/>
+ <xi:include href="xml/dia-object-change-list.xml" />
<xi:include href="xml/object-alias.xml"/>
<xi:include href="xml/create.xml"/>
<xi:include href="xml/diatransform.xml"/>
diff --git a/lib/dia-object-change.c b/lib/dia-object-change.c
index 398bc1759..c97995290 100644
--- a/lib/dia-object-change.c
+++ b/lib/dia-object-change.c
@@ -27,6 +27,24 @@
#include "object.h"
+/**
+ * SECTION:dia-object-change
+ *
+ * Forming the basic of undo support to be implemented in objects
+ *
+ * Object implementations need some effort to support undo/redo
+ *
+ * Return value of object changing functions and methods of DiaObject
+ *
+ * FIXME: #DiaObjectChange functions should not require the changed object
+ * as an argument. Every change object should keep track of the
+ * relevant object instead. The second argument in the above typedefs
+ * is deprecated and should not be relied on.
+ *
+ * Replaces ObjectChange
+ */
+
+
static void
dia_object_change_real_apply (DiaObjectChange *self,
DiaObject *object)
diff --git a/lib/dia-object-change.h b/lib/dia-object-change.h
index c500f4271..935dda794 100644
--- a/lib/dia-object-change.h
+++ b/lib/dia-object-change.h
@@ -117,6 +117,16 @@ struct _DiaObjectChange {
};
+/**
+ * DiaObjectChangeClass:
+ * @apply: do the change
+ * @revert: undo the effects of @apply
+ * @free: clear fields (called during destruction)
+ *
+ * Since: 0.98
+ *
+ * Stability: Stable
+ */
struct _DiaObjectChangeClass {
GTypeClass parent;
diff --git a/lib/objchange.c b/lib/dia-state-object-change.c
similarity index 87%
rename from lib/objchange.c
rename to lib/dia-state-object-change.c
index bc341d3df..fd9abc2e9 100644
--- a/lib/objchange.c
+++ b/lib/dia-state-object-change.c
@@ -18,7 +18,7 @@
#include <config.h>
-#include "objchange.h"
+#include "dia-state-object-change.h"
/**
@@ -82,6 +82,19 @@ dia_state_object_change_free (DiaObjectChange *self)
}
+/**
+ * dia_state_object_change_new:
+ * @obj: the #DiaObject whos state changed
+ * @old_state: the previous #ObjectState
+ * @get_state: a #GetStateFunc used to generate the #ObjectState of @obj
+ * @set_state: a #SetStateFunc used to apply a #ObjectState to @obj
+ *
+ * Create a single change from the ObjectState
+ *
+ * Since: 0.98
+ *
+ * Stability: Stable
+ */
DiaObjectChange *
dia_state_object_change_new (DiaObject *obj,
ObjectState *old_state,
diff --git a/lib/dia-state-object-change.h b/lib/dia-state-object-change.h
new file mode 100644
index 000000000..c0432b83a
--- /dev/null
+++ b/lib/dia-state-object-change.h
@@ -0,0 +1,80 @@
+/* Dia -- an diagram creation/manipulation program
+ * Copyright (C) 1999 Alexander Larsson
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#pragma once
+
+#include "diatypes.h"
+#include "dia-object-change.h"
+
+G_BEGIN_DECLS
+
+#define DIA_TYPE_STATE_OBJECT_CHANGE dia_state_object_change_get_type ()
+G_DECLARE_FINAL_TYPE (DiaStateObjectChange,
+ dia_state_object_change,
+ DIA, STATE_OBJECT_CHANGE,
+ DiaObjectChange)
+
+
+/**
+ * ObjectState:
+ * @free: (nullable): destroy the #ObjectState content
+ *
+ * Since: dawn-of-time
+ */
+struct _ObjectState {
+ void (*free) (ObjectState *state);
+};
+
+
+/**
+ * GetStateFunc:
+ *
+ * Gets the internal state from the object.
+ * This is used to snapshot the object state
+ * so that it can be stored for undo/redo.
+ *
+ * Need not save state that only depens on
+ * the object and it's handles positions.
+ *
+ * The calling function owns the returned reference.
+ *
+ * Since: dawn-of-time
+ */
+typedef ObjectState * (*GetStateFunc) (DiaObject* obj);
+
+
+/**
+ * SetStateFunc:
+ *
+ * Sets the internal state from the object.
+ * This is used to snapshot the object state
+ * so that it can be stored for undo/redo.
+ *
+ * The called function owns the reference and is
+ * responsible for freeing it.
+ *
+ * Since: dawn-of-time
+ */
+typedef void (*SetStateFunc) (DiaObject* obj, ObjectState *state);
+
+DiaObjectChange *dia_state_object_change_new (DiaObject *obj,
+ ObjectState *old_state,
+ GetStateFunc get_state,
+ SetStateFunc set_state);
+
+G_END_DECLS
diff --git a/lib/dummy_dep.h b/lib/dummy_dep.h
index bb458f9fb..42b9eecb7 100644
--- a/lib/dummy_dep.h
+++ b/lib/dummy_dep.h
@@ -34,7 +34,7 @@
#include "dynamic_obj.h"
#include "connectionpoint.h"
#include "diafontselector.h"
-#include "objchange.h"
+#include "dia-state-object-change.h"
/* This is a file with dummy dependencies so that all
object files will be linked into the app.
diff --git a/lib/meson.build b/lib/meson.build
index 162c89f59..bf13db1d6 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -87,14 +87,12 @@ libdia_sources = stdprop_sources + [
'polyshape.h',
'beziershape.c',
'beziershape.h',
- 'objchange.c',
- 'objchange.h',
'dia-change.c',
'dia-change.h',
'dia-object-change.c',
'dia-object-change.h',
- 'dia-object-change-legacy.c',
- 'dia-object-change-legacy.h',
+ 'dia-state-object-change.c',
+ 'dia-state-object-change.h',
'dia-object-change-list.c',
'dia-object-change-list.h',
'dialogs.c',
diff --git a/lib/object.c b/lib/object.c
index 7e4a53f0f..13f125570 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -27,7 +27,6 @@
#include "message.h"
#include "parent.h"
#include "dia-layer.h"
-#include "dia-object-change-legacy.h"
#include "dummy_dep.h"
@@ -347,12 +346,17 @@ object_list_move_delta (GList *objects, Point *delta)
}
-typedef struct _ObjectChangeExchange {
- ObjectChange change;
- DiaObject *orig;
- DiaObject *subst;
- gboolean applied;
-} ObjectChangeExchange;
+struct _DiaExchangeObjectChange {
+ DiaObjectChange change;
+ DiaObject *orig;
+ DiaObject *subst;
+ gboolean applied;
+};
+
+
+DIA_DEFINE_OBJECT_CHANGE (DiaExchangeObjectChange,
+ dia_exchange_object_change)
+
static Handle *
_find_connectable (DiaObject *obj, int *num)
@@ -424,10 +428,11 @@ object_copy_style (DiaObject *dest, const DiaObject *src)
prop_list_free (props);
}
+
static void
-_object_exchange (ObjectChange *change, DiaObject *obj)
+_object_exchange (DiaObjectChange *self, DiaObject *obj)
{
- ObjectChangeExchange *c = (ObjectChangeExchange *)change;
+ DiaExchangeObjectChange *c = DIA_EXCHANGE_OBJECT_CHANGE (self);
DiaLayer *layer = dia_object_get_parent_layer (obj);
DiagramData *dia = layer ? dia_layer_get_parent_diagram (layer) : NULL;
DiaObject *subst = (obj == c->orig) ? c->subst : c->orig;
diff --git a/objects/ER/attribute.c b/objects/ER/attribute.c
index d9bfec0b7..a50f0fb05 100644
--- a/objects/ER/attribute.c
+++ b/objects/ER/attribute.c
@@ -31,7 +31,7 @@
#include "diarenderer.h"
#include "attributes.h"
#include "properties.h"
-#include "objchange.h"
+#include "dia-state-object-change.h"
#include "pixmaps/attribute.xpm"
diff --git a/objects/UML/association.c b/objects/UML/association.c
index d7dd258ae..9cd5bdd02 100644
--- a/objects/UML/association.c
+++ b/objects/UML/association.c
@@ -62,7 +62,7 @@
#include "arrows.h"
#include "uml.h"
#include "properties.h"
-#include "objchange.h"
+#include "dia-state-object-change.h"
#include "pixmaps/association.xpm"
diff --git a/objects/UML/class.c b/objects/UML/class.c
index 62295fd9f..b71d737cc 100644
--- a/objects/UML/class.c
+++ b/objects/UML/class.c
@@ -35,7 +35,7 @@
#include "properties.h"
#include "diamenu.h"
#include "class.h"
-#include "objchange.h"
+#include "dia-state-object-change.h"
#include "pixmaps/umlclass.xpm"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]