summaryrefslogtreecommitdiff
path: root/gtk2_ardour/route_group_menu.cc
blob: baf383be5d2f669f57431643752444cb5252f8cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
    Copyright (C) 2009 Paul Davis

    This program 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.

    This program 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 more 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., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include <gtkmm/menu.h>
#include <gtkmm/stock.h>
#include "ardour/session.h"
#include "ardour/route_group.h"
#include "route_group_menu.h"
#include "route_group_dialog.h"
#include "i18n.h"

using namespace Gtk;
using namespace ARDOUR;
using namespace PBD;

RouteGroupMenu::RouteGroupMenu (Session* s, PropertyList* plist)
	: SessionHandlePtr (s)
	, _default_properties (plist)
	, _inhibit_group_selected (false)
	, _selected_route_group (0)
{
	rebuild (0);
}

RouteGroupMenu::~RouteGroupMenu()
{
	delete _default_properties; 
}

void
RouteGroupMenu::rebuild (RouteGroup* curr)
{
	using namespace Menu_Helpers;

	_selected_route_group = curr;

	_inhibit_group_selected = true;

	items().clear ();

	items().push_back (MenuElem (_("New group..."), sigc::mem_fun (*this, &RouteGroupMenu::new_group)));
	items().push_back (SeparatorElem ());

	RadioMenuItem::Group group;
	items().push_back (RadioMenuElem (group, _("No group"), sigc::bind (sigc::mem_fun (*this, &RouteGroupMenu::set_group), (RouteGroup *) 0)));

	if (curr == 0) {
		static_cast<RadioMenuItem*> (&items().back())->set_active ();
	}

	if (_session) {
		_session->foreach_route_group (sigc::bind (sigc::mem_fun (*this, &RouteGroupMenu::add_item), curr, &group));
	}

	_inhibit_group_selected = false;
}

void
RouteGroupMenu::add_item (RouteGroup* rg, RouteGroup* curr, RadioMenuItem::Group* group)
{
	using namespace Menu_Helpers;

	items().push_back (RadioMenuElem (*group, rg->name(), sigc::bind (sigc::mem_fun(*this, &RouteGroupMenu::set_group), rg)));

	if (rg == curr) {
		static_cast<RadioMenuItem*> (&items().back())->set_active ();
	}
}

void
RouteGroupMenu::set_group (RouteGroup* g)
{
	if (g == _selected_route_group) {
		/* cut off the signal_toggled that GTK emits for an option that is being un-selected
		   when a new option is being selected instead
		*/
		return;
	}
	
	if (!_inhibit_group_selected) {
		GroupSelected (g);
	}

	_selected_route_group = g;
}

void
RouteGroupMenu::new_group ()
{
	if (!_session) {
		return;
	}

	RouteGroup* g = new RouteGroup (*_session, "");
	g->set_properties (*_default_properties);

	RouteGroupDialog d (g, Gtk::Stock::NEW);
	int const r = d.do_run ();

	if (r == Gtk::RESPONSE_OK) {
		_session->add_route_group (g);
		set_group (g);
	} else {
		delete g;
	}
}