drastic, deep and wide changes to make RouteGroup use boost::shared_ptr<Route> and...
[ardour.git] / gtk2_ardour / route_group_menu.cc
1 /*
2     Copyright (C) 2009 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
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"
26 #include "i18n.h"
27
28 using namespace Gtk;
29 using namespace ARDOUR;
30
31 RouteGroupMenu::RouteGroupMenu (Session& s, RouteGroup::Property p)
32         : _session (s),
33           _default_properties (p)
34 {
35         rebuild (0);
36 }
37
38 void
39 RouteGroupMenu::rebuild (RouteGroup* curr)
40 {
41         using namespace Menu_Helpers;
42
43         items().clear ();
44
45         items().push_back (MenuElem (_("New group..."), mem_fun (*this, &RouteGroupMenu::new_group)));
46         items().push_back (SeparatorElem ());
47
48         RadioMenuItem::Group group;
49         items().push_back (RadioMenuElem (group, _("No group"), bind (mem_fun (*this, &RouteGroupMenu::set_group), (RouteGroup *) 0)));
50
51         if (curr == 0) {
52                 static_cast<RadioMenuItem*> (&items().back())->set_active ();
53         }
54
55         _session.foreach_route_group (bind (mem_fun (*this, &RouteGroupMenu::add_item), curr, &group));
56 }
57
58 void
59 RouteGroupMenu::add_item (RouteGroup* rg, RouteGroup* curr, RadioMenuItem::Group* group)
60 {
61         using namespace Menu_Helpers;
62
63         items().push_back (RadioMenuElem (*group, rg->name(), bind (mem_fun(*this, &RouteGroupMenu::set_group), rg)));
64
65         if (rg == curr) {
66                 static_cast<RadioMenuItem*> (&items().back())->set_active ();
67         }
68 }
69
70 void
71 RouteGroupMenu::set_group (RouteGroup* g)
72 {
73         GroupSelected (g);
74 }
75
76 void
77 RouteGroupMenu::new_group ()
78 {
79         RouteGroup* g = new RouteGroup (_session, "", RouteGroup::Active, _default_properties);
80
81         RouteGroupDialog d (g, Gtk::Stock::NEW);
82         int const r = d.do_run ();
83
84         if (r == Gtk::RESPONSE_OK) {
85                 _session.add_route_group (g);
86                 set_group (g);
87         } else {
88                 delete g;
89         }
90 }