From cd9c2adf12076194e8ea6c1cb2eb5ab641fb96ef Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 28 Jan 2010 04:16:30 +0000 Subject: Universal properties window. Instead of custom designed limited dialogs for each object type, this replacement is built dynamically and shows all properties of an object. Preliminary work, this version allows the user to wreck things by changing properties that shouldn't ever be changed manually. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2385 a436a847-0d15-0410-975c-d299462d15a1 --- src/common/interface/Resource.hpp | 2 + src/gui/Controls.cpp | 8 +- src/gui/LoadPluginWindow.hpp | 30 +-- src/gui/NodePropertiesWindow.cpp | 76 ------ src/gui/NodePropertiesWindow.hpp | 61 ----- src/gui/PatchPropertiesWindow.cpp | 103 -------- src/gui/PatchPropertiesWindow.hpp | 64 ----- src/gui/PatchView.cpp | 1 - src/gui/PatchWindow.cpp | 1 - src/gui/Port.cpp | 1 - src/gui/PropertiesWindow.cpp | 302 ++++++++++++++++++++++++ src/gui/PropertiesWindow.hpp | 96 ++++++++ src/gui/WindowFactory.cpp | 47 +--- src/gui/WindowFactory.hpp | 8 +- src/gui/ingen_gui.glade | 482 +++++++++----------------------------- src/gui/wscript | 3 +- src/shared/ResourceImpl.cpp | 13 + src/shared/ResourceImpl.hpp | 1 + 18 files changed, 553 insertions(+), 746 deletions(-) delete mode 100644 src/gui/NodePropertiesWindow.cpp delete mode 100644 src/gui/NodePropertiesWindow.hpp delete mode 100644 src/gui/PatchPropertiesWindow.cpp delete mode 100644 src/gui/PatchPropertiesWindow.hpp create mode 100644 src/gui/PropertiesWindow.cpp create mode 100644 src/gui/PropertiesWindow.hpp diff --git a/src/common/interface/Resource.hpp b/src/common/interface/Resource.hpp index 5c9a90eb..4f3e6128 100644 --- a/src/common/interface/Resource.hpp +++ b/src/common/interface/Resource.hpp @@ -44,6 +44,8 @@ public: const Raul::Atom& value) = 0; virtual const Raul::Atom& get_property(const Raul::URI& uri) const = 0; + + virtual bool has_property(const Raul::URI& uri, const Raul::Atom& value) = 0; }; diff --git a/src/gui/Controls.cpp b/src/gui/Controls.cpp index 6b825b48..e810585d 100644 --- a/src/gui/Controls.cpp +++ b/src/gui/Controls.cpp @@ -22,11 +22,11 @@ #include "client/PluginModel.hpp" #include "client/NodeModel.hpp" #include "client/PortModel.hpp" -#include "Controls.hpp" +#include "App.hpp" #include "ControlPanel.hpp" -#include "PortPropertiesWindow.hpp" +#include "Controls.hpp" #include "GladeFactory.hpp" -#include "App.hpp" +#include "PortPropertiesWindow.hpp" using namespace std; using namespace Raul; @@ -49,7 +49,7 @@ Control::Control(BaseObjectType* cobject, const Glib::RefPtr& menu_xml->get_widget("port_control_menu_properties", _menu_properties); _menu_properties->signal_activate().connect( - sigc::mem_fun(this, &SliderControl::menu_properties)); + sigc::mem_fun(this, &SliderControl::menu_properties)); } diff --git a/src/gui/LoadPluginWindow.hpp b/src/gui/LoadPluginWindow.hpp index b5a3bbd5..9f24d278 100644 --- a/src/gui/LoadPluginWindow.hpp +++ b/src/gui/LoadPluginWindow.hpp @@ -65,21 +65,21 @@ private: /** Columns for the plugin list */ class ModelColumns : public Gtk::TreeModel::ColumnRecord { public: - ModelColumns() { - add(_col_icon); - add(_col_name); - add(_col_type); - add(_col_uri); - add(_col_plugin); - } - - Gtk::TreeModelColumn > _col_icon; - Gtk::TreeModelColumn _col_name; - Gtk::TreeModelColumn _col_type; - Gtk::TreeModelColumn _col_uri; - - // Not displayed: - Gtk::TreeModelColumn > _col_plugin; + ModelColumns() { + add(_col_icon); + add(_col_name); + add(_col_type); + add(_col_uri); + add(_col_plugin); + } + + Gtk::TreeModelColumn > _col_icon; + Gtk::TreeModelColumn _col_name; + Gtk::TreeModelColumn _col_type; + Gtk::TreeModelColumn _col_uri; + + // Not displayed: + Gtk::TreeModelColumn > _col_plugin; }; /** Column for the filter criteria combo box. */ diff --git a/src/gui/NodePropertiesWindow.cpp b/src/gui/NodePropertiesWindow.cpp deleted file mode 100644 index f3058e5d..00000000 --- a/src/gui/NodePropertiesWindow.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007-2009 Dave Robillard - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include "client/NodeModel.hpp" -#include "client/PluginModel.hpp" -#include "NodePropertiesWindow.hpp" - -using namespace std; -using namespace Raul; - -namespace Ingen { -namespace GUI { - - -NodePropertiesWindow::NodePropertiesWindow(BaseObjectType* cobject, const Glib::RefPtr& glade_xml) - : Window(cobject) -{ - glade_xml->get_widget("node_properties_path_label", _node_path_label); - glade_xml->get_widget("node_properties_polyphonic_checkbutton", _node_polyphonic_toggle); - glade_xml->get_widget("node_properties_plugin_type_label", _plugin_type_label); - glade_xml->get_widget("node_properties_plugin_uri_label", _plugin_uri_label); - glade_xml->get_widget("node_properties_plugin_name_label", _plugin_name_label); - glade_xml->get_widget("node_properties_close_button", _close_button); - - _close_button->signal_clicked().connect( - sigc::mem_fun(this, &Window::hide)); -} - - -/** Set the node this window is associated with. - * This function MUST be called before using this object in any way. - */ -void -NodePropertiesWindow::set_node(SharedPtr node_model) -{ - assert(node_model); - - _node_model = node_model; - - set_title(node_model->path().str() + " Properties - Ingen"); - - _node_path_label->set_text(node_model->path().str()); - _node_polyphonic_toggle->set_active(node_model->polyphonic()); - - const PluginModel* pm = dynamic_cast(node_model->plugin()); - if (pm) { - _plugin_type_label->set_text(pm->type_uri()); - _plugin_uri_label->set_text(pm->uri().str()); - const Atom& name = pm->get_property("doap:name"); - if (name.is_valid()) - _plugin_name_label->set_text(pm->get_property("doap:name").get_string()); - else - _plugin_name_label->set_text("(Unknown)"); - } -} - - -} // namespace GUI -} // namespace Ingen - diff --git a/src/gui/NodePropertiesWindow.hpp b/src/gui/NodePropertiesWindow.hpp deleted file mode 100644 index adbdb2c4..00000000 --- a/src/gui/NodePropertiesWindow.hpp +++ /dev/null @@ -1,61 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007-2009 Dave Robillard - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef NODEPROPERTIESWINDOW_H -#define NODEPROPERTIESWINDOW_H - -#include -#include -#include "raul/SharedPtr.hpp" -#include "client/NodeModel.hpp" -#include "Window.hpp" - -using namespace Ingen::Client; - -namespace Ingen { -namespace GUI { - - -/** Node properties window. - * - * Loaded by libglade as a derived object. - * - * \ingroup GUI - */ -class NodePropertiesWindow : public Window -{ -public: - NodePropertiesWindow(BaseObjectType* cobject, const Glib::RefPtr& refGlade); - - void present(SharedPtr node_model) { set_node(node_model); Gtk::Window::present(); } - void set_node(SharedPtr node_model); - -private: - - SharedPtr _node_model; - Gtk::Label* _node_path_label; - Gtk::CheckButton* _node_polyphonic_toggle; - Gtk::Label* _plugin_type_label; - Gtk::Label* _plugin_uri_label; - Gtk::Label* _plugin_name_label; - Gtk::Button* _close_button; -}; - -} // namespace GUI -} // namespace Ingen - -#endif // NODEPROPERTIESWINDOW_H diff --git a/src/gui/PatchPropertiesWindow.cpp b/src/gui/PatchPropertiesWindow.cpp deleted file mode 100644 index cf5a9917..00000000 --- a/src/gui/PatchPropertiesWindow.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007-2009 Dave Robillard - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include "client/PatchModel.hpp" -#include "PatchPropertiesWindow.hpp" -#include "App.hpp" - -using namespace std; -using namespace Raul; - -namespace Ingen { -namespace GUI { - - -PatchPropertiesWindow::PatchPropertiesWindow(BaseObjectType* cobject, const Glib::RefPtr& glade_xml) - : Window(cobject) -{ - glade_xml->get_widget("properties_name_entry", _name_entry); - glade_xml->get_widget("properties_author_entry", _author_entry); - glade_xml->get_widget("properties_description_textview", _textview); - glade_xml->get_widget("properties_cancel_button", _cancel_button); - glade_xml->get_widget("properties_ok_button", _ok_button); - - _cancel_button->signal_clicked().connect(sigc::mem_fun(this, &PatchPropertiesWindow::cancel_clicked)); - _ok_button->signal_clicked().connect(sigc::mem_fun(this, &PatchPropertiesWindow::ok_clicked)); -} - - -/** Set the patch model this description is for. - * - * This function is a "post-constructor" - it MUST be called before using - * the window in any way. - */ -void -PatchPropertiesWindow::set_patch(SharedPtr patch_model) -{ - property_title() = patch_model->path().str() + " Properties"; - _patch_model = patch_model; - - const Atom& name_atom = _patch_model->get_property("doap:name"); - _name_entry->set_text( - (name_atom.type() == Atom::STRING) ? name_atom.get_string() : "" ); - - const Atom& author_atom = _patch_model->get_property("dc:creator"); - _author_entry->set_text( - (author_atom.type() == Atom::STRING) ? author_atom.get_string() : "" ); - - const Atom& desc_atom = _patch_model->get_property("dc:description"); - _textview->get_buffer()->set_text( - (desc_atom.type() == Atom::STRING) ? desc_atom.get_string() : "" ); -} - - -void -PatchPropertiesWindow::cancel_clicked() -{ - const Atom& name_atom = _patch_model->get_property("doap:name"); - _name_entry->set_text( - (name_atom.type() == Atom::STRING) ? name_atom.get_string() : "" ); - - const Atom& author_atom = _patch_model->get_property("dc:creator"); - _author_entry->set_text( - (author_atom.type() == Atom::STRING) ? author_atom.get_string() : "" ); - - const Atom& desc_atom = _patch_model->get_property("dc:description"); - _textview->get_buffer()->set_text( - (desc_atom.type() == Atom::STRING) ? desc_atom.get_string() : "" ); - - hide(); -} - - -void -PatchPropertiesWindow::ok_clicked() -{ - App::instance().engine()->set_property(_patch_model->path(), "doap:name", - Atom(Atom::STRING, _name_entry->get_text())); - App::instance().engine()->set_property(_patch_model->path(), "dc:creator", - Atom(Atom::STRING, _author_entry->get_text())); - App::instance().engine()->set_property(_patch_model->path(), "dc:description", - Atom(Atom::STRING, _textview->get_buffer()->get_text())); - hide(); -} - - - -} // namespace GUI -} // namespace Ingen diff --git a/src/gui/PatchPropertiesWindow.hpp b/src/gui/PatchPropertiesWindow.hpp deleted file mode 100644 index 3683fdd0..00000000 --- a/src/gui/PatchPropertiesWindow.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007-2009 Dave Robillard - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef PATCHPROPERTIESWINDOW_H -#define PATCHPROPERTIESWINDOW_H - -#include -#include -#include "raul/SharedPtr.hpp" -#include "Window.hpp" - -namespace Ingen { namespace Client { class PatchModel; } } -using Ingen::Client::PatchModel; - -namespace Ingen { -namespace GUI { - - -/** Patch Properties Window. - * - * Loaded by libglade as a derived object. - * - * \ingroup GUI - */ -class PatchPropertiesWindow : public Window -{ -public: - PatchPropertiesWindow(BaseObjectType* cobject, const Glib::RefPtr& refGlade); - - void present(SharedPtr patch_model) { set_patch(patch_model); Gtk::Window::present(); } - void set_patch(SharedPtr patch_model); - - void cancel_clicked(); - void ok_clicked(); - -private: - SharedPtr _patch_model; - - Gtk::Entry* _name_entry; - Gtk::Entry* _author_entry; - Gtk::TextView* _textview; - Gtk::Button* _cancel_button; - Gtk::Button* _ok_button; -}; - - -} // namespace GUI -} // namespace Ingen - -#endif // PATCHPROPERTIESWINDOW_H diff --git a/src/gui/PatchView.cpp b/src/gui/PatchView.cpp index 6e3282bc..6fce3797 100644 --- a/src/gui/PatchView.cpp +++ b/src/gui/PatchView.cpp @@ -27,7 +27,6 @@ #include "NewSubpatchWindow.hpp" #include "LoadSubpatchWindow.hpp" #include "NodeControlWindow.hpp" -#include "PatchPropertiesWindow.hpp" #include "PatchTreeWindow.hpp" #include "GladeFactory.hpp" diff --git a/src/gui/PatchWindow.cpp b/src/gui/PatchWindow.cpp index 926929f9..13c1f2ff 100644 --- a/src/gui/PatchWindow.cpp +++ b/src/gui/PatchWindow.cpp @@ -31,7 +31,6 @@ #include "LoadPatchWindow.hpp" #include "LoadSubpatchWindow.hpp" #include "NodeControlWindow.hpp" -#include "PatchPropertiesWindow.hpp" #include "Configuration.hpp" #include "MessagesWindow.hpp" #include "PatchTreeWindow.hpp" diff --git a/src/gui/Port.cpp b/src/gui/Port.cpp index 5e1050f8..bbde8100 100644 --- a/src/gui/Port.cpp +++ b/src/gui/Port.cpp @@ -103,7 +103,6 @@ Port::update_metadata() } - void Port::create_menu() { diff --git a/src/gui/PropertiesWindow.cpp b/src/gui/PropertiesWindow.cpp new file mode 100644 index 00000000..48440817 --- /dev/null +++ b/src/gui/PropertiesWindow.cpp @@ -0,0 +1,302 @@ +/* This file is part of Ingen. + * Copyright (C) 2007-2009 Dave Robillard + * + * Ingen is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include "raul/log.hpp" +#include "client/NodeModel.hpp" +#include "client/PluginModel.hpp" +#include "App.hpp" +#include "PropertiesWindow.hpp" + +#define LOG(s) s << "[PropertiesWindow] " + +using namespace std; +using namespace Raul; + +namespace Ingen { +namespace GUI { + + +PropertiesWindow::PropertiesWindow(BaseObjectType* cobject, const Glib::RefPtr& glade_xml) + : Window(cobject) +{ + glade_xml->get_widget("properties_vbox", _vbox); + glade_xml->get_widget("properties_scrolledwindow", _scrolledwindow); + glade_xml->get_widget("properties_table", _table); + glade_xml->get_widget("properties_cancel_button", _cancel_button); + glade_xml->get_widget("properties_apply_button", _apply_button); + glade_xml->get_widget("properties_ok_button", _ok_button); + + _type_choices = Gtk::ListStore::create(_type_cols); + for (int i = Raul::Atom::INT; i <= Raul::Atom::BLOB; ++i) { + Gtk::TreeModel::Row row = *_type_choices->append(); + row[_type_cols.type] = static_cast(i); + ostringstream ss; + ss << static_cast(i); + row[_type_cols.choice] = ss.str(); + } + + _cancel_button->signal_clicked().connect( + sigc::mem_fun(this, &PropertiesWindow::cancel_clicked)); + + _apply_button->signal_clicked().connect( + sigc::mem_fun(this, &PropertiesWindow::apply_clicked)); + + _ok_button->signal_clicked().connect( + sigc::mem_fun(this, &PropertiesWindow::ok_clicked)); +} + + +/** Set the node this window is associated with. + * This function MUST be called before using this object in any way. + */ +void +PropertiesWindow::set_object(SharedPtr model) +{ + _table->children().clear(); + _table->resize(1, 3); + _table->property_n_rows() = 1; + + _property_connection.disconnect(); + _model = model; + + set_title(model->path().chop_scheme() + " Properties - Ingen"); + + ostringstream ss; + unsigned n_rows = 0; + for (ObjectModel::Properties::const_iterator i = model->properties().begin(); + i != model->properties().end(); ++i) { + _table->property_n_rows() = ++n_rows; + + const Raul::Atom& value = i->second; + + // Column 0: Property + Gtk::Label* lab = manage(new Gtk::Label(i->first.str(), 0.0, 0.5)); + _table->attach(*lab, 0, 1, n_rows, n_rows + 1, Gtk::FILL|Gtk::SHRINK, Gtk::SHRINK); + + // Column 1: Type + Gtk::ComboBox* combo = manage(new Gtk::ComboBox()); + combo->set_model(_type_choices); + combo->pack_start(_type_cols.choice); + const char path[] = { static_cast(value.type()) - 1 + '0', '\0' }; + combo->set_active(_type_choices->get_iter(path)); + Gtk::Alignment* align = manage(new Gtk::Alignment(0.0, 0.5, 0.0, 1.0)); + align->add(*combo); + _table->attach(*align, 1, 2, n_rows, n_rows + 1, Gtk::FILL|Gtk::SHRINK, Gtk::SHRINK); + + Record record; + record.value = value; + record.type_widget = combo; + + // Column 2: Value + align = manage(new Gtk::Alignment(0.0, 0.5, 1.0, 0.0)); + Gtk::Widget* value_widget = create_value_widget(i->first, value); + align->add(*value_widget); + _table->attach(*align, 2, 3, n_rows, n_rows + 1, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK); + record.value_widget = align; + record.row = n_rows; + _records.insert(make_pair(i->first, record)); + } + + _table->show_all(); + + _property_connection = model->signal_property.connect( + sigc::mem_fun(this, &PropertiesWindow::property_changed)); +} + +Gtk::Widget* +PropertiesWindow::create_value_widget(const Raul::URI& uri, const Raul::Atom& value) +{ + if (value.type() == Atom::INT) { + Gtk::SpinButton* widget = manage(new Gtk::SpinButton(0.0, 0)); + widget->property_numeric() = true; + widget->set_value(value.get_int32()); + widget->set_snap_to_ticks(true); + widget->set_range(INT_MIN, INT_MAX); + widget->set_increments(1, 10); + widget->signal_value_changed().connect(sigc::bind( + sigc::mem_fun(this, &PropertiesWindow::value_edited), + uri)); + return widget; + } else if (value.type() == Atom::FLOAT) { + Gtk::SpinButton* widget = manage(new Gtk::SpinButton(0.0, 4)); + widget->property_numeric() = true; + widget->set_snap_to_ticks(false); + widget->set_range(DBL_MIN, DBL_MAX); + widget->set_value(value.get_float()); + widget->set_increments(0.1, 1.0); + widget->signal_value_changed().connect(sigc::bind( + sigc::mem_fun(this, &PropertiesWindow::value_edited), + uri)); + return widget; + } else if (value.type() == Atom::BOOL) { + Gtk::CheckButton* widget = manage(new Gtk::CheckButton()); + widget->set_active(value.get_bool()); + widget->signal_toggled().connect(sigc::bind( + sigc::mem_fun(this, &PropertiesWindow::value_edited), + uri)); + return widget; + } else if (value.type() == Atom::URI) { + Gtk::Entry* widget = manage(new Gtk::Entry()); + widget->set_text(value.get_uri()); + widget->signal_changed().connect(sigc::bind( + sigc::mem_fun(this, &PropertiesWindow::value_edited), + uri)); + return widget; + } else if (value.type() == Atom::STRING) { + Gtk::Entry* widget = manage(new Gtk::Entry()); + widget->set_text(value.get_string()); + widget->signal_changed().connect(sigc::bind( + sigc::mem_fun(this, &PropertiesWindow::value_edited), + uri)); + return widget; + } + + return NULL; +} + + +void +PropertiesWindow::on_show() +{ + static const int WIN_PAD = 32; + static const int VBOX_PAD = 12; + int width = 0; + int height = 0; + Gtk::Requisition req; + + typedef Gtk::Box_Helpers::BoxList Children; + for (Children::const_iterator i = _vbox->children().begin(); i != _vbox->children().end(); ++i) { + req = (*i).get_widget()->size_request(); + if ((*i).get_widget() != _scrolledwindow) { + width = std::max(width, req.width); + height += req.height + VBOX_PAD; + } + } + + req = _table->size_request(); + width = std::max(width, req.width); + height += req.height; + + set_default_size(width + WIN_PAD, height + WIN_PAD); + resize(width + WIN_PAD, height + WIN_PAD); + Gtk::Window::on_show(); +} + + +void +PropertiesWindow::property_changed(const Raul::URI& predicate, const Raul::Atom& value) +{ + Records::iterator r = _records.find(predicate); + if (r == _records.end()) { + LOG(error) << "Unknown property `" << predicate << "' changed" << endl; + return; + } + + Record& record = r->second; + Gtk::Widget* value_widget = create_value_widget(predicate, value); + + record.value_widget->remove(); + record.value_widget->add(*value_widget); + record.value = value; + value_widget->show(); +} + + +void +PropertiesWindow::value_edited(const Raul::URI& predicate) +{ + Records::iterator r = _records.find(predicate); + if (r == _records.end()) { + LOG(error) << "Unknown property `" << predicate << "' edited" << endl; + return; + } + + Record& record = r->second; + Raul::Atom::Type type = (*record.type_widget->get_active())[_type_cols.type]; + if (type == Atom::INT) { + Gtk::SpinButton* widget = dynamic_cast(record.value_widget->get_child()); + if (!widget) goto bad_type; + record.value = Atom(widget->get_value_as_int()); + } else if (type == Atom::FLOAT) { + Gtk::SpinButton* widget = dynamic_cast(record.value_widget->get_child()); + if (!widget) goto bad_type; + record.value = Atom(static_cast(widget->get_value())); + } else if (type == Atom::BOOL) { + Gtk::CheckButton* widget = dynamic_cast(record.value_widget->get_child()); + if (!widget) goto bad_type; + record.value = Atom(widget->get_active()); + } else if (type == Atom::URI) { + Gtk::Entry* widget = dynamic_cast(record.value_widget->get_child()); + if (!widget) goto bad_type; + record.value = Atom(Atom::URI, widget->get_text()); + } else if (type == Atom::STRING) { + Gtk::Entry* widget = dynamic_cast(record.value_widget->get_child()); + if (!widget) goto bad_type; + record.value = Atom(Atom::URI, widget->get_text()); + } + + cout << "VALUE EDITED " << predicate << " = " << record.value << endl; + return; + +bad_type: + LOG(error) << "Property `" << predicate << "' value widget has wrong type" << endl; + return; +} + + +void +PropertiesWindow::cancel_clicked() +{ + set_object(_model); // reset + Gtk::Window::hide(); +} + + +void +PropertiesWindow::apply_clicked() +{ + LOG(debug) << "apply {" << endl; + Shared::Resource::Properties properties; + for (Records::const_iterator r = _records.begin(); r != _records.end(); ++r) { + const Raul::URI& uri = r->first; + const Record& record = r->second; + if (!_model->has_property(uri, record.value)) { + LOG(debug) << "\t" << uri + << " = " << record.value + << " :: " << record.value.type() << endl; + properties.insert(make_pair(uri, record.value)); + } + } + + App::instance().engine()->put(_model->path(), properties); + + LOG(debug) << "}" << endl; +} + + +void +PropertiesWindow::ok_clicked() +{ + apply_clicked(); + Gtk::Window::hide(); +} + + +} // namespace GUI +} // namespace Ingen diff --git a/src/gui/PropertiesWindow.hpp b/src/gui/PropertiesWindow.hpp new file mode 100644 index 00000000..d2f619f9 --- /dev/null +++ b/src/gui/PropertiesWindow.hpp @@ -0,0 +1,96 @@ +/* This file is part of Ingen. + * Copyright (C) 2007-2009 Dave Robillard + * + * Ingen is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PROPERTIES_WINDOW_HPP +#define PROPERTIES_WINDOW_HPP + +#include +#include +#include "raul/SharedPtr.hpp" +#include "client/NodeModel.hpp" +#include "Window.hpp" + +using namespace Ingen::Client; + +namespace Ingen { +namespace GUI { + + +/** Node properties window. + * + * Loaded by libglade as a derived object. + * + * \ingroup GUI + */ +class PropertiesWindow : public Window +{ +public: + PropertiesWindow(BaseObjectType* cobject, const Glib::RefPtr& refGlade); + + void present(SharedPtr model) { set_object(model); Gtk::Window::present(); } + void set_object(SharedPtr model); + +private: + /** Record of a property (row in the table) */ + struct Record { + Raul::Atom value; + Gtk::ComboBox* type_widget; + Gtk::Alignment* value_widget; + int row; + }; + + /** Columns for type combo in treeview */ + class TypeColumns : public Gtk::TreeModel::ColumnRecord { + public: + TypeColumns() { add(type); add(choice); } + + Gtk::TreeModelColumn type; + Gtk::TreeModelColumn choice; + }; + + Gtk::Widget* create_value_widget(const Raul::URI& uri, const Raul::Atom& value); + + void on_show(); + + void property_changed(const Raul::URI& predicate, const Raul::Atom& value); + + void value_edited(const Raul::URI& predicate); + + void cancel_clicked(); + void apply_clicked(); + void ok_clicked(); + + typedef std::map Records; + Records _records; + + TypeColumns _type_cols; + Glib::RefPtr _type_choices; + + SharedPtr _model; + sigc::connection _property_connection; + Gtk::VBox* _vbox; + Gtk::ScrolledWindow* _scrolledwindow; + Gtk::Table* _table; + Gtk::Button* _cancel_button; + Gtk::Button* _apply_button; + Gtk::Button* _ok_button; +}; + +} // namespace GUI +} // namespace Ingen + +#endif // PROPERTIES_WINDOW_HPP diff --git a/src/gui/WindowFactory.cpp b/src/gui/WindowFactory.cpp index 3131070f..1842a04a 100644 --- a/src/gui/WindowFactory.cpp +++ b/src/gui/WindowFactory.cpp @@ -26,11 +26,9 @@ #include "LoadSubpatchWindow.hpp" #include "NewSubpatchWindow.hpp" #include "NodeControlWindow.hpp" -#include "NodePropertiesWindow.hpp" -#include "PatchPropertiesWindow.hpp" +#include "PropertiesWindow.hpp" #include "PatchView.hpp" #include "PatchWindow.hpp" -#include "PortPropertiesWindow.hpp" #include "RenameWindow.hpp" #include "WindowFactory.hpp" #ifdef HAVE_CURL @@ -50,9 +48,7 @@ WindowFactory::WindowFactory() , _upload_patch_win(NULL) , _new_subpatch_win(NULL) , _load_subpatch_win(NULL) - , _patch_properties_win(NULL) - , _node_properties_win(NULL) - , _port_properties_win(NULL) + , _properties_win(NULL) { Glib::RefPtr xml = GladeFactory::new_glade_reference(); @@ -61,9 +57,7 @@ WindowFactory::WindowFactory() xml->get_widget_derived("load_remote_patch_win", _load_remote_patch_win); xml->get_widget_derived("new_subpatch_win", _new_subpatch_win); xml->get_widget_derived("load_subpatch_win", _load_subpatch_win); - xml->get_widget_derived("patch_properties_win", _patch_properties_win); - xml->get_widget_derived("node_properties_win", _node_properties_win); - xml->get_widget_derived("port_properties_win", _port_properties_win); + xml->get_widget_derived("properties_win", _properties_win); xml->get_widget_derived("rename_win", _rename_win); #ifdef HAVE_CURL @@ -347,35 +341,16 @@ WindowFactory::present_rename(SharedPtr object) void WindowFactory::present_properties(SharedPtr object) { - SharedPtr patch = PtrCast(object); - if (patch) { - PatchWindowMap::iterator w = _patch_windows.find(patch->path()); - if (w != _patch_windows.end()) - _patch_properties_win->set_transient_for(*w->second); - - _patch_properties_win->present(patch); - return; - } - - SharedPtr node = PtrCast(object); - if (node) { - PatchWindowMap::iterator w = _patch_windows.find(node->path().parent()); - if (w != _patch_windows.end()) - _node_properties_win->set_transient_for(*w->second); - - _node_properties_win->present(node); - return; - } + PatchWindowMap::iterator w = _patch_windows.find(object->path()); + if (w == _patch_windows.end()) + w = _patch_windows.find(object->path().parent()); + if (w == _patch_windows.end()) + w = _patch_windows.find(object->path().parent().parent()); - SharedPtr port = PtrCast(object); - if (port) { - PatchWindowMap::iterator w = _patch_windows.find(port->path().parent().parent()); - if (w != _patch_windows.end()) - _patch_properties_win->set_transient_for(*w->second); + if (w != _patch_windows.end()) + _properties_win->set_transient_for(*w->second); - _port_properties_win->present(port); - return; - } + _properties_win->present(object); } diff --git a/src/gui/WindowFactory.hpp b/src/gui/WindowFactory.hpp index dce08c96..adfd1c0d 100644 --- a/src/gui/WindowFactory.hpp +++ b/src/gui/WindowFactory.hpp @@ -42,11 +42,9 @@ class LoadRemotePatchWindow; class LoadSubpatchWindow; class NewSubpatchWindow; class NodeControlWindow; -class NodePropertiesWindow; -class PatchPropertiesWindow; +class PropertiesWindow; class PatchView; class PatchWindow; -class PortPropertiesWindow; class RenameWindow; class UploadPatchWindow; @@ -107,9 +105,7 @@ private: UploadPatchWindow* _upload_patch_win; NewSubpatchWindow* _new_subpatch_win; LoadSubpatchWindow* _load_subpatch_win; - PatchPropertiesWindow* _patch_properties_win; - NodePropertiesWindow* _node_properties_win; - PortPropertiesWindow* _port_properties_win; + PropertiesWindow* _properties_win; RenameWindow* _rename_win; }; diff --git a/src/gui/ingen_gui.glade b/src/gui/ingen_gui.glade index a255e541..f294678b 100644 --- a/src/gui/ingen_gui.glade +++ b/src/gui/ingen_gui.glade @@ -1231,7 +1231,8 @@ True 6 - 2 + 12 + 12 True @@ -1750,24 +1751,6 @@ 8 - - - - - - - - - - - - - - - - - - @@ -1976,137 +1959,6 @@ - - 400 - 200 - 8 - Patch Description - center-on-parent - - - True - 6 - - - True - 2 - 2 - 8 - 8 - - - True - Name: - - - GTK_FILL - - - - - True - True - - - 1 - 2 - - - - - True - True - - - 1 - 2 - 1 - 2 - - - - - True - Author: - - - 1 - 2 - GTK_FILL - - - - - False - 0 - - - - - True - True - automatic - automatic - in - - - True - True - A short description of the patch to be included in the patch file - word - - - - - 1 - - - - - True - 5 - end - - - gtk-cancel - True - True - True - False - True - - - False - False - 0 - - - - - gtk-ok - True - True - True - False - Apply these changes to be saved the next time the patch is saved - True - - - False - False - 1 - - - - - False - False - 2 - - - - - 250 Rename @@ -2264,230 +2116,6 @@ - - 8 - Node Properties - Ingen - mouse - - - True - vertical - 4 - - - True - 0 - <b>Node</b> - True - - - False - False - 0 - - - - - True - 12 - vertical - 6 - - - True - 4 - - - True - Path: - - - False - False - 0 - - - - - True - - - True - - - False - False - 1 - - - - - False - False - 0 - - - - - Polyphonic - True - False - True - False - True - True - - - False - False - 1 - - - - - 6 - 1 - - - - - 240 - True - 0 - <b>Plugin</b> - True - - - False - False - 2 - - - - - True - 12 - 3 - 2 - 10 - 6 - - - True - 0 - - - - - 1 - 2 - GTK_FILL - - - - - - True - 0 - Type: - - - GTK_FILL - - - - - - True - 0 - URI: - - - 1 - 2 - GTK_FILL - - - - - - True - 0 - - - True - - - 1 - 2 - 1 - 2 - GTK_FILL - - - - - - True - 0 - Name: - - - 2 - 3 - GTK_FILL - - - - - - True - 0 - - - - - 1 - 2 - 2 - 3 - GTK_FILL - - - - - - 3 - - - - - True - end - - - gtk-close - True - True - True - True - True - True - True - True - - - False - False - 0 - - - - - False - False - 4 - - - - - True normal @@ -3296,8 +2924,7 @@ Thank you for contributing. gtk-properties True - True - False + True @@ -3534,4 +3161,107 @@ Thank you for contributing. + + 12 + center-on-parent + + + True + vertical + 12 + + + True + True + automatic + automatic + + + True + queue + none + + + True + 3 + 12 + 6 + + + + + + + + + + + + + + + + 0 + + + + + True + 6 + end + + + gtk-cancel + True + True + True + True + True + + + False + False + 0 + + + + + gtk-apply + True + True + True + True + + + False + False + 1 + + + + + gtk-ok + True + True + True + True + True + True + + + False + False + 2 + + + + + False + end + 1 + + + + + diff --git a/src/gui/wscript b/src/gui/wscript index 7d7e61fc..5550f836 100644 --- a/src/gui/wscript +++ b/src/gui/wscript @@ -24,17 +24,16 @@ def build(bld): NodeControlWindow.cpp NodeMenu.cpp NodeModule.cpp - NodePropertiesWindow.cpp ObjectMenu.cpp PatchCanvas.cpp PatchPortModule.cpp - PatchPropertiesWindow.cpp PatchTreeWindow.cpp PatchView.cpp PatchWindow.cpp Port.cpp PortMenu.cpp PortPropertiesWindow.cpp + PropertiesWindow.cpp RenameWindow.cpp SubpatchModule.cpp ThreadedLoader.cpp diff --git a/src/shared/ResourceImpl.cpp b/src/shared/ResourceImpl.cpp index 93d6ea03..949a8b36 100644 --- a/src/shared/ResourceImpl.cpp +++ b/src/shared/ResourceImpl.cpp @@ -62,6 +62,19 @@ ResourceImpl::set_property(const Raul::URI& uri, const Raul::Atom& value) } +bool +ResourceImpl::has_property(const Raul::URI& uri, const Raul::Atom& value) +{ + Properties::const_iterator i = _properties.find(uri); + for (; i->first == uri; ++i) { + if (i->second == value) { + return true; + } + } + return false; +} + + Raul::Atom& ResourceImpl::set_property(const Raul::URI& uri, const Raul::Atom& value) const { diff --git a/src/shared/ResourceImpl.hpp b/src/shared/ResourceImpl.hpp index b4afc50a..7ff88f6a 100644 --- a/src/shared/ResourceImpl.hpp +++ b/src/shared/ResourceImpl.hpp @@ -40,6 +40,7 @@ public: const Raul::Atom& get_property(const Raul::URI& uri) const; Raul::Atom& set_property(const Raul::URI& uri, const Raul::Atom& value); + bool has_property(const Raul::URI& uri, const Raul::Atom& value); void add_property(const Raul::URI& uri, const Raul::Atom& value); void set_properties(const Properties& p); void add_properties(const Properties& p); -- cgit v1.2.1