From c8ae7295e911c62cf9dedf90187656937cc18cbb Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 30 Jul 2016 13:10:13 -0400 Subject: Add undo support --- ingen/AtomWriter.hpp | 9 +++++++-- ingen/Interface.hpp | 14 +++++++++++--- ingen/Resource.hpp | 15 +++++++++++++-- ingen/URIs.hpp | 8 ++++++-- ingen/client/ClientStore.hpp | 4 +++- ingen/client/SigClientInterface.hpp | 4 +++- ingen/ingen.h | 6 +++++- 7 files changed, 48 insertions(+), 12 deletions(-) (limited to 'ingen') diff --git a/ingen/AtomWriter.hpp b/ingen/AtomWriter.hpp index 6ae6bdbc..9ea5fa27 100644 --- a/ingen/AtomWriter.hpp +++ b/ingen/AtomWriter.hpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2015 David Robillard + Copyright 2007-2016 David Robillard Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -35,7 +35,8 @@ class INGEN_API AtomWriter : public Interface { public: AtomWriter(URIMap& map, URIs& uris, AtomSink& sink); - ~AtomWriter() {} + + ~AtomWriter(); Raul::URI uri() const { return Raul::URI("ingen:/clients/atom_writer"); @@ -74,6 +75,10 @@ public: const Raul::URI& predicate, const Atom& value); + void undo(); + + void redo(); + void set_response_id(int32_t id); void get(const Raul::URI& uri); diff --git a/ingen/Interface.hpp b/ingen/Interface.hpp index 8f6e25c4..a1a93c06 100644 --- a/ingen/Interface.hpp +++ b/ingen/Interface.hpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2015 David Robillard + Copyright 2007-2016 David Robillard Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -55,10 +55,14 @@ public: virtual void set_respondee(SPtr respondee) {} - /** Begin an atomic bundle */ + /** Begin a transaction. + * + * This does not guarantee strict atomicity, but the events in a bundle will be + * considered one operation, and they will all be undone at once. + */ virtual void bundle_begin() = 0; - /** End (and send) an atomic bundle */ + /** End a transaction. */ virtual void bundle_end() = 0; virtual void put(const Raul::URI& uri, @@ -90,6 +94,10 @@ public: const Raul::URI& predicate, const Atom& value) = 0; + virtual void undo() = 0; + + virtual void redo() = 0; + /** Set the ID to use to respond to the next message. * Setting the ID to 0 will disable responses. */ diff --git a/ingen/Resource.hpp b/ingen/Resource.hpp index 31d23dac..604428ce 100644 --- a/ingen/Resource.hpp +++ b/ingen/Resource.hpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2015 David Robillard + Copyright 2007-2016 David Robillard Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -122,6 +122,15 @@ public: Graph ctx = Graph::DEFAULT) { insert(std::make_pair(key, Property(value, ctx))); } + + bool contains(const Raul::URI& key, const Atom& value) { + for (const_iterator i = find(key); i != end() && i->first == key; ++i) { + if (i->second == value) { + return true; + } + } + return false; + } }; /** Get a single property value. @@ -156,8 +165,10 @@ public: * This will not remove any existing values, so if properties with * predicate `uri` and values other than `value` exist, this will result * in multiple values for the property. + * + * @return True iff a new property was added. */ - virtual void add_property(const Raul::URI& uri, + virtual bool add_property(const Raul::URI& uri, const Atom& value, Graph ctx = Graph::DEFAULT); diff --git a/ingen/URIs.hpp b/ingen/URIs.hpp index 290f8c94..52921085 100644 --- a/ingen/URIs.hpp +++ b/ingen/URIs.hpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2015 David Robillard + Copyright 2007-2016 David Robillard Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -100,9 +100,13 @@ public: const Quark doap_name; const Quark ingen_Arc; const Quark ingen_Block; + const Quark ingen_BundleEnd; + const Quark ingen_BundleStart; const Quark ingen_Graph; const Quark ingen_GraphPrototype; const Quark ingen_Internal; + const Quark ingen_Redo; + const Quark ingen_Undo; const Quark ingen_activity; const Quark ingen_arc; const Quark ingen_block; @@ -183,9 +187,9 @@ public: const Quark patch_subject; const Quark patch_value; const Quark patch_wildcard; + const Quark pprops_logarithmic; const Quark pset_Preset; const Quark pset_preset; - const Quark pprops_logarithmic; const Quark rdf_type; const Quark rdfs_Class; const Quark rdfs_label; diff --git a/ingen/client/ClientStore.hpp b/ingen/client/ClientStore.hpp index 9f18f16d..de603458 100644 --- a/ingen/client/ClientStore.hpp +++ b/ingen/client/ClientStore.hpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2015 David Robillard + Copyright 2007-2016 David Robillard Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -102,6 +102,8 @@ public: void del(const Raul::URI& uri); + void undo() {} + void redo() {} void set_response_id(int32_t id) {} void get(const Raul::URI& uri) {} void response(int32_t id, Status status, const std::string& subject) {} diff --git a/ingen/client/SigClientInterface.hpp b/ingen/client/SigClientInterface.hpp index 72e34422..33430480 100644 --- a/ingen/client/SigClientInterface.hpp +++ b/ingen/client/SigClientInterface.hpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2015 David Robillard + Copyright 2007-2016 David Robillard Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -114,6 +114,8 @@ protected: void set_property(const Raul::URI& subject, const Raul::URI& key, const Atom& value) { EMIT(property_change, subject, key, value); } + void undo() {} + void redo() {} void set_response_id(int32_t id) {} void get(const Raul::URI& uri) {} }; diff --git a/ingen/ingen.h b/ingen/ingen.h index d9091039..3af2042c 100644 --- a/ingen/ingen.h +++ b/ingen/ingen.h @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2014-2015 David Robillard + Copyright 2014-2016 David Robillard Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -38,11 +38,15 @@ #define INGEN__Arc INGEN_NS "Arc" #define INGEN__Block INGEN_NS "Block" +#define INGEN__BundleEnd INGEN_NS "BundleEnd" +#define INGEN__BundleStart INGEN_NS "BundleStart" #define INGEN__Graph INGEN_NS "Graph" #define INGEN__GraphPrototype INGEN_NS "GraphPrototype" #define INGEN__Internal INGEN_NS "Internal" #define INGEN__Node INGEN_NS "Node" #define INGEN__Plugin INGEN_NS "Plugin" +#define INGEN__Redo INGEN_NS "Redo" +#define INGEN__Undo INGEN_NS "Undo" #define INGEN__activity INGEN_NS "activity" #define INGEN__arc INGEN_NS "arc" #define INGEN__block INGEN_NS "block" -- cgit v1.2.1