route list + edit group list now pretty much functional, plus preparations for ardour...
[ardour.git] / gtk2_ardour / editor_edit_groups.cc
1 /*
2     Copyright (C) 2000 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     $Id$
19 */
20
21 #include <cstdlib>
22 #include <cmath>
23
24 #include <gtkmm2ext/stop_signal.h>
25 #include <gtkmm2ext/gtk_ui.h>
26 #include <ardour/route_group.h>
27
28 #include "editor.h"
29 #include "keyboard.h"
30 #include "marker.h"
31 #include "time_axis_view.h"
32 #include "prompter.h"
33 #include "gui_thread.h"
34
35 #include <ardour/route.h>
36
37 #include "i18n.h"
38
39 using namespace sigc;
40 using namespace ARDOUR;
41 using namespace Gtk;
42
43 void
44 Editor::build_edit_group_list_menu ()
45 {
46         using namespace Gtk::Menu_Helpers;
47
48         edit_group_list_menu = new Menu;
49         edit_group_list_menu->set_name ("ArdourContextMenu");
50         MenuList& items = edit_group_list_menu->items();
51
52         items.push_back (MenuElem (_("Activate All"), mem_fun(*this, &Editor::activate_all_edit_groups)));
53         items.push_back (MenuElem (_("Disable All"), mem_fun(*this, &Editor::disable_all_edit_groups)));
54         items.push_back (SeparatorElem());
55         items.push_back (MenuElem (_("Add group"), mem_fun(*this, &Editor::new_edit_group)));
56         
57 }
58
59 void
60 Editor::activate_all_edit_groups ()
61 {
62         Gtk::TreeModel::Children children = group_model->children();
63         for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
64                 (*iter)[group_columns.is_active] = true;
65         }
66 }
67
68 void
69 Editor::disable_all_edit_groups ()
70 {
71         Gtk::TreeModel::Children children = group_model->children();
72         for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
73                 (*iter)[group_columns.is_active] = false;
74         }
75 }
76
77 void
78 Editor::new_edit_group ()
79 {
80         if (session == 0) {
81                 return;
82         }
83
84         ArdourPrompter prompter;
85         string result;
86
87         prompter.set_prompt (_("Name for new edit group"));
88         prompter.show_all ();
89
90         switch (prompter.run ()) {
91         case GTK_RESPONSE_ACCEPT:
92                 prompter.get_result (result);
93                 if (result.length()) {
94                         session->add_edit_group (result);
95                 }
96                 break;
97         }
98 }
99
100 void
101 Editor::edit_group_list_button_clicked ()
102 {
103         new_edit_group ();
104 }
105
106 gint
107 Editor::edit_group_list_button_press_event (GdkEventButton* ev)
108 {
109         if (Keyboard::is_context_menu_event (ev)) {
110                 if (edit_group_list_menu == 0) {
111                         build_edit_group_list_menu ();
112                 }
113                 edit_group_list_menu->popup (1, 0);
114                 return true;
115         }
116
117
118         RouteGroup* group;
119         TreeIter iter;
120         TreeModel::Path path;
121         TreeViewColumn* column;
122         int cellx;
123         int celly;
124
125         if (!edit_group_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
126                 return false;
127         }
128
129         switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
130         case 2:
131                 if (Keyboard::is_edit_event (ev)) {
132                         if ((iter = group_model->get_iter (path))) {
133                                 if ((group = (*iter)[group_columns.routegroup]) != 0) {
134                                         // edit_route_group (group);
135                                         return true;
136                                 }
137                         }
138                         
139                 } 
140                 break;
141
142         case 1:
143                 if ((iter = group_model->get_iter (path))) {
144                         bool visible = (*iter)[group_columns.is_visible];
145                         (*iter)[group_columns.is_visible] = !visible;
146                         return true;
147                 }
148                 break;
149
150         case 0:
151                 if ((iter = group_model->get_iter (path))) {
152                         bool active = (*iter)[group_columns.is_active];
153                         (*iter)[group_columns.is_active] = !active;
154                         return true;
155                 }
156                 break;
157                 
158         default:
159                 break;
160         }
161         
162         return false;
163  }
164
165 void 
166 Editor::edit_group_row_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter)
167 {
168         RouteGroup* group;
169
170         if ((group = (*iter)[group_columns.routegroup]) == 0) {
171                 return;
172         }
173
174         if ((*iter)[group_columns.is_visible]) {
175                 for (TrackViewList::iterator j = track_views.begin(); j != track_views.end(); ++j) {
176                         if ((*j)->edit_group() == group) {
177                                 show_track_in_display (**j);
178                         }
179                 }
180         } else {
181                 for (TrackViewList::iterator j = track_views.begin(); j != track_views.end(); ++j) {
182                         if ((*j)->edit_group() == group) {
183                                 hide_track_in_display (**j);
184                         }
185                 }
186         }
187
188         bool active = (*iter)[group_columns.is_active];
189         group->set_active (active, this);
190 }
191
192 void
193 Editor::add_edit_group (RouteGroup* group)
194 {
195         ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::add_edit_group), group));
196
197         TreeModel::Row row = *(group_model->append());
198         row[group_columns.is_active] = group->is_active();
199         row[group_columns.is_visible] = true;
200         row[group_columns.text] = group->name();
201         row[group_columns.routegroup] = group;
202
203         group->FlagsChanged.connect (bind (mem_fun(*this, &Editor::group_flags_changed), group));
204 }
205
206 void
207 Editor::group_flags_changed (void* src, RouteGroup* group)
208 {
209         ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::group_flags_changed), src, group));
210
211         Gtk::TreeModel::Children children = group_model->children();
212         for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
213                 if (group == (*iter)[group_columns.routegroup]) {
214                         (*iter)[group_columns.is_active] = group->is_active();
215                 }
216         }
217 }
218
219