X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fvisibility_group.cc;h=d0ef1dd63510a0c36b9253a4421ab724410b2d06;hb=720292696a94c96d764e74b5e84fce09a1b3621c;hp=c817ff3fcb1dba86429d0c98ea075bc8d24fdcc9;hpb=05e5d7964ee182368ebc36acceacffff238a2dab;p=ardour.git diff --git a/gtk2_ardour/visibility_group.cc b/gtk2_ardour/visibility_group.cc index c817ff3fcb..d0ef1dd635 100644 --- a/gtk2_ardour/visibility_group.cc +++ b/gtk2_ardour/visibility_group.cc @@ -21,10 +21,13 @@ #include #include #include + +#include "pbd/strsplit.h" #include "pbd/xml++.h" + #include "visibility_group.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace std; @@ -40,17 +43,21 @@ VisibilityGroup::VisibilityGroup (std::string const & name) * @param id Some single-word ID to be used for the state of this member in XML. * @param name User-visible name for the widget. * @param visible true to default to visible, otherwise false. + * @param override A functor to decide whether the visibility specified by the member should be + * overridden by some external factor; if the returned optional value is given, it will be used + * to override whatever visibility setting the member has. */ void -VisibilityGroup::add (Gtk::Widget* widget, string const & id, string const & name, bool visible) +VisibilityGroup::add (Gtk::Widget* widget, string const & id, string const & name, bool visible, boost::function ()> override) { Member m; m.widget = widget; m.id = id; m.name = name; m.visible = visible; - + m.override = override; + _members.push_back (m); } @@ -84,13 +91,27 @@ VisibilityGroup::menu () return m; } +/** @return true if the member should be visible, even taking into account any override functor */ +bool +VisibilityGroup::should_actually_be_visible (Member const & m) const +{ + if (m.override) { + boost::optional o = m.override (); + if (o) { + return o.get (); + } + } + + return m.visible; +} + /** Update visible consequences of any changes to our _members vector */ void VisibilityGroup::update () { for (vector::iterator i = _members.begin(); i != _members.end(); ++i) { if (i->widget) { - if (i->visible) { + if (should_actually_be_visible (*i)) { i->widget->show (); } else { i->widget->hide (); @@ -143,12 +164,58 @@ VisibilityGroup::set_state (string v) } v = v.substr (comma + 1); - + } while (1); update (); } +string +VisibilityGroup::remove_element (std::string const& from, std::string const& element) +{ + std::vector s; + std::string ret; + + split (from, s, ','); + for (std::vector::const_iterator i = s.begin(); i != s.end(); ++i) { + if ((*i) == element) { + continue; + } + if (!ret.empty()) { + ret += ','; + } + ret += *i; + } + + return ret; +} + +string +VisibilityGroup::add_element (std::string const& from, std::string const& element) +{ + std::vector s; + std::string ret; + + split (from, s, ','); + + for (std::vector::const_iterator i = s.begin(); i != s.end(); ++i) { + if ((*i) == element) { + /* already present, just return the original */ + return from; + } + } + + ret = from; + + if (!ret.empty()) { + ret += ','; + } + + ret += element; + + return ret; +} + string VisibilityGroup::get_state_name () const { @@ -177,11 +244,11 @@ VisibilityGroup::update_list_view () if (!_model) { return; } - + _ignore_list_view_change = true; _model->clear (); - + for (vector::iterator i = _members.begin(); i != _members.end(); ++i) { Gtk::TreeModel::iterator j = _model->append (); Gtk::TreeModel::Row row = *j; @@ -202,8 +269,8 @@ VisibilityGroup::list_view () Gtk::TreeView* v = Gtk::manage (new Gtk::TreeView (_model)); v->set_headers_visible (false); - v->append_column (_(""), _model_columns._visible); - v->append_column (_(""), _model_columns._name); + v->append_column ("", _model_columns._visible); + v->append_column ("", _model_columns._name); Gtk::CellRendererToggle* visible_cell = dynamic_cast (v->get_column_cell_renderer (0)); visible_cell->property_activatable() = true; @@ -217,7 +284,7 @@ VisibilityGroup::list_view_visible_changed (string const & path) if (_ignore_list_view_change) { return; } - + Gtk::TreeModel::iterator i = _model->get_iter (path); if (!i) { return;