2 Copyright (C) 2006 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.
20 #include <gtkmm2ext/pathlist.h>
25 using namespace Gtkmm2ext;
32 _store(Gtk::ListStore::create(path_columns)),
35 _view.append_column(_("Paths"), path_columns.paths);
36 _view.set_size_request(-1, 100);
37 _view.set_headers_visible (false);
39 Gtk::ScrolledWindow* scroll = manage(new Gtk::ScrolledWindow);
40 scroll->set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
45 Gtk::HBox* btn_box = manage(new Gtk::HBox);
46 btn_box->add(add_btn);
47 btn_box->add(subtract_btn);
51 add_btn.signal_clicked().connect (mem_fun(*this, &PathList::add_btn_clicked));
52 subtract_btn.signal_clicked().connect (mem_fun(*this, &PathList::subtract_btn_clicked));
53 _view.get_selection()->signal_changed().connect (mem_fun(*this, &PathList::selection_changed));
57 PathList::get_paths ()
61 Gtk::TreeModel::Children children(_store->children());
63 for (Gtk::TreeIter iter = children.begin(); iter != children.end(); ++iter) {
64 Gtk::ListStore::Row row = *iter;
66 paths.push_back(row[path_columns.paths]);
73 PathList::set_paths (vector<string> paths)
77 for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i) {
78 Gtk::ListStore::iterator iter = _store->append();
79 Gtk::ListStore::Row row = *iter;
80 row[path_columns.paths] = *i;
85 PathList::add_btn_clicked ()
87 Gtk::FileChooserDialog path_chooser (_("Path Chooser"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
89 path_chooser.add_button (Gtk::Stock::ADD, Gtk::RESPONSE_OK);
90 path_chooser.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
92 int result = path_chooser.run ();
94 if (result == Gtk::RESPONSE_OK) {
95 string pathname = path_chooser.get_filename();
97 if (pathname.length ()) {
98 Gtk::ListStore::iterator iter = _store->append ();
99 Gtk::ListStore::Row row = *iter;
100 row[path_columns.paths] = pathname;
102 PathsUpdated (); // EMIT_SIGNAL
108 PathList::subtract_btn_clicked ()
110 Gtk::ListStore::iterator iter = _view.get_selection()->get_selected();
111 _store->erase (iter);
113 PathsUpdated (); // EMIT_SIGNAL
117 PathList::selection_changed ()
119 if (_view.get_selection()->count_selected_rows ()) {
120 subtract_btn.set_sensitive (true);
122 subtract_btn.set_sensitive (false);