2 Copyright (C) 2014 Robin Gareus <robin@gareus.org>
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.
21 #include <gtkmm/filechooserdialog.h>
22 #include <gtkmm/liststore.h>
23 #include <gtkmm/stock.h>
24 #include <gtkmm/treestore.h>
27 #include "pbd/pathexpand.h"
28 #include "widgets/paths_dialog.h"
32 using namespace ArdourWidgets;
34 PathsDialog::PathsDialog (Gtk::Window& parent, std::string title, std::string current_paths, std::string default_paths)
35 : Dialog (title, parent, true)
36 , paths_list_view(1, false, Gtk::SELECTION_SINGLE)
37 , add_path_button(_("Add"))
38 , remove_path_button(_("Delete"))
39 , set_default_button(_("Reset to Default"))
40 , _default_paths(default_paths)
42 set_name ("PathsDialog");
43 set_skip_taskbar_hint (true);
45 set_size_request (400, -1);
47 paths_list_view.set_border_width (4);
49 add_path_button.signal_clicked().connect (sigc::mem_fun (*this, &PathsDialog::add_path));
50 remove_path_button.signal_clicked().connect (sigc::mem_fun (*this, &PathsDialog::remove_path));
51 set_default_button.signal_clicked().connect (sigc::mem_fun (*this, &PathsDialog::set_default));
52 remove_path_button.set_sensitive(false);
54 paths_list_view.set_column_title(0,"Path");
56 std::vector <std::string> a = PBD::parse_path(current_paths);
57 for(vector<std::string>::const_iterator i = a.begin(); i != a.end(); ++i) {
58 paths_list_view.append_text(*i);
61 paths_list_view.get_selection()->signal_changed().connect (mem_fun (*this, &PathsDialog::selection_changed));
63 VBox *vbox = manage (new VBox);
64 vbox->pack_start (add_path_button, false, false);
65 vbox->pack_start (remove_path_button, false, false);
66 vbox->pack_start (set_default_button, false, false);
69 HBox *hbox = manage (new HBox);
70 hbox->pack_start (*vbox, false, false);
71 hbox->pack_start (paths_list_view, true, true); // TODO, wrap in scroll-area ?!
72 hbox->set_spacing (4);
74 get_vbox()->set_spacing (4);
75 get_vbox()->pack_start (*hbox, true, true);
77 add_button (Stock::CANCEL, RESPONSE_CANCEL);
78 add_button (Stock::OK, RESPONSE_ACCEPT);
83 PathsDialog::~PathsDialog ()
88 PathsDialog::on_show() {
93 PathsDialog::get_serialized_paths() {
95 for (unsigned int i = 0; i < paths_list_view.size(); ++i) {
96 if (i > 0) path += G_SEARCHPATH_SEPARATOR;
97 path += paths_list_view.get_text(i, 0);
103 PathsDialog::selection_changed () {
104 std::vector<int> selection = paths_list_view.get_selected();
105 if (selection.size() > 0) {
106 remove_path_button.set_sensitive(true);
108 remove_path_button.set_sensitive(false);
113 PathsDialog::add_path() {
114 Gtk::FileChooserDialog d (_("Add folder to search path"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
116 std::vector<int> selection = paths_list_view.get_selected();
117 if (selection.size() == 1 ) {
118 d.set_current_folder(paths_list_view.get_text(selection.at(0), 0));
121 d.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
122 d.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
123 ResponseType r = (ResponseType) d.run ();
124 if (r == Gtk::RESPONSE_OK) {
125 std::string dir = d.get_filename();
126 if (Glib::file_test (dir, Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
128 for (unsigned int i = 0; i < paths_list_view.size(); ++i) {
129 if (paths_list_view.get_text(i, 0) == dir) {
135 paths_list_view.prepend_text(dir);
142 PathsDialog::remove_path() {
143 std::vector<int> selection = paths_list_view.get_selected();
144 if (selection.size() == 0 ) { return ; }
146 /* Gtk::ListViewText internals to delete row(s) */
147 Gtk::TreeModel::iterator row_it = paths_list_view.get_selection()->get_selected();
148 Glib::RefPtr<Gtk::TreeModel> reftm = paths_list_view.get_model();
149 Glib::RefPtr<Gtk::TreeStore> refStore = Glib::RefPtr<Gtk::TreeStore>::cast_dynamic(reftm);
151 refStore->erase(row_it);
154 Glib::RefPtr<Gtk::ListStore> refLStore = Glib::RefPtr<Gtk::ListStore>::cast_dynamic(reftm);
156 refLStore->erase(row_it);
162 PathsDialog::set_default() {
164 paths_list_view.clear_items();
165 std::vector <std::string> a = PBD::parse_path(_default_paths);
166 for(vector<std::string>::const_iterator i = a.begin(); i != a.end(); ++i) {
167 paths_list_view.append_text(*i);