correct check for presence of / or \ in a session name
[ardour.git] / gtk2_ardour / editor_region_list.cc
index f9e4b5bcb15a6b33f52d754974e50a0459db9538..0e14391895fd78c3b8add627634b36095cb13366 100644 (file)
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #include <cstdlib>
 #include <cmath>
 #include <algorithm>
 #include <string>
+#include <sstream>
 
 #include <pbd/basename.h>
 
 #include <ardour/audioregion.h>
+#include <ardour/audiofilesource.h>
+#include <ardour/silentfilesource.h>
 #include <ardour/session_region.h>
+#include <ardour/profile.h>
 
 #include <gtkmm2ext/stop_signal.h>
 
 #include "editor.h"
 #include "editing.h"
+#include "keyboard.h"
 #include "ardour_ui.h"
 #include "gui_thread.h"
 #include "actions.h"
+#include "region_view.h"
+#include "utils.h"
 
 #include "i18n.h"
 
 using namespace sigc;
 using namespace ARDOUR;
+using namespace PBD;
 using namespace Gtk;
+using namespace Glib;
 using namespace Editing;
-using namespace ActionManager;
-
-#define wave_cursor_width 43
-#define wave_cursor_height 61
-#define wave_cursor_x_hot 0
-#define wave_cursor_y_hot 25
-static const gchar wave_cursor_bits[] = {
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff,
-0x03,
-   0x02, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,
-0x02,
-   0x02, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,
-0x02,
-   0x02, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,
-0x02,
-   0x02, 0x04, 0x00, 0x00, 0x00, 0x02, 0x02, 0x04, 0x00, 0x04, 0x00,
-0x02,
-   0x02, 0x04, 0x00, 0x04, 0x00, 0x02, 0x02, 0x0c, 0x08, 0x0c, 0x00,
-0x02,
-   0x02, 0x1c, 0x08, 0x0c, 0x00, 0x02, 0x02, 0x1c, 0x08, 0x0c, 0x04,
-0x02,
-   0x02, 0x3c, 0x18, 0x0c, 0x04, 0x02, 0x02, 0x7c, 0x18, 0x1c, 0x0c,
-0x02,
-   0x82, 0xfc, 0x38, 0x1c, 0x0c, 0x02, 0xc2, 0xfc, 0x78, 0x3c, 0x1c,
-0x02,
-   0xe2, 0xfd, 0xf9, 0x7d, 0x1c, 0x02, 0xf2, 0xff, 0xfb, 0xff, 0x1c,
-0x02,
-   0xfa, 0xff, 0xfb, 0xff, 0x3f, 0x02, 0xfe, 0xff, 0xff, 0xff, 0xff,
-0x03,
-   0xfe, 0xff, 0xff, 0xff, 0xff, 0x03, 0xfa, 0xff, 0xff, 0xff, 0x3f,
-0x02,
-   0xf2, 0xff, 0xfb, 0xfd, 0x3c, 0x02, 0xe2, 0xfd, 0x7b, 0x7c, 0x1c,
-0x02,
-   0xc2, 0xfc, 0x39, 0x3c, 0x1c, 0x02, 0x82, 0xfc, 0x18, 0x1c, 0x1c,
-0x02,
-   0x02, 0xfc, 0x18, 0x1c, 0x0c, 0x02, 0x02, 0x7c, 0x18, 0x0c, 0x0c,
-0x02,
-   0x02, 0x3c, 0x08, 0x0c, 0x04, 0x02, 0x02, 0x1c, 0x08, 0x0c, 0x04,
-0x02,
-   0x02, 0x1c, 0x08, 0x0c, 0x00, 0x02, 0x02, 0x0c, 0x00, 0x04, 0x00,
-0x02,
-   0x02, 0x04, 0x00, 0x04, 0x00, 0x02, 0x02, 0x04, 0x00, 0x00, 0x00,
-0x02,
-   0x02, 0x04, 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,
-0x02,
-   0x02, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,
-0x02,
-   0x02, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,
-0x02,
-   0x02, 0x00, 0x00, 0x00, 0x00, 0x02, 0xfe, 0xff, 0xff, 0xff, 0xff,
-0x03,
-   0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-
-#define wave_cursor_mask_width 43
-#define wave_cursor_mask_height 61
-#define wave_cursor_mask_x_hot 0
-#define wave_cursor_mask_y_hot 25
-static const gchar wave_cursor_mask_bits[] = {
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00,
-0x00,
-   0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0c, 0x08, 0x0c, 0x00,
-0x00,
-   0x00, 0x1c, 0x08, 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x08, 0x0c, 0x04,
-0x00,
-   0x00, 0x3c, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x7c, 0x18, 0x1c, 0x0c,
-0x00,
-   0x80, 0xfc, 0x38, 0x1c, 0x0c, 0x00, 0xc0, 0xfc, 0x78, 0x3c, 0x1c,
-0x00,
-   0xe0, 0xfd, 0xf9, 0x7d, 0x1c, 0x00, 0xf0, 0xff, 0xfb, 0xff, 0x1c,
-0x00,
-   0xf8, 0xff, 0xfb, 0xff, 0x3f, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
-0x07,
-   0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xf8, 0xff, 0xff, 0xff, 0x3f,
-0x00,
-   0xf0, 0xff, 0xfb, 0xfd, 0x3c, 0x00, 0xe0, 0xfd, 0x7b, 0x7c, 0x1c,
-0x00,
-   0xc0, 0xfc, 0x39, 0x3c, 0x1c, 0x00, 0x80, 0xfc, 0x18, 0x1c, 0x1c,
-0x00,
-   0x00, 0xfc, 0x18, 0x1c, 0x0c, 0x00, 0x00, 0x7c, 0x18, 0x0c, 0x0c,
-0x00,
-   0x00, 0x3c, 0x08, 0x0c, 0x04, 0x00, 0x00, 0x1c, 0x08, 0x0c, 0x04,
-0x00,
-   0x00, 0x1c, 0x08, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x04, 0x00,
-0x00,
-   0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00,
-   0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-
-GdkCursor *wave_cursor = 0;
 
 void
-Editor::handle_audio_region_removed (AudioRegion* ignored)
+Editor::handle_audio_region_removed (boost::weak_ptr<AudioRegion> wregion)
 {
+       ENSURE_GUI_THREAD (mem_fun (*this, &Editor::redisplay_regions));
        redisplay_regions ();
 }
 
 void
-Editor::handle_new_audio_region (AudioRegion *region)
+Editor::handle_new_audio_regions (vector<boost::weak_ptr<AudioRegion> >& v)
 {
-       /* don't copy region - the one we are being notified
-          about belongs to the session, and so it will
-          never be edited.
-       */
-       add_audio_region_to_region_display (region);
+       ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::handle_new_audio_regions), v));
+       add_audio_regions_to_region_display (v);
 }
 
 void
