minor polish for midi export dialog
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 23 May 2012 21:12:07 +0000 (21:12 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 23 May 2012 21:12:07 +0000 (21:12 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@12403 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor_export_audio.cc
gtk2_ardour/midi_export_dialog.cc
gtk2_ardour/midi_export_dialog.h

index 9521f6a0c676be686a814236e35b1d2fec3c5163..dbe95c229ff5ed28313fcfc935d28299957e1958 100644 (file)
@@ -136,7 +136,42 @@ Editor::export_region ()
                        return;
                }
 
+               dialog.hide ();
+
                string path = dialog.get_path ();
+
+               if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
+
+                       MessageDialog checker (_("File Exists!"),
+                                              true,
+                                              Gtk::MESSAGE_WARNING,
+                                              Gtk::BUTTONS_NONE);
+                       
+                       checker.set_title (_("File Exists!"));
+
+                       checker.add_button (Stock::CANCEL, RESPONSE_CANCEL);
+                       checker.add_button (_("Overwrite Existing File"), RESPONSE_ACCEPT);
+                       checker.set_default_response (RESPONSE_CANCEL);
+                       
+                       checker.set_wmclass (X_("midi_export_file_exists"), PROGRAM_NAME);
+                       checker.set_position (Gtk::WIN_POS_MOUSE);
+
+                       ret = checker.run ();
+
+                       switch (ret) {
+                       case Gtk::RESPONSE_ACCEPT:
+                               /* force unlink because the backend code will
+                                  go wrong if it tries to open an existing
+                                  file for writing.
+                               */
+                               ::unlink (path.c_str());
+                               break;
+                       default:
+                               return;
+                       }
+                       
+               }
+
                (void) midi_region->clone (path);
        }
 }
index 95bb7b658723f520dd05959f5e2c709be4991381..522bf50cb9eeb49ee96b752a792370e959bed151 100644 (file)
@@ -19,7 +19,9 @@
 
 #include <gtkmm/stock.h>
 
+#include "ardour/directory_names.h"
 #include "ardour/midi_region.h"
+#include "ardour/session.h"
 
 #include "midi_export_dialog.h"
 
@@ -29,17 +31,34 @@ MidiExportDialog::MidiExportDialog (PublicEditor&, boost::shared_ptr<MidiRegion>
        : ArdourDialog (string_compose (_("Export MIDI: %1"), region->name()))
        , file_chooser (Gtk::FILE_CHOOSER_ACTION_SAVE)
 {
+       set_border_width (12);
+
        add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
        add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+
+       get_vbox()->set_border_width (12);
        get_vbox()->pack_start (file_chooser);
-       file_chooser.set_filename (region->name() + ".mid");
+
+       set_default_response (Gtk::RESPONSE_ACCEPT);
+
+       file_chooser.set_current_name (region->name() + ".mid");
        file_chooser.show ();
+
+       file_chooser.signal_file_activated().connect (sigc::bind (sigc::mem_fun (*this, &MidiExportDialog::response), Gtk::RESPONSE_ACCEPT));
 }
 
 MidiExportDialog::~MidiExportDialog ()
 {
 }
 
+void
+MidiExportDialog::set_session (Session* s)
+{
+       ArdourDialog::set_session (s);
+
+       file_chooser.set_current_folder (Glib::build_filename (Glib::path_get_dirname (s->path()), ARDOUR::export_dir_name));
+}
+
 std::string
 MidiExportDialog::get_path () const
 {
index 86b2328415ab16600fb2fcc15c0d38e73c2811fc..f7399af63c823e001197b6c77bb34a5c6a76edfe 100644 (file)
@@ -32,6 +32,8 @@ class MidiExportDialog : public ArdourDialog {
        MidiExportDialog (PublicEditor& editor, boost::shared_ptr<ARDOUR::MidiRegion>);
        ~MidiExportDialog ();
 
+       void set_session (ARDOUR::Session*);
+
        std::string get_path() const;
 
   private: