Added PathList widget to Gtkmm2ext. It is for adding and removing directory
authorTaybin Rutkin <taybin@taybin.com>
Wed, 26 Jul 2006 19:22:06 +0000 (19:22 +0000)
committerTaybin Rutkin <taybin@taybin.com>
Wed, 26 Jul 2006 19:22:06 +0000 (19:22 +0000)
paths to a list.  It'll be used for sfdb_paths and raid_paths in the OptionEditor.

git-svn-id: svn://localhost/ardour2/trunk@693 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/option_editor.cc
gtk2_ardour/option_editor.h
libs/gtkmm2ext/SConscript
libs/gtkmm2ext/gtkmm2ext/pathlist.h [new file with mode: 0644]
libs/gtkmm2ext/pathlist.cc [new file with mode: 0644]

index 09aacdab15968ed7a935485dea451f7d2ec60b78..fc4a412f9b303f21d48c6e45290472efb5a74748 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2001 Paul Davis 
+    Copyright (C) 2001-2006 Paul Davis 
 
     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
@@ -59,9 +59,7 @@ OptionEditor::OptionEditor (ARDOUR_UI& uip, PublicEditor& ed, Mixer_UI& mixui)
 
          /* Paths */
          path_table (11, 2),
-         sfdb_path_columns(),
-         sfdb_paths(ListStore::create(sfdb_path_columns)),
-         sfdb_path_view(sfdb_paths),
+         sfdb_path_view(),
 
          /* Fades */
 
@@ -251,10 +249,6 @@ OptionEditor::setup_path_options()
        path_table.attach(*label, 0, 1, 2, 3, FILL|EXPAND, FILL);
        path_table.attach(sfdb_path_view, 1, 3, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
 
-       sfdb_path_view.append_column(_("Paths"), sfdb_path_columns.paths);
-       sfdb_path_view.set_size_request(-1, 100);
-       sfdb_path_view.set_headers_visible (false);
-
        path_table.show_all();
 }
 
index b9690b02e2d07572fd862df7c84ecda4b5036c37..68407246e04f272ad25ac8538abf0e7eb7abd1c0 100644 (file)
@@ -33,6 +33,8 @@
 #include <gtkmm/radiobutton.h>
 #include <gtkmm/comboboxtext.h>
 
+#include <gtkmm2ext/pathlist.h>
+
 #include <ardour/session.h>
 
 #include "ardour_dialog.h"
@@ -70,19 +72,10 @@ class OptionEditor : public Gtk::Dialog
 
        /* paths */
 
-       Gtk::Table              path_table;
-       Gtk::Entry              session_raid_entry;
-
-       struct SoundFilePathColumns : public Gtk::TreeModel::ColumnRecord {
-           public:
-                 SoundFilePathColumns() { add (paths); }
-                 Gtk::TreeModelColumn<std::string> paths;
-                           
-       };
+       Gtk::Table      path_table;
+       Gtk::Entry      session_raid_entry;
 
-       SoundFilePathColumns sfdb_path_columns;
-       Glib::RefPtr<Gtk::ListStore> sfdb_paths;
-       Gtk::TreeView sfdb_path_view;
+       Gtkmm2ext::PathList sfdb_path_view;
 
        void setup_path_options();
        void add_session_paths ();
