From bee242f29045b82e50a4f112ac17f7e14344df78 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 26 Jul 2007 19:16:52 +0000 Subject: 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 --- src/libs/engine/events/RenameEvent.cpp | 45 +++++++++++++++++----------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'src/libs/engine/events/RenameEvent.cpp') 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 #include "ObjectStore.hpp" +using namespace std; + namespace Ingen { @@ -34,7 +36,7 @@ RenameEvent::RenameEvent(Engine& engine, SharedPtr 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* 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 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::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(); } -- cgit v1.2.1