2 Copyright (C) 2000 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.
26 #include "ardour/named_selection.h"
27 #include "ardour/session_selection.h"
28 #include "ardour/playlist.h"
30 #include <gtkmm2ext/stop_signal.h>
34 #include "selection.h"
35 #include "time_axis_view.h"
36 #include "ardour_ui.h"
43 using namespace ARDOUR;
46 using namespace Gtkmm2ext;
49 Editor::handle_new_named_selection ()
51 ARDOUR_UI::instance()->call_slot (mem_fun(*this, &Editor::redisplay_named_selections));
55 Editor::add_named_selection_to_named_selection_display (NamedSelection& selection)
57 TreeModel::Row row = *(named_selection_model->append());
58 row[named_selection_columns.text] = selection.name;
59 row[named_selection_columns.selection] = &selection;
63 Editor::redisplay_named_selections ()
65 named_selection_model->clear ();
66 session->foreach_named_selection (*this, &Editor::add_named_selection_to_named_selection_display);
70 Editor::named_selection_display_key_release (GdkEventKey* ev)
78 remove_selected_named_selections ();
89 Editor::remove_selected_named_selections ()
91 Glib::RefPtr<TreeSelection> selection = named_selection_display.get_selection();
92 TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
94 if (selection->count_selected_rows() == 0) {
98 for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin(); i != rows.end(); ++i) {
102 if ((iter = named_selection_model->get_iter (*i))) {
103 session->remove_named_selection ((*iter)[named_selection_columns.selection]);
109 Editor::named_selection_display_button_release (GdkEventButton *ev)
111 TreeModel::Children rows = named_selection_model->children();
112 TreeModel::Children::iterator i;
113 Glib::RefPtr<TreeSelection> selection = named_selection_display.get_selection();
115 for (i = rows.begin(); i != rows.end(); ++i) {
116 if (selection->is_selected (i)) {
117 switch (ev->button) {
119 if (Keyboard::is_delete_event (ev)) {
120 session->remove_named_selection ((*i)[named_selection_columns.selection]);
139 Editor::named_selection_display_selection_changed ()
144 Editor::create_named_selection ()
152 /* check for a range-based selection */
154 if (selection->time.empty()) {
158 TrackViewList *views = get_valid_views (selection->time.track, selection->time.group);
160 if (views->empty()) {
165 boost::shared_ptr<Playlist> what_we_found;
166 list<boost::shared_ptr<Playlist> > thelist;
168 for (TrackViewList::iterator i = views->begin(); i != views->end(); ++i) {
170 boost::shared_ptr<Playlist> pl = (*i)->playlist();
172 if (pl && (what_we_found = pl->copy (selection->time, false)) != 0) {
173 thelist.push_back (what_we_found);
177 if (!thelist.empty()) {
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"));
189 case Gtk::RESPONSE_ACCEPT:
199 new NamedSelection (name, thelist); // creation will add it to the model
201 /* make the one we just added be selected */
203 TreeModel::Children::iterator added = named_selection_model->children().end();
205 named_selection_display.get_selection()->select (*added);
207 error << _("No selectable material found in the currently selected time range") << endmsg;