summaryrefslogtreecommitdiffstats
path: root/src/libs/engine/events/RenameEvent.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-07-26 19:16:52 +0000
committerDavid Robillard <d@drobilla.net>2007-07-26 19:16:52 +0000
commitbee242f29045b82e50a4f112ac17f7e14344df78 (patch)
treee3c43801ab004b4b15581c63fff61dea33bcc104 /src/libs/engine/events/RenameEvent.cpp
parent90cb0280fdb356bc1474be31a15f8c6f24ed95ee (diff)
downloadingen-bee242f29045b82e50a4f112ac17f7e14344df78.tar.gz
ingen-bee242f29045b82e50a4f112ac17f7e14344df78.tar.bz2
ingen-bee242f29045b82e50a4f112ac17f7e14344df78.zip
Use PathTable for engine side objects.
Re-implement renaming and destroying more cleanly (not to mention workingly). git-svn-id: http://svn.drobilla.net/lad/ingen@638 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs/engine/events/RenameEvent.cpp')
-rw-r--r--src/libs/engine/events/RenameEvent.cpp45
1 files changed, 23 insertions, 22 deletions
diff --git a/src/libs/engine/events/RenameEvent.cpp b/src/libs/engine/events/RenameEvent.cpp
index 0a2b0239..a7dc4874 100644
--- a/src/libs/engine/events/RenameEvent.cpp
+++ b/src/libs/engine/events/RenameEvent.cpp
@@ -25,6 +25,8 @@
#include <raul/Path.hpp>
#include "ObjectStore.hpp"
+using namespace std;
+
namespace Ingen {
@@ -34,7 +36,7 @@ RenameEvent::RenameEvent(Engine& engine, SharedPtr<Shared::Responder> responder,
_name(name),
_new_path(_old_path.parent().base() + name),
_parent_patch(NULL),
- _store_treenode(NULL),
+ _store_iterator(engine.object_store()->objects().end()),
_error(NO_ERROR)
{
/*
@@ -59,34 +61,33 @@ RenameEvent::pre_process()
return;
}
- if (_engine.object_store()->find(_new_path)) {
- _error = OBJECT_EXISTS;
- QueuedEvent::pre_process();
- return;
- }
-
- TreeNode<GraphObject*>* obj = _engine.object_store()->remove(_old_path);
-
- if (obj == NULL) {
+ _store_iterator = _engine.object_store()->find(_old_path);
+ if (_store_iterator == _engine.object_store()->objects().end()) {
_error = OBJECT_NOT_FOUND;
QueuedEvent::pre_process();
return;
}
- // Renaming only works for Nodes and Patches (which are Nodes)
- /*if (obj->as_node() == NULL) {
- _error = OBJECT_NOT_RENAMABLE;
- QueuedEvent::pre_process();
- return;
- }*/
+ Table<Path,GraphObject*> removed = _engine.object_store()->remove(_store_iterator);
+ assert(removed.size() > 0);
- if (obj != NULL) {
- obj->node()->set_path(_new_path);
- obj->key(_new_path);
- _engine.object_store()->add(obj);
- assert(obj->node()->path() == _new_path);
+ for (Table<Path,GraphObject*>::iterator i = removed.begin(); i != removed.end(); ++i) {
+ const Path& child_old_path = i->first;
+ assert(Path::descendant_comparator(_old_path, child_old_path));
+
+ Path child_new_path;
+ if (child_old_path == _old_path)
+ child_new_path = _new_path;
+ else
+ child_new_path = _new_path.base() + child_old_path.substr(_old_path.length()+1);
+
+ cerr << "Renamed " << child_old_path << " -> " << child_new_path << endl;
+ i->second->set_path(child_new_path);
+ i->first = child_new_path;
}
-
+
+ _engine.object_store()->add(removed);
+
QueuedEvent::pre_process();
}