try to sensibly handle repeated imports of the same file. the same thing might be...
[ardour.git] / gtk2_ardour / editor_audio_import.cc
index cd3c76a4ad85b7e2e4d9af7bc70eea3bd8f5f666..852958b79846a917ef595e19c5e9d3879a85ba49 100644 (file)
@@ -359,6 +359,7 @@ Editor::do_import (vector<string> paths, ImportDisposition chns, ImportMode mode
                if (cancel) {
                        ok = false;
                } else {
+                        ipw.show ();
                        ok = (import_sndfiles (paths, mode, quality, pos, 1, 1, track, false) == 0);
                }
 
@@ -392,6 +393,8 @@ Editor::do_import (vector<string> paths, ImportDisposition chns, ImportMode mode
                                 pos = -1;
                         }
 
+                        ipw.show ();
+                                
                         switch (chns) {
                         case Editing::ImportDistinctFiles:
                                 
@@ -505,6 +508,41 @@ int
 Editor::import_sndfiles (vector<string> paths, ImportMode mode, SrcQuality quality, framepos_t& pos,
                         int target_regions, int target_tracks, boost::shared_ptr<Track>& track, bool replace)
 {
+        /* check for existing wholefile regions of the same name,
+           which can happen when we import foo.wav but end up with foo-L.wav 
+           and foo-R.wav inside the session. this case doesn't trigger
+           source name collisions, so we have to catch it at the region
+           name level.
+        */
+        
+        string region_name = region_name_from_path (paths.front(), true, false);
+        
+        if (RegionFactory::wholefile_region_by_name (region_name)) {
+                string message = string_compose ( _("You appear to have already imported this file, since a region called %1 already exists.\nDo you really want to import it again?"),
+                                                  region_name);
+                MessageDialog dialog (message, false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_OK_CANCEL, true);
+                int ret;
+                
+                dialog.show ();
+                ret = dialog.run ();
+                dialog.hide ();
+                
+                if (ret != RESPONSE_OK) {
+                        return -1;
+                }
+                
+                int l = 0;
+                
+                while (RegionFactory::region_by_name (region_name) && ++l < 999) {
+                        region_name = bump_name_once (region_name, '.');
+                }
+                
+                if (l == 999) {
+                        error << string_compose (_("Too many regions already named something like \"%1\""), paths.front()) << endmsg;
+                        return -1;
+                }
+        }
+
        import_status.paths = paths;
        import_status.done = false;
        import_status.cancel = false;
@@ -749,6 +787,12 @@ Editor::add_sources (vector<string> paths, SourceList& sources, framepos_t& pos,
 
                region_name = region_name_from_path (paths.front(), (sources.size() > 1), false);
 
+                /* we checked in import_sndfiles() that there were not too many */
+
+                while (RegionFactory::region_by_name (region_name)) {
+                        region_name = bump_name_once (region_name, '.');
+                }
+
                PropertyList plist; 
                
                plist.add (ARDOUR::Properties::start, 0);
@@ -929,7 +973,7 @@ Editor::finish_bringing_in_material (boost::shared_ptr<Region> region, uint32_t
 
                                existing_track = mt.front();
                        }
-
+                        
                        existing_track->set_name (region->name());
                }