various fixes to MidiRegionView selection handling, key handling, drawing of ghost...
[ardour2.git] / gtk2_ardour / search_path_option.cc
blob92b7938eddb7771a44daa2f44f0172be8c193bd9
1 /*
2 Copyright (C) 2010 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.
19 #include "pbd/strsplit.h"
20 #include "pbd/compose.h"
21 #include "search_path_option.h"
22 #include "i18n.h"
24 using namespace std;
25 using namespace Gtk;
27 SearchPathOption::SearchPathOption (const string& pathname, const string& label,
28 sigc::slot<std::string> get, sigc::slot<bool, std::string> set)
29 : Option (pathname, label)
30 , _get (get)
31 , _set (set)
32 , add_chooser (_("Select folder to search for media"), FILE_CHOOSER_ACTION_SELECT_FOLDER)
34 add_chooser.signal_file_set().connect (sigc::mem_fun (*this, &SearchPathOption::path_chosen));
36 HBox* hbox = manage (new HBox);
38 hbox->set_border_width (12);
39 hbox->set_spacing (6);
40 hbox->pack_end (add_chooser, true, true);
41 hbox->pack_end (*manage (new Label (_("Click to add a new location"))), false, false);
42 hbox->show_all ();
44 vbox.pack_start (path_box);
45 vbox.pack_end (*hbox);
47 session_label.set_use_markup (true);
48 session_label.set_markup (string_compose ("<i>%1</i>", _("the session folder")));
49 session_label.set_alignment (0.0, 0.5);
50 session_label.show ();
52 path_box.pack_start (session_label);
55 SearchPathOption::~SearchPathOption()
61 void
62 SearchPathOption::path_chosen ()
64 string path = add_chooser.get_filename ();
65 add_path (path);
66 changed ();
69 void
70 SearchPathOption::add_to_page (OptionEditorPage* p)
72 int const n = p->table.property_n_rows();
73 p->table.resize (n + 1, 3);
75 Label* label = manage (new Label);
76 label->set_alignment (0.0, 0.0);
77 label->set_markup (string_compose ("%1", _name));
79 p->table.attach (*label, 1, 2, n, n + 1, FILL | EXPAND);
80 p->table.attach (vbox, 2, 3, n, n + 1, FILL | EXPAND);
83 void
84 SearchPathOption::clear ()
86 path_box.remove (session_label);
87 for (list<PathEntry*>::iterator p = paths.begin(); p != paths.end(); ++p) {
88 path_box.remove ((*p)->box);
89 delete *p;
91 paths.clear ();
94 void
95 SearchPathOption::set_state_from_config ()
97 string str = _get ();
98 vector<string> dirs;
100 clear ();
101 path_box.pack_start (session_label);
103 split (str, dirs, ':');
105 for (vector<string>::iterator d = dirs.begin(); d != dirs.end(); ++d) {
106 add_path (*d);
110 void
111 SearchPathOption::changed ()
113 string str;
115 for (list<PathEntry*>::iterator p = paths.begin(); p != paths.end(); ++p) {
117 if (!str.empty()) {
118 str += ':';
120 str += (*p)->entry.get_text ();
123 _set (str);
126 void
127 SearchPathOption::add_path (const string& path, bool removable)
129 PathEntry* pe = new PathEntry (path, removable);
130 paths.push_back (pe);
131 path_box.pack_start (pe->box, false, false);
132 pe->remove_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &SearchPathOption::remove_path), pe));
135 void
136 SearchPathOption::remove_path (PathEntry* pe)
138 path_box.remove (pe->box);
139 paths.remove (pe);
140 delete pe;
141 changed ();
144 SearchPathOption::PathEntry::PathEntry (const std::string& path, bool removable)
145 : remove_button (Stock::REMOVE)
147 entry.set_text (path);
148 entry.show ();
150 box.set_spacing (6);
151 box.set_homogeneous (false);
152 box.pack_start (entry, true, true);
154 if (removable) {
155 box.pack_start (remove_button, false, false);
156 remove_button.show ();
159 box.show ();