2014-02-26 11:55:06 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2014 Robin Gareus <robin@gareus.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
#include "i18n.h"
|
2014-02-26 19:35:57 -05:00
|
|
|
#include "pbd/pathexpand.h"
|
|
|
|
#include "gtkmm2ext/paths_dialog.h"
|
2014-02-26 11:55:06 -05:00
|
|
|
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace std;
|
2014-02-26 19:35:57 -05:00
|
|
|
using namespace Gtkmm2ext;
|
2014-02-26 11:55:06 -05:00
|
|
|
|
2014-02-28 18:56:24 -05:00
|
|
|
PathsDialog::PathsDialog (std::string title, std::string current_paths, std::string default_paths)
|
2014-02-26 19:35:57 -05:00
|
|
|
: Dialog (title, true)
|
2014-02-28 18:56:24 -05:00
|
|
|
, paths_list_view(1, false, Gtk::SELECTION_SINGLE)
|
2014-02-26 11:55:06 -05:00
|
|
|
, add_path_button(_("Add"))
|
|
|
|
, remove_path_button(_("Delete"))
|
2014-02-28 18:56:24 -05:00
|
|
|
, set_default_button(_("Reset to Default"))
|
|
|
|
, _default_paths(default_paths)
|
2014-02-26 11:55:06 -05:00
|
|
|
{
|
|
|
|
set_name ("PathsDialog");
|
|
|
|
set_skip_taskbar_hint (true);
|
|
|
|
set_resizable (true);
|
|
|
|
set_size_request (400, -1);
|
|
|
|
|
|
|
|
paths_list_view.set_border_width (4);
|
|
|
|
|
|
|
|
add_path_button.signal_clicked().connect (sigc::mem_fun (*this, &PathsDialog::add_path));
|
|
|
|
remove_path_button.signal_clicked().connect (sigc::mem_fun (*this, &PathsDialog::remove_path));
|
2014-02-28 18:56:24 -05:00
|
|
|
set_default_button.signal_clicked().connect (sigc::mem_fun (*this, &PathsDialog::set_default));
|
2014-02-26 11:55:06 -05:00
|
|
|
remove_path_button.set_sensitive(false);
|
|
|
|
|
2014-02-28 18:56:24 -05:00
|
|
|
paths_list_view.set_column_title(0,"Path");
|
2014-02-26 11:55:06 -05:00
|
|
|
|
2014-02-28 18:56:24 -05:00
|
|
|
std::vector <std::string> a = PBD::parse_path(current_paths);
|
2014-02-26 11:55:06 -05:00
|
|
|
for(vector<std::string>::const_iterator i = a.begin(); i != a.end(); ++i) {
|
2014-03-02 16:38:29 -05:00
|
|
|
paths_list_view.append_text(*i);
|
2014-02-26 11:55:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
paths_list_view.get_selection()->signal_changed().connect (mem_fun (*this, &PathsDialog::selection_changed));
|
|
|
|
|
2014-02-28 18:56:24 -05:00
|
|
|
VBox *vbox = manage (new VBox);
|
|
|
|
vbox->pack_start (add_path_button, false, false);
|
|
|
|
vbox->pack_start (remove_path_button, false, false);
|
|
|
|
vbox->pack_start (set_default_button, false, false);
|
|
|
|
|
2014-02-26 11:55:06 -05:00
|
|
|
/* Overall layout */
|
|
|
|
HBox *hbox = manage (new HBox);
|
2014-02-28 18:56:24 -05:00
|
|
|
hbox->pack_start (*vbox, false, false);
|
|
|
|
hbox->pack_start (paths_list_view, true, true); // TODO, wrap in scroll-area ?!
|
|
|
|
hbox->set_spacing (4);
|
|
|
|
|
2014-02-26 11:55:06 -05:00
|
|
|
get_vbox()->set_spacing (4);
|
|
|
|
get_vbox()->pack_start (*hbox, true, true);
|
|
|
|
|
|
|
|
add_button (Stock::CANCEL, RESPONSE_CANCEL);
|
|
|
|
add_button (Stock::OK, RESPONSE_ACCEPT);
|
|
|
|
|
|
|
|
show_all_children ();
|
|
|
|
}
|
|
|
|
|
|
|
|
PathsDialog::~PathsDialog ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PathsDialog::on_show() {
|
|
|
|
Dialog::on_show ();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
2014-02-28 18:56:24 -05:00
|
|
|
PathsDialog::get_serialized_paths() {
|
2014-02-26 11:55:06 -05:00
|
|
|
std::string path;
|
|
|
|
for (unsigned int i = 0; i < paths_list_view.size(); ++i) {
|
|
|
|
if (i > 0) path += G_SEARCHPATH_SEPARATOR;
|
2014-02-28 18:56:24 -05:00
|
|
|
path += paths_list_view.get_text(i, 0);
|
2014-02-26 11:55:06 -05:00
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PathsDialog::selection_changed () {
|
|
|
|
std::vector<int> selection = paths_list_view.get_selected();
|
|
|
|
if (selection.size() > 0) {
|
2014-02-28 18:56:24 -05:00
|
|
|
remove_path_button.set_sensitive(true);
|
|
|
|
} else {
|
|
|
|
remove_path_button.set_sensitive(false);
|
2014-02-26 11:55:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PathsDialog::add_path() {
|
|
|
|
Gtk::FileChooserDialog d (_("Add folder to search path"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
|
|
|
|
d.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
|
|
|
d.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
|
|
|
|
ResponseType r = (ResponseType) d.run ();
|
|
|
|
if (r == Gtk::RESPONSE_OK) {
|
|
|
|
std::string dir = d.get_filename();
|
|
|
|
if (Glib::file_test (dir, Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
|
2014-02-28 11:32:57 -05:00
|
|
|
bool dup = false;
|
|
|
|
for (unsigned int i = 0; i < paths_list_view.size(); ++i) {
|
2014-02-28 18:56:24 -05:00
|
|
|
if (paths_list_view.get_text(i, 0) == dir) {
|
2014-02-28 11:32:57 -05:00
|
|
|
dup = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!dup) {
|
2014-03-02 16:38:29 -05:00
|
|
|
paths_list_view.prepend_text(dir);
|
2014-02-28 11:32:57 -05:00
|
|
|
}
|
2014-02-26 11:55:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PathsDialog::remove_path() {
|
|
|
|
std::vector<int> selection = paths_list_view.get_selected();
|
2014-02-28 18:56:24 -05:00
|
|
|
if (selection.size() == 0 ) { return ; }
|
2014-02-26 11:55:06 -05:00
|
|
|
|
|
|
|
/* Gtk::ListViewText internals to delete row(s) */
|
|
|
|
Gtk::TreeModel::iterator row_it = paths_list_view.get_selection()->get_selected();
|
|
|
|
Glib::RefPtr<Gtk::TreeModel> reftm = paths_list_view.get_model();
|
|
|
|
Glib::RefPtr<Gtk::TreeStore> refStore = Glib::RefPtr<Gtk::TreeStore>::cast_dynamic(reftm);
|
|
|
|
if(refStore) {
|
|
|
|
refStore->erase(row_it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Glib::RefPtr<Gtk::ListStore> refLStore = Glib::RefPtr<Gtk::ListStore>::cast_dynamic(reftm);
|
|
|
|
if(refLStore){
|
|
|
|
refLStore->erase(row_it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-02-28 18:56:24 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
PathsDialog::set_default() {
|
|
|
|
|
|
|
|
paths_list_view.clear_items();
|
|
|
|
std::vector <std::string> a = PBD::parse_path(_default_paths);
|
|
|
|
for(vector<std::string>::const_iterator i = a.begin(); i != a.end(); ++i) {
|
2014-03-02 16:51:04 -05:00
|
|
|
paths_list_view.append_text(*i);
|
2014-02-28 18:56:24 -05:00
|
|
|
}
|
|
|
|
}
|