Remove most using declarations from header files.
[ardour.git] / gtk2_ardour / editor_selection_list.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 */
19
20 #include <cstdlib>
21 #include <cmath>
22 #include <vector>
23
24 #include <gtkmm.h>
25
26 #include "ardour/named_selection.h"
27 #include "ardour/session_selection.h"
28 #include "ardour/playlist.h"
29
30 #include <gtkmm2ext/stop_signal.h>
31
32 #include "editor.h"
33 #include "keyboard.h"
34 #include "selection.h"
35 #include "time_axis_view.h"
36 #include "ardour_ui.h"
37 #include "prompter.h"
38
39 #include "i18n.h"
40
41 using namespace std;
42 using namespace sigc;
43 using namespace ARDOUR;
44 using namespace PBD;
45 using namespace Gtk;
46 using namespace Gtkmm2ext;
47
48 void
49 Editor::handle_new_named_selection ()
50 {
51         ARDOUR_UI::instance()->call_slot (mem_fun(*this, &Editor::redisplay_named_selections));
52 }
53
54 void
55 Editor::add_named_selection_to_named_selection_display (NamedSelection& selection)
56 {
57         TreeModel::Row row = *(named_selection_model->append());
58         row[named_selection_columns.text] = selection.name;
59         row[named_selection_columns.selection] = &selection;
60 }
61
62 void
63 Editor::redisplay_named_selections ()
64 {
65         named_selection_model->clear ();
66         session->foreach_named_selection (*this, &Editor::add_named_selection_to_named_selection_display);
67 }
68
69 bool
70 Editor::named_selection_display_key_release (GdkEventKey* ev)
71 {
72         if (session == 0) {
73                 return true;
74         }
75
76         switch (ev->keyval) {
77         case GDK_Delete:
78                 remove_selected_named_selections ();
79                 return true;
80                 break;
81         default:
82                 return false;
83                 break;
84         }
85
86 }
87
88 void
89 Editor::remove_selected_named_selections ()
90 {
91         Glib::RefPtr<TreeSelection> selection = named_selection_display.get_selection();
92         TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
93
94         if (selection->count_selected_rows() == 0) {
95                 return;
96         }
97
98         for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin(); i != rows.end(); ++i) {
99
100                 TreeIter iter;
101
102                 if ((iter = named_selection_model->get_iter (*i))) {
103                         session->remove_named_selection ((*iter)[named_selection_columns.selection]);
104                 }
105         }
106 }
107
108 bool
109 Editor::named_selection_display_button_release (GdkEventButton *ev)
110 {
111         TreeModel::Children rows = named_selection_model->children();
112         TreeModel::Children::iterator i;
113         Glib::RefPtr<TreeSelection> selection = named_selection_display.get_selection();
114
115         for (i = rows.begin(); i != rows.end(); ++i) {
116                 if (selection->is_selected (i)) {
117                         switch (ev->button) {
118                         case 1:
119                                 if (Keyboard::is_delete_event (ev)) {
120                                         session->remove_named_selection ((*i)[named_selection_columns.selection]);
121                                         return true;
122                                 }
123                                 break;
124                         case 2:
125                                 break;
126                         case 3:
127                                 break;
128                         default:
129                                 break;
130                         }
131                 }
132         }
133
134         return false;
135 }
136
137
138 void
139 Editor::named_selection_display_selection_changed ()
140 {
141 }
142
143 void
144 Editor::create_named_selection ()
145 {
146         string name;
147
148         if (session == 0) {
149                 return;
150         }
151
152         /* check for a range-based selection */
153
154         if (selection->time.empty()) {
155                 return;
156         }
157         
158         TrackViewList *views = get_valid_views (selection->time.track, selection->time.group);
159
160         if (views->empty()) {
161                 delete views;
162                 return;
163         }
164
165         boost::shared_ptr<Playlist>        what_we_found;
166         list<boost::shared_ptr<Playlist> > thelist;
167
168         for (TrackViewList::iterator i = views->begin(); i != views->end(); ++i) {
169                 
170                 boost::shared_ptr<Playlist> pl = (*i)->playlist();
171                 
172                 if (pl && (what_we_found = pl->copy (selection->time, false)) != 0) {
173                         thelist.push_back (what_we_found);
174                 }
175         }
176
177         if (!thelist.empty()) {
178
179                 ArdourPrompter p;
180                 
181                 p.set_prompt (_("Name for Chunk:"));
182                 p.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
183                 p.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
184                 p.change_labels (_("Create Chunk"), _("Forget it"));
185                 p.show_all ();
186                 
187                 switch (p.run ()) {
188                         
189                 case Gtk::RESPONSE_ACCEPT:
190                         p.get_result (name);
191                         if (name.empty()) {
192                                 return;
193                         }       
194                         break;
195                 default:
196                         return;
197                 }
198
199                 new NamedSelection (name, thelist); // creation will add it to the model
200
201                 /* make the one we just added be selected */
202                 
203                 TreeModel::Children::iterator added = named_selection_model->children().end();
204                 --added;
205                 named_selection_display.get_selection()->select (*added);
206         } else {
207                 error << _("No selectable material found in the currently selected time range") << endmsg;
208         }
209 }
210