Reenable the correct sort column and type when redisplaying regions
[ardour.git] / gtk2_ardour / search_path_option.cc
1 /*
2  * Copyright (C) 2010-2011 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2010-2016 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2014 John Emmas <john@creativepost.co.uk>
5  * Copyright (C) 2017-2019 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include <gtkmm/stock.h>
23
24 #include "pbd/strsplit.h"
25 #include "pbd/compose.h"
26 #include "pbd/shortpath.h"
27
28 #include "gtkmm2ext/utils.h"
29
30 #include "search_path_option.h"
31 #include "pbd/i18n.h"
32
33 using namespace std;
34 using namespace Gtk;
35
36 SearchPathOption::SearchPathOption (const string& pathname, const string& label,
37                                     const string& default_path,
38                                     sigc::slot<std::string> get, sigc::slot<bool, std::string> set)
39         : Option (pathname, label)
40         , _get (get)
41         , _set (set)
42         , add_chooser (_("Select folder to search for media"), FILE_CHOOSER_ACTION_SELECT_FOLDER)
43 {
44         Gtkmm2ext::add_volume_shortcuts (add_chooser);
45         add_chooser.signal_file_set().connect (sigc::mem_fun (*this, &SearchPathOption::path_chosen));
46
47         HBox* hbox = manage (new HBox);
48
49         hbox->set_border_width (12);
50         hbox->set_spacing (6);
51         hbox->pack_end (add_chooser, true, true);
52         hbox->pack_end (*manage (new Label (_("Click to add a new location"))), false, false);
53         hbox->show_all ();
54
55         vbox.pack_start (path_box);
56         vbox.pack_end (*hbox);
57
58         session_label.set_use_markup (true);
59         session_label.set_markup (string_compose ("<i>%1 (%2)</i>", _("the session folder"), short_path (default_path, 32)));
60         session_label.set_alignment (0.0, 0.5);
61         session_label.show ();
62
63         path_box.pack_start (session_label);
64 }
65
66 SearchPathOption::~SearchPathOption()
67 {
68
69
70 }
71
72 void
73 SearchPathOption::path_chosen ()
74 {
75         string path = add_chooser.get_filename ();
76         add_path (path);
77         changed ();
78 }
79
80 void
81 SearchPathOption::add_to_page (OptionEditorPage* p)
82 {
83         int const n = p->table.property_n_rows();
84         p->table.resize (n + 1, 3);
85
86         Label* label = manage (new Label);
87         label->set_alignment (0.0, 0.0);
88         label->set_text (string_compose ("%1", _name));
89
90         p->table.attach (*label, 1, 2, n, n + 1, FILL | EXPAND);
91         p->table.attach (vbox, 2, 3, n, n + 1, FILL | EXPAND);
92 }
93
94 void
95 SearchPathOption::clear ()
96 {
97         path_box.remove (session_label);
98         for (list<PathEntry*>::iterator p = paths.begin(); p != paths.end(); ++p) {
99                 path_box.remove ((*p)->box);
100                 delete *p;
101         }
102         paths.clear ();
103 }
104
105 void
106 SearchPathOption::set_state_from_config ()
107 {
108         string str = _get ();
109         vector<string> dirs;
110
111         clear ();
112         path_box.pack_start (session_label);
113
114         split (str, dirs, G_SEARCHPATH_SEPARATOR);
115
116         for (vector<string>::iterator d = dirs.begin(); d != dirs.end(); ++d) {
117                 add_path (*d);
118         }
119 }
120
121 void
122 SearchPathOption::changed ()
123 {
124         string str;
125
126         for (list<PathEntry*>::iterator p = paths.begin(); p != paths.end(); ++p) {
127
128                 if (!str.empty()) {
129                         str += G_SEARCHPATH_SEPARATOR;
130                 }
131                 str += (*p)->entry.get_text ();
132         }
133
134         _set (str);
135 }
136
137 void
138 SearchPathOption::add_path (const string& path, bool removable)
139 {
140         PathEntry* pe = new PathEntry (path, removable);
141         paths.push_back (pe);
142         path_box.pack_start (pe->box, false, false);
143         pe->remove_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &SearchPathOption::remove_path), pe));
144 }
145
146 void
147 SearchPathOption::remove_path (PathEntry* pe)
148 {
149         path_box.remove (pe->box);
150         paths.remove (pe);
151         delete pe;
152         changed ();
153 }
154
155 SearchPathOption::PathEntry::PathEntry (const std::string& path, bool removable)
156         : remove_button (Stock::REMOVE)
157 {
158         entry.set_text (path);
159         entry.show ();
160
161         box.set_spacing (6);
162         box.set_homogeneous (false);
163         box.pack_start (entry, true, true);
164
165         if (removable) {
166                 box.pack_start (remove_button, false, false);
167                 remove_button.show ();
168         }
169
170         box.show ();
171 }