mackie: restore access to trim and pan width control
[ardour.git] / libs / gtkmm2ext / paths_dialog.cc
index 7b42a85f32a7a1322c9dfcafa6e7f2c24c318a80..1f3a3b5de640add4436e44e07caa10da000740cf 100644 (file)
@@ -26,11 +26,13 @@ using namespace Gtk;
 using namespace std;
 using namespace Gtkmm2ext;
 
-PathsDialog::PathsDialog (std::string title, std::string user_paths, std::string fixed_paths)
+PathsDialog::PathsDialog (std::string title, std::string current_paths, std::string default_paths)
        : Dialog (title, true)
-       , paths_list_view(2, false, Gtk::SELECTION_SINGLE)
+       , paths_list_view(1, false, Gtk::SELECTION_SINGLE)
        , add_path_button(_("Add"))
        , remove_path_button(_("Delete"))
+       , set_default_button(_("Reset to Default"))
+       , _default_paths(default_paths)
 {
        set_name ("PathsDialog");
        set_skip_taskbar_hint (true);
@@ -41,35 +43,34 @@ PathsDialog::PathsDialog (std::string title, std::string user_paths, std::string
 
        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));
+       set_default_button.signal_clicked().connect (sigc::mem_fun (*this, &PathsDialog::set_default));
        remove_path_button.set_sensitive(false);
 
-       paths_list_view.set_column_title(0,"Type");
-       paths_list_view.set_column_title(1,"Path");
+       paths_list_view.set_column_title(0,"Path");
 
-       /* TODO fill in Text View */
-       std::vector <std::string> a = PBD::parse_path(user_paths);
+       std::vector <std::string> a = PBD::parse_path(current_paths);
        for(vector<std::string>::const_iterator i = a.begin(); i != a.end(); ++i) {
-               int row = paths_list_view.append(_("user"));
-               paths_list_view.set_text(row, 1, *i);
-       }
-       a = PBD::parse_path(fixed_paths);
-       for(vector<std::string>::const_iterator i = a.begin(); i != a.end(); ++i) {
-               int row = paths_list_view.append( _("sys"));
-               paths_list_view.set_text(row, 1, *i);
+               paths_list_view.append_text(*i);
        }
 
        paths_list_view.get_selection()->signal_changed().connect (mem_fun (*this, &PathsDialog::selection_changed));
 
+       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);
+
        /* Overall layout */
        HBox *hbox = manage (new HBox);
-       hbox->pack_start (paths_list_view, true, true);
+       hbox->pack_start (*vbox, false, false);
+       hbox->pack_start (paths_list_view, true, true); // TODO, wrap in scroll-area ?!
+       hbox->set_spacing (4);
+
        get_vbox()->set_spacing (4);
        get_vbox()->pack_start (*hbox, true, true);
 
        add_button (Stock::CANCEL, RESPONSE_CANCEL);
        add_button (Stock::OK, RESPONSE_ACCEPT);
-       get_action_area()->pack_start (add_path_button, false, false);
-       get_action_area()->pack_start (remove_path_button, false, false);
 
        show_all_children ();
 }
@@ -84,12 +85,11 @@ PathsDialog::on_show() {
 }
 
 std::string
-PathsDialog::get_serialized_paths(bool include_fixed) {
+PathsDialog::get_serialized_paths() {
        std::string path;
        for (unsigned int i = 0; i < paths_list_view.size(); ++i) {
-               if (!include_fixed && paths_list_view.get_text(i, 0) != _("user")) continue;
                if (i > 0) path += G_SEARCHPATH_SEPARATOR;
-               path += paths_list_view.get_text(i, 1);
+               path += paths_list_view.get_text(i, 0);
        }
        return path;
 }
@@ -98,26 +98,37 @@ void
 PathsDialog::selection_changed () {
        std::vector<int> selection = paths_list_view.get_selected();
        if (selection.size() > 0) {
-               const int row = selection.at(0);
-               if (paths_list_view.get_text(row, 0) == _("user")) {
-                       remove_path_button.set_sensitive(true);
-                       return;
-               }
+               remove_path_button.set_sensitive(true);
+       } else {
+               remove_path_button.set_sensitive(false);
        }
-       remove_path_button.set_sensitive(false);
 }
 
 void
 PathsDialog::add_path() {
        Gtk::FileChooserDialog d (_("Add folder to search path"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
+
+       std::vector<int> selection = paths_list_view.get_selected();
+       if (selection.size() == 1 ) {
+               d.set_current_folder(paths_list_view.get_text(selection.at(0), 0));
+       }
+
        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)) {
-                       paths_list_view.prepend(_("user"));
-                       paths_list_view.set_text(0, 1, dir);
+                       bool dup = false;
+                       for (unsigned int i = 0; i < paths_list_view.size(); ++i) {
+                               if (paths_list_view.get_text(i, 0) == dir) {
+                                       dup = true;
+                                       break;
+                               }
+                       }
+                       if (!dup) {
+                               paths_list_view.prepend_text(dir);
+                       }
                }
        }
 }
@@ -125,9 +136,7 @@ PathsDialog::add_path() {
 void
 PathsDialog::remove_path() {
        std::vector<int> selection = paths_list_view.get_selected();
-       if (selection.size() != 1) { return ; }
-       const int row = selection.at(0);
-       if (paths_list_view.get_text(row, 0) != _("user")) { return ; }
+       if (selection.size() == 0 ) { return ; }
 
        /* Gtk::ListViewText internals to delete row(s) */
        Gtk::TreeModel::iterator row_it = paths_list_view.get_selection()->get_selected();
@@ -143,3 +152,13 @@ PathsDialog::remove_path() {
                return;
        }
 }
+
+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) {
+               paths_list_view.append_text(*i);
+       }
+}