index bb289456417eca246ffc7bd74cd0ea5d35643699..cf513eb5a1b7a77b05e099a576af12cc549f12a2 100644 (file)
@@ -24,10 +24,10 @@ gtkmm2ext.Merge ([
 
 domain = 'libgtkmm2ext'
 
-gtkmm2ext.Append(DOMAIN=domain,MAJOR=0,MINOR=8,MICRO=2)
+gtkmm2ext.Append(DOMAIN=domain,MAJOR=0,MINOR=8,MICRO=3)
 gtkmm2ext.Append(CXXFLAGS="-DPACKAGE=\\\"" + domain + "\\\"")
 gtkmm2ext.Append(CXXFLAGS="-DLIBSIGC_DISABLE_DEPRECATED")
-gtkmm2ext.Append(CPPPATH='#libs/surfaces/control_protocol')
+#gtkmm2ext.Append(CPPPATH='#libs/surfaces/control_protocol')
 gtkmm2ext.Append(PACKAGE=domain)
 gtkmm2ext.Append(POTFILE=domain + '.pot')
 
@@ -42,6 +42,7 @@ fastmeter.cc
 gtk_ui.cc
 hexentry.cc
 idle_adjustment.cc
+pathlist.cc
 pixscroller.cc
 popup.cc
 prompter.cc
diff --git a/libs/gtkmm2ext/gtkmm2ext/pathlist.h b/libs/gtkmm2ext/gtkmm2ext/pathlist.h
new file mode 100644 (file)
index 0000000..7b86e01
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+    Copyright (C) 2006 Paul Davis 
+
+    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.
+
+*/
+
+#ifndef __gtkmm2ext_pathlist_h__
+#define __gtkmm2ext_pathlist_h__
+
+#include <vector>
+#include <string>
+
+#include <gtkmm.h>
+
+namespace Gtkmm2ext {
+
+class PathList : public Gtk::VBox
+{
+  public:
+       PathList ();
+       ~PathList () {};
+               
+       std::vector<std::string> get_paths ();
+       void set_paths (std::vector<std::string> paths);
+       
+       sigc::signal<void> paths_updated;
+       
+  protected:
+       Gtk::Button    add_btn;
+       Gtk::Button    subtract_btn;
+
+       void add_btn_clicked ();
+       void subtract_btn_clicked ();
+
+  private:
+       struct PathColumns : public Gtk::TreeModel::ColumnRecord {
+               PathColumns() { add (paths); }
+               Gtk::TreeModelColumn<std::string> paths;
+       };
+       PathColumns path_columns;
+       
+       Glib::RefPtr<Gtk::ListStore> _store;
+       Gtk::TreeView  _view;
+       
+       void selection_changed ();
+};
+
+} // namespace Gtkmm2ext
+
+#endif // __gtkmm2ext_pathlist_h__
diff --git a/libs/gtkmm2ext/pathlist.cc b/libs/gtkmm2ext/pathlist.cc
new file mode 100644 (file)
index 0000000..500cb8c
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+    Copyright (C) 2006 Paul Davis 
+
+    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 <gtkmm2ext/pathlist.h>
+
+#include "i18n.h"
+
+using namespace std;
+using namespace Gtkmm2ext;
+
+PathList::PathList ()
+       :
+       add_btn(_("+")),
+       subtract_btn(_("-")),
+       path_columns(),
+       _store(Gtk::ListStore::create(path_columns)),
+       _view(_store)
+{
+       _view.append_column(_("Paths"), path_columns.paths);
+       _view.set_size_request(-1, 100);
+       _view.set_headers_visible (false);
+       
+       Gtk::ScrolledWindow* scroll = manage(new Gtk::ScrolledWindow);
+       scroll->set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+       scroll->add(_view);
+       
+       add (*scroll);
+       
+       Gtk::HBox* btn_box = manage(new Gtk::HBox);
+       btn_box->add(add_btn);
+       btn_box->add(subtract_btn);
+
+       add (*btn_box);
+       
+       add_btn.signal_clicked().connect (mem_fun(*this, &PathList::add_btn_clicked));
+       subtract_btn.signal_clicked().connect (mem_fun(*this, &PathList::subtract_btn_clicked));
+       _view.get_selection()->signal_changed().connect (mem_fun(*this, &PathList::selection_changed));
+}
+
+vector<string>
+PathList::get_paths ()
+{
+       vector<string> paths;
+       
+       Gtk::TreeModel::Children children(_store->children());
+       
+       for (Gtk::TreeIter iter = children.begin(); iter != children.end(); ++iter) {
+               Gtk::ListStore::Row row = *iter;
+               
+               paths.push_back(row[path_columns.paths]);
+       }
+       
+       return paths;
+}
+
+void
+PathList::set_paths (vector<string> paths)
+{
+       _store.clear();
+       
+       for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i) {
+               Gtk::ListStore::iterator iter = _store->append();
+               Gtk::ListStore::Row row = *iter;
+               row[path_columns.paths] = *i;
+       }
+}
+
+void
+PathList::add_btn_clicked ()
+{
+       Gtk::FileChooserDialog path_chooser (_("Path Chooser"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
+       
+       path_chooser.add_button (Gtk::Stock::ADD, Gtk::RESPONSE_OK);
+       path_chooser.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+       
+       int result = path_chooser.run ();
+       
+       if (result == Gtk::RESPONSE_OK) {
+               string pathname = path_chooser.get_filename();
+               
+               if (pathname.length ()) {
+                       Gtk::ListStore::iterator iter = _store->append ();
+                       Gtk::ListStore::Row row = *iter;
+                       row[path_columns.paths] = pathname;
+                       
+                       paths_updated (); // EMIT_SIGNAL
+               }
+       }
+}
+
+void
+PathList::subtract_btn_clicked ()
+{
+       Gtk::ListStore::iterator iter = _view.get_selection()->get_selected();
+       _store->erase (iter);
+       
+       paths_updated (); // EMIT_SIGNAL
+}
+
+void
+PathList::selection_changed ()
+{
+       if (_view.get_selection()->count_selected_rows ()) {
+               subtract_btn.set_sensitive (true);
+       } else {
+               subtract_btn.set_sensitive (false);
+       }
+}