From 715d577a38d04a98405a015fd18d49c0fed40c21 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 30 Dec 2009 15:48:50 +0000 Subject: Fix renaming (fix ticket #458). git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2324 a436a847-0d15-0410-975c-d299462d15a1 --- src/client/ClientStore.cpp | 8 ++--- src/client/ObjectModel.cpp | 19 +++++++++- src/client/ObjectModel.hpp | 4 +-- src/engine/GraphObjectImpl.cpp | 2 +- src/engine/QueuedEngineInterface.cpp | 6 ++-- src/gui/RenameWindow.cpp | 69 ++++++++++++++++++++++-------------- src/gui/RenameWindow.hpp | 6 ++-- src/gui/ingen_gui.glade | 55 ++++++++++++++++++++-------- src/shared/ResourceImpl.cpp | 9 ++++- src/shared/ResourceImpl.hpp | 4 ++- 10 files changed, 127 insertions(+), 55 deletions(-) diff --git a/src/client/ClientStore.cpp b/src/client/ClientStore.cpp index b0b6bdbf..5f379035 100644 --- a/src/client/ClientStore.cpp +++ b/src/client/ClientStore.cpp @@ -253,13 +253,13 @@ void ClientStore::put(const URI& uri, const Resource::Properties& properties) { typedef Resource::Properties::const_iterator iterator; - /*cerr << "CLIENT PUT " << uri << " {" << endl; + cerr << "CLIENT PUT " << uri << " {" << endl; for (iterator i = properties.begin(); i != properties.end(); ++i) cerr << "\t" << i->first << " = " << i->second << " :: " << i->second.type() << endl; - cerr << "}" << endl;*/ + cerr << "}" << endl; bool is_path = Path::is_valid(uri.str()); - bool is_meta = uri.substr(0, 6) == "meta:#"; + bool is_meta = ResourceImpl::is_meta_uri(uri); if (!(is_path || is_meta)) { const URI& type_uri = properties.find("rdf:type")->second.get_uri(); @@ -366,7 +366,7 @@ ClientStore::set_property(const URI& subject_uri, const URI& predicate, const At cerr << "ERROR: Property '" << predicate << "' is invalid" << endl; } else if (subject) { subject->set_property(predicate, value); - } else if (subject_uri.substr(0, 6) == "meta:#") { + } else if (ResourceImpl::is_meta_uri(subject_uri)) { Path instance_path = string("/") + subject_uri.substr(hash + 1); SharedPtr om = PtrCast(subject); if (om) diff --git a/src/client/ObjectModel.cpp b/src/client/ObjectModel.cpp index 3ffd96bd..e41be6c9 100644 --- a/src/client/ObjectModel.cpp +++ b/src/client/ObjectModel.cpp @@ -29,7 +29,7 @@ namespace Client { ObjectModel::ObjectModel(const Path& path) : ResourceImpl(path) - , _meta(std::string("meta:#") + path.chop_start("/")) + , _meta(ResourceImpl::meta_uri(path)) , _path(path) { } @@ -103,6 +103,23 @@ ObjectModel::set(SharedPtr o) } +void +ObjectModel::set_path(const Raul::Path& p) +{ + _path = p; + _meta.set_uri(ResourceImpl::meta_uri(_path)); + signal_moved.emit(); +} + + +void +ObjectModel::set_parent(SharedPtr p) +{ + assert(p); + _parent = p; +} + + } // namespace Client } // namespace Ingen diff --git a/src/client/ObjectModel.hpp b/src/client/ObjectModel.hpp index 72692d65..9b0544f6 100644 --- a/src/client/ObjectModel.hpp +++ b/src/client/ObjectModel.hpp @@ -82,8 +82,8 @@ protected: ObjectModel(const Raul::Path& path); - virtual void set_path(const Raul::Path& p) { _path = p; signal_moved.emit(); } - virtual void set_parent(SharedPtr p) { assert(p); _parent = p; } + virtual void set_path(const Raul::Path& p); + virtual void set_parent(SharedPtr p); virtual void add_child(SharedPtr c) {} virtual bool remove_child(SharedPtr c) { return true; } diff --git a/src/engine/GraphObjectImpl.cpp b/src/engine/GraphObjectImpl.cpp index 40cdc792..50b0e58b 100644 --- a/src/engine/GraphObjectImpl.cpp +++ b/src/engine/GraphObjectImpl.cpp @@ -32,7 +32,7 @@ GraphObjectImpl::GraphObjectImpl(GraphObjectImpl* parent, const std::string& nam : ResourceImpl((parent ? parent->path().base() : Raul::Path::root_uri) + name) , _parent(parent) , _name(name) - , _meta(std::string("meta:#") + path().chop_start("/")) + , _meta(ResourceImpl::meta_uri(uri())) , _polyphonic(polyphonic) { assert(parent == NULL || _name.length() > 0); diff --git a/src/engine/QueuedEngineInterface.cpp b/src/engine/QueuedEngineInterface.cpp index 09e711cc..421342e5 100644 --- a/src/engine/QueuedEngineInterface.cpp +++ b/src/engine/QueuedEngineInterface.cpp @@ -155,14 +155,14 @@ void QueuedEngineInterface::put(const URI& uri, const Resource::Properties& properties) { - bool meta = uri.substr(0, 6) == "meta:#"; + bool meta = ResourceImpl::is_meta_uri(uri); URI subject(meta ? (string("path:/") + uri.substr(6)) : uri.str()); - /*cerr << "ENGINE PUT " << subject << " {" << endl; + cerr << "ENGINE PUT " << subject << " {" << endl; typedef Resource::Properties::const_iterator iterator; for (iterator i = properties.begin(); i != properties.end(); ++i) cerr << "\t" << i->first << " = " << i->second << " :: " << i->second.type() << endl; - cerr << "}" << endl;*/ + cerr << "}" << endl; push_queued(new Events::SetMetadata(_engine, _responder, now(), this, true, meta, subject, properties)); } diff --git a/src/gui/RenameWindow.cpp b/src/gui/RenameWindow.cpp index b6c41e68..32210466 100644 --- a/src/gui/RenameWindow.cpp +++ b/src/gui/RenameWindow.cpp @@ -33,12 +33,14 @@ namespace GUI { RenameWindow::RenameWindow(BaseObjectType* cobject, const Glib::RefPtr& glade_xml) : Window(cobject) { - glade_xml->get_widget("rename_name_entry", _name_entry); + glade_xml->get_widget("rename_symbol_entry", _symbol_entry); + glade_xml->get_widget("rename_label_entry", _label_entry); glade_xml->get_widget("rename_message_label", _message_label); glade_xml->get_widget("rename_cancel_button", _cancel_button); glade_xml->get_widget("rename_ok_button", _ok_button); - _name_entry->signal_changed().connect(sigc::mem_fun(this, &RenameWindow::name_changed)); + _symbol_entry->signal_changed().connect(sigc::mem_fun(this, &RenameWindow::symbol_changed)); + _label_entry->signal_changed().connect(sigc::mem_fun(this, &RenameWindow::label_changed)); _cancel_button->signal_clicked().connect(sigc::mem_fun(this, &RenameWindow::cancel_clicked)); _ok_button->signal_clicked().connect(sigc::mem_fun(this, &RenameWindow::ok_clicked)); @@ -53,7 +55,10 @@ void RenameWindow::set_object(SharedPtr object) { _object = object; - _name_entry->set_text(object->path().name()); + _symbol_entry->set_text(object->path().name()); + const Atom& name_atom = object->get_property("lv2:name"); + _label_entry->set_text( + (name_atom.type() == Atom::STRING) ? name_atom.get_string() : ""); } @@ -61,7 +66,7 @@ void RenameWindow::present(SharedPtr object) { set_object(object); - _name_entry->grab_focus(); + _symbol_entry->grab_focus(); Gtk::Window::present(); } @@ -70,28 +75,31 @@ RenameWindow::present(SharedPtr object) * Used to display warning messages, and enable/disable the rename button. */ void -RenameWindow::name_changed() +RenameWindow::symbol_changed() { - assert(_name_entry); - assert(_message_label); - assert(_object); - assert(_object->parent()); - - string name = _name_entry->get_text(); - if (name.find("/") != string::npos) { - _message_label->set_text("Name may not contain '/'"); + const string& symbol = _symbol_entry->get_text(); + if (symbol.length() == 0) { + _message_label->set_text("Symbol must be at least 1 character"); _ok_button->property_sensitive() = false; - } else if (!Path::is_valid_name(name)) { - _message_label->set_text("Name contains invalid characters"); + } else if (!Path::is_valid_name(symbol)) { + _message_label->set_text("Symbol contains invalid characters"); _ok_button->property_sensitive() = false; - } else if (name == _object->path().name()) { - _message_label->set_text(""); - _ok_button->property_sensitive() = false; - } else if ((App::instance().store()->object(_object->parent()->path().base() + name))) { - _message_label->set_text("An object already exists with that name."); + } else if (App::instance().store()->object(_object->parent()->path().base() + symbol)) { + _message_label->set_text("An object already exists with that path"); _ok_button->property_sensitive() = false; - } else if (name.length() == 0) { + } else { _message_label->set_text(""); + _ok_button->property_sensitive() = true; + } +} + + +void +RenameWindow::label_changed() +{ + const string& label = _label_entry->get_text(); + if (label == "") { + _message_label->set_text("Label must be at least 1 character"); _ok_button->property_sensitive() = false; } else { _message_label->set_text(""); @@ -103,7 +111,7 @@ RenameWindow::name_changed() void RenameWindow::cancel_clicked() { - _name_entry->set_text(""); + _symbol_entry->set_text(""); hide(); } @@ -117,11 +125,20 @@ RenameWindow::cancel_clicked() void RenameWindow::ok_clicked() { - string name = _name_entry->get_text(); - assert(name.length() > 0); - assert(name.find("/") == string::npos); + const string& symbol = _symbol_entry->get_text(); + const string& label = _label_entry->get_text(); + Path path = _object->path(); + const Atom& name_atom = _object->get_property("lv2:name"); + + if (Path::is_valid_name(symbol) && symbol != _object->path().name()) { + path = _object->path().parent().base() + symbol; + App::instance().engine()->move(_object->path(), path); + } - App::instance().engine()->move(_object->path(), _object->path().parent().base() + name); + if (label != "" && (!name_atom.is_valid() || label != name_atom.get_string())) { + App::instance().engine()->set_property(path, + "lv2:name", Atom(Atom::STRING, label)); + } hide(); } diff --git a/src/gui/RenameWindow.hpp b/src/gui/RenameWindow.hpp index 0e014534..360fc36f 100644 --- a/src/gui/RenameWindow.hpp +++ b/src/gui/RenameWindow.hpp @@ -44,13 +44,15 @@ public: private: void set_object(SharedPtr object); - void name_changed(); + void symbol_changed(); + void label_changed(); void cancel_clicked(); void ok_clicked(); SharedPtr _object; - Gtk::Entry* _name_entry; + Gtk::Entry* _symbol_entry; + Gtk::Entry* _label_entry; Gtk::Label* _message_label; Gtk::Button* _cancel_button; Gtk::Button* _ok_button; diff --git a/src/gui/ingen_gui.glade b/src/gui/ingen_gui.glade index 462b3273..3d42a76d 100644 --- a/src/gui/ingen_gui.glade +++ b/src/gui/ingen_gui.glade @@ -2141,35 +2141,64 @@ 250 Rename center-on-parent + True dialog - + True 5 + vertical - + True + 2 + 2 + 8 True - New name: + Symbol: - False - False - 0 + GTK_FILL + + + + + True + True + + True + + + 1 + 2 + 1 + 2 + + + + + True + Label: + + + 1 + 2 + GTK_FILL - + True True True - True + True - 1 + 1 + 2 @@ -2180,18 +2209,16 @@ True - True - False - 6 + 12 1 True - 5 + 8 end @@ -2199,7 +2226,7 @@ True True True - False + True True diff --git a/src/shared/ResourceImpl.cpp b/src/shared/ResourceImpl.cpp index 6af25ef0..93d6ea03 100644 --- a/src/shared/ResourceImpl.cpp +++ b/src/shared/ResourceImpl.cpp @@ -25,8 +25,15 @@ namespace Ingen { namespace Shared { +bool +ResourceImpl::is_meta_uri(const Raul::URI& uri) +{ + return uri.substr(0, 6) == "meta:#"; +} + + const Raul::URI -ResourceImpl::meta_uri(const Raul::URI& base, const Raul::URI& uri) +ResourceImpl::meta_uri(const Raul::URI& uri) { return string("meta:#") + uri.chop_start("/"); } diff --git a/src/shared/ResourceImpl.hpp b/src/shared/ResourceImpl.hpp index 9b10ec15..b4afc50a 100644 --- a/src/shared/ResourceImpl.hpp +++ b/src/shared/ResourceImpl.hpp @@ -32,6 +32,7 @@ class ResourceImpl : virtual public Resource public: ResourceImpl(const Raul::URI& uri) : _uri(uri) {} + virtual void set_uri(const Raul::URI& uri) { _uri = uri; } virtual const Raul::URI uri() const { return _uri.str(); } const Properties& properties() const { return _properties; } @@ -55,7 +56,8 @@ public: bool& node, bool& port, bool& is_output, PortType& data_type); - static const Raul::URI meta_uri(const Raul::URI& base, const Raul::URI& uri); + static bool is_meta_uri(const Raul::URI& uri); + static const Raul::URI meta_uri(const Raul::URI& uri); protected: Raul::Atom& set_property(const Raul::URI& uri, const Raul::Atom& value) const; -- cgit v1.2.1