diff options
author | David Robillard <d@drobilla.net> | 2009-12-30 15:48:50 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-12-30 15:48:50 +0000 |
commit | 715d577a38d04a98405a015fd18d49c0fed40c21 (patch) | |
tree | 02102070145066128a6ff4181256da59c63aacf7 /src/gui | |
parent | 87be66d677b1947ef1b5f866c44b0beb1263ac17 (diff) | |
download | ingen-715d577a38d04a98405a015fd18d49c0fed40c21.tar.gz ingen-715d577a38d04a98405a015fd18d49c0fed40c21.tar.bz2 ingen-715d577a38d04a98405a015fd18d49c0fed40c21.zip |
Fix renaming (fix ticket #458).
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2324 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/RenameWindow.cpp | 69 | ||||
-rw-r--r-- | src/gui/RenameWindow.hpp | 6 | ||||
-rw-r--r-- | src/gui/ingen_gui.glade | 55 |
3 files changed, 88 insertions, 42 deletions
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<Gnome::Glade::Xml>& 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<ObjectModel> 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<ObjectModel> object) { set_object(object); - _name_entry->grab_focus(); + _symbol_entry->grab_focus(); Gtk::Window::present(); } @@ -70,28 +75,31 @@ RenameWindow::present(SharedPtr<ObjectModel> 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<ObjectModel> object); - void name_changed(); + void symbol_changed(); + void label_changed(); void cancel_clicked(); void ok_clicked(); SharedPtr<ObjectModel> _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 @@ <property name="width_request">250</property> <property name="title" translatable="yes">Rename</property> <property name="window_position">center-on-parent</property> + <property name="destroy_with_parent">True</property> <property name="type_hint">dialog</property> <child> - <widget class="GtkVBox" id="vbox15"> + <widget class="GtkVBox" id="vbox1"> <property name="visible">True</property> <property name="border_width">5</property> + <property name="orientation">vertical</property> <child> - <widget class="GtkHBox" id="hbox53"> + <widget class="GtkTable" id="table2"> <property name="visible">True</property> + <property name="n_rows">2</property> + <property name="n_columns">2</property> + <property name="row_spacing">8</property> <child> <widget class="GtkLabel" id="label95"> <property name="visible">True</property> - <property name="label" translatable="yes">New name: </property> + <property name="label" translatable="yes">Symbol: </property> </widget> <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> + <property name="x_options">GTK_FILL</property> + </packing> + </child> + <child> + <widget class="GtkEntry" id="rename_label_entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="invisible_char">●</property> + <property name="activates_default">True</property> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="label95"> + <property name="visible">True</property> + <property name="label" translatable="yes">Label: </property> + </widget> + <packing> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="x_options">GTK_FILL</property> </packing> </child> <child> - <widget class="GtkEntry" id="rename_name_entry"> + <widget class="GtkEntry" id="rename_symbol_entry"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="has_focus">True</property> - <property name="is_focus">True</property> + <property name="invisible_char">●</property> <property name="activates_default">True</property> </widget> <packing> - <property name="position">1</property> + <property name="left_attach">1</property> + <property name="right_attach">2</property> </packing> </child> </widget> @@ -2180,18 +2209,16 @@ <child> <widget class="GtkLabel" id="rename_message_label"> <property name="visible">True</property> - <property name="wrap">True</property> </widget> <packing> - <property name="expand">False</property> - <property name="padding">6</property> + <property name="padding">12</property> <property name="position">1</property> </packing> </child> <child> <widget class="GtkHButtonBox" id="hbuttonbox4"> <property name="visible">True</property> - <property name="spacing">5</property> + <property name="spacing">8</property> <property name="layout_style">end</property> <child> <widget class="GtkButton" id="rename_cancel_button"> @@ -2199,7 +2226,7 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="can_default">True</property> - <property name="receives_default">False</property> + <property name="receives_default">True</property> <property name="use_stock">True</property> </widget> <packing> |