2 Copyright (C) 2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <gtkmm/menu.h>
21 #include <gtkmm/stock.h>
22 #include "ardour/session.h"
23 #include "ardour/route_group.h"
24 #include "route_group_menu.h"
25 #include "route_group_dialog.h"
29 using namespace ARDOUR;
31 RouteGroupMenu::RouteGroupMenu (Session* s, RouteGroup::Property p)
32 : SessionHandlePtr (s)
33 , _default_properties (p)
34 , _inhibit_group_selected (false)
35 , _selected_route_group (0)
41 RouteGroupMenu::rebuild (RouteGroup* curr)
43 using namespace Menu_Helpers;
45 _selected_route_group = curr;
47 _inhibit_group_selected = true;
51 items().push_back (MenuElem (_("New group..."), sigc::mem_fun (*this, &RouteGroupMenu::new_group)));
52 items().push_back (SeparatorElem ());
54 RadioMenuItem::Group group;
55 items().push_back (RadioMenuElem (group, _("No group"), sigc::bind (sigc::mem_fun (*this, &RouteGroupMenu::set_group), (RouteGroup *) 0)));
58 static_cast<RadioMenuItem*> (&items().back())->set_active ();
62 _session->foreach_route_group (sigc::bind (sigc::mem_fun (*this, &RouteGroupMenu::add_item), curr, &group));
65 _inhibit_group_selected = false;
69 RouteGroupMenu::add_item (RouteGroup* rg, RouteGroup* curr, RadioMenuItem::Group* group)
71 using namespace Menu_Helpers;
73 items().push_back (RadioMenuElem (*group, rg->name(), sigc::bind (sigc::mem_fun(*this, &RouteGroupMenu::set_group), rg)));
76 static_cast<RadioMenuItem*> (&items().back())->set_active ();
81 RouteGroupMenu::set_group (RouteGroup* g)
83 if (g == _selected_route_group) {
84 /* cut off the signal_toggled that GTK emits for an option that is being un-selected
85 when a new option is being selected instead
90 if (!_inhibit_group_selected) {
94 _selected_route_group = g;
98 RouteGroupMenu::new_group ()
104 RouteGroup* g = new RouteGroup (*_session, "", RouteGroup::Active, _default_properties);
106 RouteGroupDialog d (g, Gtk::Stock::NEW);
107 int const r = d.do_run ();
109 if (r == Gtk::RESPONSE_OK) {
110 _session->add_route_group (g);