+ int function = 1;
+
+ if (already_exists) {
+ string message;
+ if (all_or_nothing) {
+ // updating is still disabled
+ //message = string_compose(_("The session already contains a source file named %1. Do you want to update that file (and thus all regions using the file) or import this file as a new file?"),wave_name);
+ message = string_compose (_("The session already contains a source file named %1. Do you want to import %1 as a new file, or skip it?"), wave_name);
+ } else {
+ message = string_compose (_("The session already contains a source file named %1. Do you want to import %2 as a new source, or skip it?"), wave_name, wave_name);
+
+ }
+ MessageDialog dialog(message, false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE, true);
+
+ if (all_or_nothing) {
+ // disabled
+ //dialog.add_button("Update", 0);
+ dialog.add_button("Import", 1);
+ dialog.add_button("Skip", 2);
+ } else {
+ dialog.add_button("Import", 1);
+ dialog.add_button("Cancel", 2);
+ }
+
+ //dialog.add_button("Skip all", 4); // All or rest?
+
+ dialog.show();
+
+ function = dialog.run ();
+
+ dialog.hide();
+ }
+
+ return function;
+}
+
+boost::shared_ptr<AudioTrack>
+Editor::get_nth_selected_audio_track (int nth) const
+{
+ AudioTimeAxisView* atv;
+ TrackSelection::iterator x;
+
+ for (x = selection->tracks.begin(); nth > 0 && x != selection->tracks.end(); ++x) {
+
+ atv = dynamic_cast<AudioTimeAxisView*>(*x);
+
+ if (!atv) {
+ continue;
+ } else if (atv->is_audio_track()) {
+ --nth;
+ }
+ }
+
+ if (x == selection->tracks.end()) {
+ atv = dynamic_cast<AudioTimeAxisView*>(selection->tracks.back());
+ } else {
+ atv = dynamic_cast<AudioTimeAxisView*>(*x);
+ }
+
+ if (!atv || !atv->is_audio_track()) {
+ return boost::shared_ptr<AudioTrack>();
+ }
+
+ return atv->audio_track();
+}
+
+boost::shared_ptr<MidiTrack>
+Editor::get_nth_selected_midi_track (int nth) const
+{
+ MidiTimeAxisView* mtv;
+ TrackSelection::iterator x;
+
+ for (x = selection->tracks.begin(); nth > 0 && x != selection->tracks.end(); ++x) {
+
+ mtv = dynamic_cast<MidiTimeAxisView*>(*x);
+
+ if (!mtv) {
+ continue;
+ } else if (mtv->is_midi_track()) {
+ --nth;
+ }
+ }
+
+ if (x == selection->tracks.end()) {
+ mtv = dynamic_cast<MidiTimeAxisView*>(selection->tracks.back());
+ } else {
+ mtv = dynamic_cast<MidiTimeAxisView*>(*x);
+ }
+
+ if (!mtv || !mtv->is_midi_track()) {
+ return boost::shared_ptr<MidiTrack>();
+ }
+
+ return mtv->midi_track();
+}
+
+void
+Editor::do_import (vector<string> paths,
+ ImportDisposition disposition,
+ ImportMode mode,
+ SrcQuality quality,
+ framepos_t& pos,
+ ARDOUR::PluginInfoPtr instrument)
+{
+ boost::shared_ptr<Track> track;
+ vector<string> to_import;
+ int nth = 0;
+ bool use_timestamp = (pos == -1);
+
+ current_interthread_info = &import_status;
+ import_status.current = 1;
+ import_status.total = paths.size ();
+ import_status.all_done = false;
+
+ ImportProgressWindow ipw (&import_status, _("Import"), _("Cancel Import"));
+
+ bool ok = true;
+
+ if (disposition == Editing::ImportMergeFiles) {
+
+ /* create 1 region from all paths, add to 1 track,
+ ignore "track"
+ */
+
+ bool cancel = false;
+ for (vector<string>::iterator a = paths.begin(); a != paths.end(); ++a) {
+ int check = check_whether_and_how_to_import(*a, false);
+ if (check == 2) {
+ cancel = true;
+ break;
+ }
+ }
+
+ if (cancel) {
+ ok = false;
+ } else {
+ ipw.show ();
+ ok = (import_sndfiles (paths, disposition, mode, quality, pos, 1, 1, track, false, instrument) == 0);
+ }
+
+ } else {
+
+ bool replace = false;
+
+ for (vector<string>::iterator a = paths.begin(); a != paths.end(); ++a) {
+
+ const int check = check_whether_and_how_to_import (*a, true);
+
+ switch (check) {
+ case 2:
+ // user said skip
+ continue;
+ case 0:
+ fatal << "Updating existing sources should be disabled!" << endmsg;
+ abort(); /* NOTREACHED*/
+ break;
+ case 1:
+ replace = false;
+ break;
+ default:
+ fatal << "Illegal return " << check << " from check_whether_and_how_to_import()!" << endmsg;
+ abort(); /* NOTREACHED*/
+ }
+
+ /* have to reset this for every file we handle */
+
+ if (use_timestamp) {
+ pos = -1;
+ }
+
+ ipw.show ();
+
+ switch (disposition) {
+ case Editing::ImportDistinctFiles:
+
+ to_import.clear ();
+ to_import.push_back (*a);
+
+ if (mode == Editing::ImportToTrack) {
+ track = get_nth_selected_audio_track (nth++);
+ }
+
+ ok = (import_sndfiles (to_import, disposition, mode, quality, pos, 1, -1, track, replace, instrument) == 0);
+ break;
+
+ case Editing::ImportDistinctChannels:
+
+ to_import.clear ();
+ to_import.push_back (*a);
+
+ ok = (import_sndfiles (to_import, disposition, mode, quality, pos, -1, -1, track, replace, instrument) == 0);
+ break;
+
+ case Editing::ImportSerializeFiles:
+
+ to_import.clear ();
+ to_import.push_back (*a);
+
+ ok = (import_sndfiles (to_import, disposition, mode, quality, pos, 1, 1, track, replace, instrument) == 0);
+ break;
+
+ case Editing::ImportMergeFiles:
+ // Not entered, handled in earlier if() branch
+ break;
+ }
+ }