From b09ff415eba05b76fb3fd59099c1dd83aba86bea Mon Sep 17 00:00:00 2001 From: YPozdnyakov Date: Wed, 4 Feb 2015 18:30:00 +0200 Subject: [PATCH] [Summary]: add Save-as Dialog. Change ProgressDialog for save-as process. --- gtk2_ardour/ardour_ui.cc | 69 ++++++++++++---------------- gtk2_ardour/ardour_ui.h | 2 +- gtk2_ardour/open_file_dialog.h | 1 + gtk2_ardour/open_file_dialog.mm | 56 ++++++++++++++++++++++ gtk2_ardour/open_file_dialog_proxy.h | 1 + 5 files changed, 88 insertions(+), 41 deletions(-) diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 52b39e6e73..7a37247568 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -2300,20 +2300,14 @@ ARDOUR_UI::session_auto_save_is_allowed() const } bool -ARDOUR_UI::save_as_progress_update (float fraction, int64_t cnt, int64_t total, Gtk::Label* label, Gtk::ProgressBar* bar) +ARDOUR_UI::save_as_progress_update (float fraction, int64_t cnt, int64_t total) { char buf[256]; snprintf (buf, sizeof (buf), _("Copied %" PRId64 " of %" PRId64), cnt, total); - label->set_text (buf); - bar->set_fraction (fraction); - - /* process events, redraws, etc. */ - - while (gtk_events_pending()) { - gtk_main_iteration (); - } + _progress_dialog.set_bottom_label (buf); + _progress_dialog.set_progress (fraction); return true; /* continue with save-as */ } @@ -2325,51 +2319,46 @@ ARDOUR_UI::save_session_as () return; } - ArdourDialog save_as_dialog (_("Save As"), true); - Gtk::Label label; - Gtk::ProgressBar progress_bar; - - save_as_dialog.get_vbox()->pack_start (label); - save_as_dialog.get_vbox()->pack_start (progress_bar); - label.show (); - progress_bar.show (); + string save_as_session_full_file_name; + bool copy_media; + save_as_session_full_file_name = ARDOUR::save_as_file_dialog (Config->get_default_session_parent_dir(),_("Save As"), copy_media); + + // Button 'Cancel' was pressed + if (save_as_session_full_file_name.empty ()) + return ; - Session::SaveAs sa; - - /* THIS IS A HARD-CODED SETTING OF THE OPTIONS FOR SAVE-AS. - - IN REALITY SOME DIALOG NEEDS TO COLLECT THIS INFORMATION - FROM THE USER. - - BASED ON DISCUSSIONS WITH IGOR, TRACKS SHOULD NOT PRESENT - THE "copy_external" option, BUT SHOULD ALWAYS SET IT TO - TRUE. - */ - - sa.new_parent_folder = "/tmp"; - sa.new_name = "foobar"; - sa.switch_to = true; - sa.copy_media = true; - sa.copy_external = false; + Session::SaveAs sa; + sa.new_parent_folder = Glib::path_get_dirname (save_as_session_full_file_name); + sa.new_name = basename_nosuffix (save_as_session_full_file_name); + sa.copy_media = copy_media; + + // it should be always so + /* + Paul's comment: + BASED ON DISCUSSIONS WITH IGOR, TRACKS SHOULD NOT PRESENT + THE "copy_external" option, BUT SHOULD ALWAYS SET IT TO + TRUE. + */ + sa.switch_to = true; + sa.copy_external = true; /* this signal will be emitted from within this, the calling thread, * after every file is copied. It provides information on percentage * complete (in terms of total data to copy), the number of files * copied so far, and the total number to copy. */ - ScopedConnection c; + sa.Progress.connect_same_thread (c, boost::bind (&ARDOUR_UI::save_as_progress_update, this, _1, _2, _3)); - sa.Progress.connect_same_thread (c, boost::bind (&ARDOUR_UI::save_as_progress_update, this, _1, _2, _3, &label, &progress_bar)); - - save_as_dialog.show_all (); - save_as_dialog.present (); - + // Show ProgressDialog + _progress_dialog.set_top_label (string_compose (("Saving session: %1"), sa.new_name)); + _progress_dialog.show (); if (_session->save_as (sa)) { /* ERROR MESSAGE */ MessageDialog msg (string_compose (_("Save As failed: %1"), sa.failure_message)); msg.run (); } + _progress_dialog.hide (); } /** Ask the user for the name of a new snapshot and then take it. diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index e5e68ae810..e79bdb14d8 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -677,7 +677,7 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr guint32 last_key_press_time; void snapshot_session (bool switch_to_it); - bool save_as_progress_update (float fraction, int64_t cnt, int64_t total, Gtk::Label* label, Gtk::ProgressBar* bar); + bool save_as_progress_update (float fraction, int64_t cnt, int64_t total); void save_session_as (); void rename_session (); void setup_order_hint (); diff --git a/gtk2_ardour/open_file_dialog.h b/gtk2_ardour/open_file_dialog.h index d991933351..6cdb24a119 100644 --- a/gtk2_ardour/open_file_dialog.h +++ b/gtk2_ardour/open_file_dialog.h @@ -17,6 +17,7 @@ // The Objective-C member function you want to call from C++ + (NSString*) class_save_file_dialog:(NSString *) title withArg2:(NSString *)path; ++ (NSString*) class_save_as_file_dialog:(NSString *) title withArg2:(NSString *)path withArg3: (BOOL*) copy_media; + (NSString*) class_open_file_dialog:(NSString *) title withArg2:(NSString *)path; + (NSString*) class_choose_folder_dialog:(NSString *) title withArg2:(NSString *)path; diff --git a/gtk2_ardour/open_file_dialog.mm b/gtk2_ardour/open_file_dialog.mm index a863b7ad40..23a5d29c7c 100644 --- a/gtk2_ardour/open_file_dialog.mm +++ b/gtk2_ardour/open_file_dialog.mm @@ -87,7 +87,24 @@ ARDOUR::save_file_dialog (std::string initial_path, std::string title) return stdPath; } + +std::string +ARDOUR::save_as_file_dialog (std::string initial_path, std::string title, bool& copy_media) +{ + NSString *nsTitle = [NSString stringWithUTF8String:title.c_str()]; + //NP: we should find some gentle way to do this + NSString *nsDefaultPath = [NSString stringWithUTF8String:initial_path.c_str()]; + // Call the Objective-C method using Objective-C syntax + BOOL temp_copy_media; + NSString *nsPath = [FileDialog class_save_as_file_dialog:nsTitle withArg2:nsDefaultPath withArg3: &temp_copy_media]; + + std::string stdPath = [nsPath UTF8String]; + copy_media = [temp_copy_media BOOL]; + + return stdPath; +} + std::string ARDOUR::choose_folder_dialog(std::string initial_path, std::string title) { @@ -210,6 +227,45 @@ ARDOUR::choose_folder_dialog(std::string initial_path, std::string title) return @""; } +/* On save-as session */ ++ (NSString*) class_save_as_file_dialog:(NSString *)title withArg2:(NSString *)initial_path withArg3:(BOOL *)copy_media +{ + NSSavePanel* saveDlg = [NSSavePanel savePanel]; + [saveDlg setTitle:title]; + [saveDlg setCanCreateDirectories:YES]; + + NSFileManager *fm = [[NSFileManager alloc] init]; + BOOL isDir; + BOOL exists = [fm fileExistsAtPath:initial_path isDirectory:&isDir]; + + if(!exists) + initial_path = NSHomeDirectory(); + + [saveDlg setDirectoryURL : [NSURL fileURLWithPath:initial_path]]; + + // add checkBox + NSButton *button = [[NSButton alloc] init]; + [button setButtonType:NSSwitchButton]; + button.title = NSLocalizedString(@"Copy external media", @""); + [button sizeToFit]; + [saveDlg setAccessoryView:button]; + saveDlg.delegate = self; + + // Display the dialog box. If the OK pressed, + // process the files. + if ( [saveDlg runModal] == NSOKButton ) + { + // Gets list of all files selected + NSURL *saveURL = [saveDlg URL]; + NSString *filePath = [saveURL path]; + *copy_media = (((NSButton*)saveDlg.accessoryView).state == NSOnState); + return filePath; + } + + return @""; +} + + + (NSString*) class_choose_folder_dialog:(NSString *)title withArg2:(NSString *)initial_path { // Create a File Open Dialog class. diff --git a/gtk2_ardour/open_file_dialog_proxy.h b/gtk2_ardour/open_file_dialog_proxy.h index 06e6034339..9749dfec07 100644 --- a/gtk2_ardour/open_file_dialog_proxy.h +++ b/gtk2_ardour/open_file_dialog_proxy.h @@ -26,6 +26,7 @@ namespace ARDOUR { std::string save_file_dialog (std::string initial_path = "", std::string title = _("Save")); + std::string save_as_file_dialog (std::string, std::string title, bool &); std::string open_file_dialog (std::string initial_path = "", std::string title = _("Open")); std::vector open_file_dialog (std::vector extensions, std::string initial_path = "", std::string title = _("Open")); std::string choose_folder_dialog (std::string initial_path = "", std::string title = _("Choose Folder"));