-Editor::region_hidden (Region* r)
+Editor::region_hidden (boost::shared_ptr<Region> r)
 {
        ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::region_hidden), r));    
 
@@ -205,10 +74,27 @@ Editor::region_hidden (Region* r)
 }
 
 void
-Editor::add_audio_region_to_region_display (AudioRegion *region)
+Editor::add_audio_regions_to_region_display (vector<boost::weak_ptr<AudioRegion> >& regions)
+{
+       region_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
+       for (vector<boost::weak_ptr<AudioRegion> >::iterator x = regions.begin(); x != regions.end(); ++x) {
+               boost::shared_ptr<AudioRegion> region ((*x).lock());
+               if (region) {
+                       add_audio_region_to_region_display (region);
+               }
+       }
+       region_list_display.set_model (region_list_model);
+}
+
+void
+Editor::add_audio_region_to_region_display (boost::shared_ptr<AudioRegion> region)
 {
        string str;
        TreeModel::Row row;
+       Gdk::Color c;
+       bool missing_source;
+
+       missing_source = boost::dynamic_pointer_cast<SilentFileSource>(region->source());
 
        if (!show_automatic_regions_in_region_list && region->automatic()) {
                return;
@@ -216,34 +102,60 @@ Editor::add_audio_region_to_region_display (AudioRegion *region)
 
        if (region->hidden()) {
 
-               TreeModel::iterator iter = region_list_model->get_iter (_("/Hidden"));
+               TreeModel::iterator iter = region_list_model->get_iter ("0");
                TreeModel::Row parent;
                TreeModel::Row child;
 
-               if (iter == region_list_model->children().end()) {
-                       
+               if (!iter) {
+
                        parent = *(region_list_model->append());
                        
                        parent[region_list_columns.name] = _("Hidden");
-                       parent[region_list_columns.region] = 0;
+
                } else {
-                       parent = *iter;
+
+                       if ((*iter)[region_list_columns.name] != _("Hidden")) {
+
+                               parent = *(region_list_model->insert(iter));
+                               parent[region_list_columns.name] = _("Hidden");
+
+                       } else {
+
+                               parent = *iter;
+                       }
                }
 
                row = *(region_list_model->append (parent.children()));
 
        } else if (region->whole_file()) {
 
-               TreeModel::Row row = *(region_list_model->append());
-
-               if (region->source().name()[0] == '/') { // external file
+               TreeModel::iterator i;
+               TreeModel::Children rows = region_list_model->children();
 
-                       if (region->whole_file()) {
-                               str = ".../";
-                               str += PBD::basename_nosuffix (region->source().name());
-                       } else {
-                               str = region->name();
+               for (i = rows.begin(); i != rows.end(); ++i) {
+                       
+                       boost::shared_ptr<Region> rr = (*i)[region_list_columns.region];
+                       
+                       if (rr && region->region_list_equivalent (rr)) {
+                               return;
                        }
+               }
+
+               row = *(region_list_model->append());
+               if (missing_source) {
+                       c.set_rgb(65535,0,0);     // FIXME: error color from style
+               } else {
+                       set_color(c, rgba_from_style ("RegionListWholeFile", 0xff, 0, 0, 0, "fg", Gtk::STATE_NORMAL, false ));
+               }
+               row[region_list_columns.color_] = c;
+
+               if (region->source()->name()[0] == '/') { // external file
+
+                       /* XXX there was old code here to try to show an abbreviated version
+                          of the path name for whole file regions.
+                       */
+
+                       str = region->name();
 
                } else {
 
@@ -251,6 +163,18 @@ Editor::add_audio_region_to_region_display (AudioRegion *region)
 
                }
 
+               if (region->n_channels() > 1) {
+                       std::stringstream foo;
+                       foo << region->n_channels ();
+                       str += " [";
+                       str += foo.str();
+                       str += ']';
+               }
+
+               if (missing_source) {
+                       str += _(" (MISSING)");
+               }
+
                row[region_list_columns.name] = str;
                row[region_list_columns.region] = region;
 
@@ -262,23 +186,36 @@ Editor::add_audio_region_to_region_display (AudioRegion *region)
                
                TreeModel::iterator i;
                TreeModel::Children rows = region_list_model->children();
+               bool found_parent = false;
 
                for (i = rows.begin(); i != rows.end(); ++i) {
 
-                       Region* rr = (*i)[region_list_columns.region];
-                       AudioRegion* r = dynamic_cast<AudioRegion*>(rr);
+                       boost::shared_ptr<Region> rr = (*i)[region_list_columns.region];
+                       boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion>(rr);
 
                        if (r && r->whole_file()) {
-                               
-                               if (region->source_equivalent (*r)) {
+                               if (region->source_equivalent (r)) {
                                        row = *(region_list_model->append ((*i).children()));
+                                       found_parent = true;
                                        break;
                                }
                        }
+
+                       TreeModel::iterator ii;
+                       TreeModel::Children subrows = (*i).children();
+
+                       for (ii = subrows.begin(); ii != subrows.end(); ++ii) {
+                               
+                               boost::shared_ptr<Region> rrr = (*ii)[region_list_columns.region];
+
+                               if (region->region_list_equivalent (rrr)) {
+                                       return;
+                               }
+                       }
                }
 
-               if (i == rows.end()) {
-                       TreeModel::Row row = *(region_list_model->append());
+               if (!found_parent) {
+                       row = *(region_list_model->append());
                }
 
                
@@ -296,25 +233,38 @@ Editor::add_audio_region_to_region_display (AudioRegion *region)
 void
 Editor::region_list_selection_changed() 
 {
-       bool sensitive;
+       bool selected;
 
        if (region_list_display.get_selection()->count_selected_rows() > 0) {
-               sensitive = true;
+               selected = true;
        } else {
-               sensitive = false;
+               selected = false;
        }
        
-       for (vector<Glib::RefPtr<Gtk::Action> >::iterator i = region_list_selection_sensitive_actions.begin(); i != region_list_selection_sensitive_actions.end(); ++i) {
-               (*i)->set_sensitive (sensitive);
-       }
-
-       // GTK2FIX
-       // set_selected_regionview_from_region_list (*region, false);
+       if (selected) {
+               TreeView::Selection::ListHandle_Path rows = region_list_display.get_selection()->get_selected_rows ();
+               TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
+               TreeIter iter;
 
+               if ((iter = region_list_model->get_iter (*i))) {
+                       boost::shared_ptr<Region> r = (*iter)[region_list_columns.region];
+                       
+                       /* they could have clicked on a row that is just a placeholder, like "Hidden" */
+                       
+                       if (r) {
+                               
+                               /* just set the first selected region (in fact, the selection model might be SINGLE, which
+                                  means there can only be one.
+                               */
+                               
+                               set_selected_regionview_from_region_list (r, Selection::Set);
+                       }
+               }
+       }
 }
 
 void
-Editor::insert_into_tmp_audio_regionlist(AudioRegion* region)
+Editor::insert_into_tmp_audio_regionlist(boost::shared_ptr<AudioRegion> region)
 {
        /* keep all whole files at the beginning */
        
@@ -328,10 +278,14 @@ Editor::insert_into_tmp_audio_regionlist(AudioRegion* region)
 void
 Editor::redisplay_regions ()
 {
-       if (session) {
+       if (no_region_list_redisplay) {
+               return;
+       }
                
+       if (session) {
+
                region_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
-               region_list_model.clear ();
+               region_list_model->clear ();
 
                /* now add everything we have, via a temporary list used to help with
                   sorting.
@@ -340,55 +294,68 @@ Editor::redisplay_regions ()
                tmp_audio_region_list.clear();
                session->foreach_audio_region (this, &Editor::insert_into_tmp_audio_regionlist);
 
-               for (list<AudioRegion*>::iterator r = tmp_audio_region_list.begin(); r != tmp_audio_region_list.end(); ++r) {
+               for (list<boost::shared_ptr<AudioRegion> >::iterator r = tmp_audio_region_list.begin(); r != tmp_audio_region_list.end(); ++r) {
                        add_audio_region_to_region_display (*r);
                }
+               tmp_audio_region_list.clear();
                
-               region_list_display.set_model (region_list_sort_model);
+               region_list_display.set_model (region_list_model);
        }
 }
 
-void
-Editor::region_list_clear ()
-{
-       region_list_model->clear();
-}
-
 void
 Editor::build_region_list_menu ()
 {
-       region_list_menu = dynamic_cast<Menu*>(ui_manager->get_widget ("/RegionListMenu"));
+       region_list_menu = dynamic_cast<Menu*>(ActionManager::get_widget ("/RegionListMenu"));
                                               
        /* now grab specific menu items that we need */
 
-       toggle_full_region_list_action = ui_manager->get_action ("<Actions>/RegionList/rlShowAll");
-       
-       region_list_selection_sensitive_actions.push_back (ui_manager->get_action ("<Actions>/RegionList/rlHide"));
-       region_list_selection_sensitive_actions.push_back (ui_manager->get_action ("<Actions>/RegionList/rlAudition"));
-       region_list_selection_sensitive_actions.push_back (ui_manager->get_action ("<Actions>/RegionList/rlRemove"));
+       Glib::RefPtr<Action> act;
+
+       act = ActionManager::get_action (X_("RegionList"), X_("rlShowAll"));
+       if (act) {
+               toggle_full_region_list_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
+       }
 
-       session_sensitive_actions.push_back (ui_manager->get_action ("<Actions>/RegionList/rlEmbedAudio"));
-       session_sensitive_actions.push_back (ui_manager->get_action ("<Actions>/RegionList/rlImportAudio"));
+       act = ActionManager::get_action (X_("RegionList"), X_("rlShowAuto"));
+       if (act) {
+               toggle_show_auto_regions_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
+       }
 }
 
 void
 Editor::toggle_show_auto_regions ()
 {
-       //show_automatic_regions_in_region_list = toggle_auto_regions_item->get_active();
-       show_automatic_regions_in_region_list = true;
+       show_automatic_regions_in_region_list = toggle_show_auto_regions_action->get_active();
        redisplay_regions ();
 }
 
 void
 Editor::toggle_full_region_list ()
 {
-       if (toggle_full_region_list_item->get_active()) {
+       if (toggle_full_region_list_action->get_active()) {
                region_list_display.expand_all ();
        } else {
                region_list_display.collapse_all ();
        }
 }
 
+void
+Editor::show_region_list_display_context_menu (int button, int time)
+{
+       if (region_list_menu == 0) {
+               build_region_list_menu ();
+       }
+
+       if (region_list_display.get_selection()->count_selected_rows() > 0) {
+               ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions, true);
+       } else {
+               ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions, false);
+       }
+
+       region_list_menu->popup (button, time);
+}
+
 bool
 Editor::region_list_display_key_press (GdkEventKey* ev)
 {
@@ -413,7 +380,7 @@ Editor::region_list_display_key_release (GdkEventKey* ev)
 bool
 Editor::region_list_display_button_press (GdkEventButton *ev)
 {
-       Region* region;
+       boost::shared_ptr<Region> region;
        TreeIter iter;
        TreeModel::Path path;
        TreeViewColumn* column;
@@ -426,42 +393,17 @@ Editor::region_list_display_button_press (GdkEventButton *ev)
                }
        }
 
-       if (region == 0) {
-               return false;
-       }
-
-       if (Keyboard::is_delete_event (ev)) {
-               session->remove_region_from_region_list (*region);
-               return true;
-       }
-
        if (Keyboard::is_context_menu_event (ev)) {
-               if (region_list_menu == 0) {
-                       build_region_list_menu ();
-               }
-               region_list_menu->popup (ev->button, ev->time);
+               show_region_list_display_context_menu (ev->button, ev->time);
                return true;
        }
 
-       switch (ev->button) {
-       case 1:
-               /* audition on double click */
-               if (ev->type == GDK_2BUTTON_PRESS) {
-                       consider_auditioning (*region);
-                       return true;
-               }
-               return false;
-               break;
-
-       case 2:
-               if (!Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
-                       consider_auditioning (*region);
+       if (region != 0 && Keyboard::is_button2_event (ev)) {
+               // start/stop audition 
+               if (!Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
+                       consider_auditioning (region);
                }
                return true;
-               break;
-
-       default:
-               break; 
        }
 
        return false;
@@ -475,7 +417,7 @@ Editor::region_list_display_button_release (GdkEventButton *ev)
        TreeViewColumn* column;
        int cellx;
        int celly;
-       Region* region;
+       boost::shared_ptr<Region> region;
 
        if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
                if ((iter = region_list_model->get_iter (path))) {
@@ -483,31 +425,18 @@ Editor::region_list_display_button_release (GdkEventButton *ev)
                }
        }
 
-       if (Keyboard::is_delete_event (ev)) {
-               session->remove_region_from_region_list (*region);
+       if (region && Keyboard::is_delete_event (ev)) {
+               session->remove_region_from_region_list (region);
                return true;
        }
 
-       switch (ev->button) {
-       case 1:
-               return false;
-               break;
-
-       case 3:
-               return false;
-               break;
-
-       default:
-               break;
-       }
-
        return false;
 }
 
 void
-Editor::consider_auditioning (Region& region)
+Editor::consider_auditioning (boost::shared_ptr<Region> region)
 {
-       AudioRegion* r = dynamic_cast<AudioRegion*> (&region);
+       boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion> (region);
 
        if (r == 0) {
                session->cancel_audition ();
@@ -519,22 +448,32 @@ Editor::consider_auditioning (Region& region)
                if (r == last_audition_region) {
                        return;
                }
-       }
+       } 
 
-       session->audition_region (*r);
+       session->audition_region (r);
        last_audition_region = r;
 }
 
 int
 Editor::region_list_sorter (TreeModel::iterator a, TreeModel::iterator b)
 {
-       int cmp;
+       int cmp = 0;
+
+       boost::shared_ptr<Region> r1 = (*a)[region_list_columns.region];
+       boost::shared_ptr<Region> r2 = (*b)[region_list_columns.region];
+
+       /* handle rows without regions, like "Hidden" */
+
+       if (r1 == 0) {
+               return -1;
+       }
 
-       Region* r1 = (*a)[region_list_columns.region];
-       Region* r2 = (*b)[region_list_columns.region];
+       if (r2 == 0) {
+               return 1;
+       }
 
-       AudioRegion* region1 = dynamic_cast<AudioRegion*> (r1);
-       AudioRegion* region2 = dynamic_cast<AudioRegion*> (r2);
+       boost::shared_ptr<AudioRegion> region1 = boost::dynamic_pointer_cast<AudioRegion> (r1);
+       boost::shared_ptr<AudioRegion> region2 = boost::dynamic_pointer_cast<AudioRegion> (r2);
 
        if (region1 == 0 || region2 == 0) {
                Glib::ustring s1;
@@ -563,7 +502,7 @@ Editor::region_list_sorter (TreeModel::iterator a, TreeModel::iterator b)
                break;
                
        case ByTimestamp:
-               cmp = region1->source().timestamp() - region2->source().timestamp();
+               cmp = region1->source()->timestamp() - region2->source()->timestamp();
                break;
        
        case ByStartInFile:
@@ -575,22 +514,22 @@ Editor::region_list_sorter (TreeModel::iterator a, TreeModel::iterator b)
                break;
                
        case BySourceFileName:
-               cmp = strcasecmp (region1->source().name().c_str(), region2->source().name().c_str());
+               cmp = strcasecmp (region1->source()->name().c_str(), region2->source()->name().c_str());
                break;
 
        case BySourceFileLength:
-               cmp = region1->source().length() - region2->source().length();
+               cmp = region1->source()->length() - region2->source()->length();
                break;
                
        case BySourceFileCreationDate:
-               cmp = region1->source().timestamp() - region2->source().timestamp();
+               cmp = region1->source()->timestamp() - region2->source()->timestamp();
                break;
 
        case BySourceFileFS:
-               if (region1->source().name() == region2->source().name()) {
+               if (region1->source()->name() == region2->source()->name()) {
                        cmp = strcasecmp (region1->name().c_str(),  region2->name().c_str());
                } else {
-                       cmp = strcasecmp (region1->source().name().c_str(),  region2->source().name().c_str());
+                       cmp = strcasecmp (region1->source()->name().c_str(),  region2->source()->name().c_str());
                }
                break;
        }
@@ -609,64 +548,18 @@ Editor::reset_region_list_sort_type (RegionListSortType type)
 {
        if (type != region_list_sort_type) {
                region_list_sort_type = type;
-
-               switch (type) {
-               case ByName:
-                       region_list_display.get_column (0)->set_title (_("Regions/name"));
-                       break;
-                       
-               case ByLength:
-                       region_list_display.get_column (0)->set_title (_("Regions/length"));
-                       break;
-                       
-               case ByPosition:
-                       region_list_display.get_column (0)->set_title (_("Regions/position"));
-                       break;
-                       
-               case ByTimestamp:
-                       region_list_display.get_column (0)->set_title (_("Regions/creation"));
-                       break;
-                       
-               case ByStartInFile:
-                       region_list_display.get_column (0)->set_title (_("Regions/start"));
-                       break;
-                       
-               case ByEndInFile:
-                       region_list_display.get_column (0)->set_title (_("Regions/end"));
-                       break;
-                       
-               case BySourceFileName:
-                       region_list_display.get_column (0)->set_title (_("Regions/file name"));
-                       break;
-                       
-               case BySourceFileLength:
-                       region_list_display.get_column (0)->set_title (_("Regions/file size"));
-                       break;
-                       
-               case BySourceFileCreationDate:
-                       region_list_display.get_column (0)->set_title (_("Regions/file date"));
-                       break;
-                       
-               case BySourceFileFS:
-                       region_list_display.get_column (0)->set_title (_("Regions/file system"));
-                       break;
-               }
-                       
-               region_list_sort_model->set_sort_func (0, mem_fun (*this, &Editor::region_list_sorter));
+               region_list_model->set_sort_func (0, (mem_fun (*this, &Editor::region_list_sorter)));
        }
 }
 
 void
 Editor::reset_region_list_sort_direction (bool up)
 {
-       // GTK2FIX
-       //region_list_display.set_sort_type (up ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING);
-       /* reset to force resort */
-       region_list_sort_model->set_sort_func (0, mem_fun (*this, &Editor::region_list_sorter));
+       region_list_model->set_sort_column (0, up ? SORT_ASCENDING : SORT_DESCENDING);
 }
 
 void
-Editor::region_list_selection_mapover (slot<void,Region&> sl)
+Editor::region_list_selection_mapover (slot<void,boost::shared_ptr<Region> > sl)
 {
        Glib::RefPtr<TreeSelection> selection = region_list_display.get_selection();
        TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
@@ -680,19 +573,28 @@ Editor::region_list_selection_mapover (slot<void,Region&> sl)
                TreeIter iter;
 
                if ((iter = region_list_model->get_iter (*i))) {
-                       sl (*((*iter)[region_list_columns.region]));
+
+                       /* some rows don't have a region associated with them, but can still be
+                          selected (XXX maybe prevent them from being selected)
+                       */
+
+                       boost::shared_ptr<Region> r = (*iter)[region_list_columns.region];
+
+                       if (r) {
+                               sl (r);
+                       }
                }
        }
 }
 
 void
-Editor::hide_a_region (Region& r)
+Editor::hide_a_region (boost::shared_ptr<Region> r)
 {
-       r.set_hidden (true);
+       r->set_hidden (true);
 }
 
 void
-Editor::remove_a_region (Region& r)
+Editor::remove_a_region (boost::shared_ptr<Region> r)
 {
        session->remove_region_from_region_list (r);
 }
@@ -716,18 +618,69 @@ Editor::remove_region_from_region_list ()
 }
 
 void  
-Editor::region_list_display_drag_data_received  (GdkDragContext     *context,
-                                                gint                x,
-                                                gint                y,
-                                                GtkSelectionData   *data,
-                                                guint               info,
-                                                guint               time)
+Editor::region_list_display_drag_data_received (const RefPtr<Gdk::DragContext>& context,
+                                               int x, int y, 
+                                               const SelectionData& data,
+                                               guint info, guint time)
 {
-       vector<string> paths;
+       vector<ustring> paths;
+
+       if (data.get_target() == "GTK_TREE_MODEL_ROW") {
+               region_list_display.on_drag_data_received (context, x, y, data, info, time);
+               return;
+       }
 
        if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
-               do_embed_sndfiles (paths, false);
+               nframes64_t pos = 0;
+               if (Profile->get_sae() || Config->get_only_copy_imported_files()) {
+                       do_import (paths, Editing::ImportDistinctFiles, Editing::ImportAsRegion, SrcBest, pos); 
+               } else {
+                       do_embed (paths, Editing::ImportDistinctFiles, ImportAsRegion, pos);
+               }
+               context->drag_finish (true, false, time);
+       }
+}
+
+bool
+Editor::region_list_selection_filter (const RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
+{
+       /* not possible to select rows that do not represent regions, like "Hidden" */
+       
+       TreeModel::iterator iter = model->get_iter (path);
+
+       if (iter) {
+               boost::shared_ptr<Region> r =(*iter)[region_list_columns.region];
+               if (!r) {
+                       return false;
+               }
+       } 
+
+       return true;
+}
+
+void
+Editor::region_name_edit (const Glib::ustring& path, const Glib::ustring& new_text)
+{
+       boost::shared_ptr<Region> region;
+       TreeIter iter;
+       
+       if ((iter = region_list_model->get_iter (path))) {
+               region = (*iter)[region_list_columns.region];
+               (*iter)[region_list_columns.name] = new_text;
+       }
+       
+       /* now mapover everything */
+
+       if (region) {
+               vector<RegionView*> equivalents;
+               get_regions_corresponding_to (region, equivalents);
+
+               for (vector<RegionView*>::iterator i = equivalents.begin(); i != equivalents.end(); ++i) {
+                       if (new_text != (*i)->region()->name()) {
+                               (*i)->region()->set_name (new_text);
+                       }
+               }
        }
 
-       gtk_drag_finish (context, TRUE, FALSE, time);
 }
+