From 81239741989cac76cb95dbcca7d4d56391168edc Mon Sep 17 00:00:00 2001 From: Nikolay Polyanovskii Date: Tue, 20 May 2014 05:29:32 -0500 Subject: [PATCH] [Summary] Add default new_session and open_saved_session path. [Reviewed] GZharun [git-p4: depot-paths = "//Abdaw/dev_main/tracks/": change = 461852] --- gtk2_ardour/OpenFileDialog.h | 5 +- gtk2_ardour/OpenFileDialog.mm | 94 ++++++++++++++++------ gtk2_ardour/OpenFileDialogProxy.h | 6 +- gtk2_ardour/session_dialog.logic.cc | 5 +- gtk2_ardour/tracks_control_panel.cc | 2 + gtk2_ardour/tracks_control_panel.h | 2 + gtk2_ardour/tracks_control_panel.logic.cc | 55 ++++++++++++- gtk2_ardour/tracks_control_panel.logic.h | 5 ++ gtk2_ardour/ui/tracks_preferences.xml | 8 ++ libs/ardour/ardour/rc_configuration_vars.h | 4 + 10 files changed, 155 insertions(+), 31 deletions(-) diff --git a/gtk2_ardour/OpenFileDialog.h b/gtk2_ardour/OpenFileDialog.h index 3a3af100f2..fd595dc40c 100644 --- a/gtk2_ardour/OpenFileDialog.h +++ b/gtk2_ardour/OpenFileDialog.h @@ -16,8 +16,9 @@ } // The Objective-C member function you want to call from C++ -+ (NSString*) ClassSaveFileDialog:(NSString *) title; -+ (NSString*) ClassOpenFileDialog:(NSString *) title; ++ (NSString*) ClassSaveFileDialog:(NSString *) title withArg2:(NSString *)path; ++ (NSString*) ClassOpenFileDialog:(NSString *) title withArg2:(NSString *)path; ++ (NSString*) ClassChooseFolderDialog:(NSString *) title withArg2:(NSString *)path; @end diff --git a/gtk2_ardour/OpenFileDialog.mm b/gtk2_ardour/OpenFileDialog.mm index 40574fbb66..feee77cd20 100644 --- a/gtk2_ardour/OpenFileDialog.mm +++ b/gtk2_ardour/OpenFileDialog.mm @@ -19,34 +19,55 @@ using namespace std; namespace ARDOUR { -// ====== C "trampoline" functions to invoke Objective-C method ====== // -string OpenFileDialog(string title) -{ - NSString *nsTitle = [NSString stringWithUTF8String:title.c_str()]; - - // Call the Objective-C method using Objective-C syntax - NSString *path = [FileDialog ClassOpenFileDialog : nsTitle]; - string stdPath = [path UTF8String]; - - return stdPath; -} + // ====== C "trampoline" functions to invoke Objective-C method ====== // + string OpenFileDialog(std::string path, string title) + { + NSString *nsTitle = [NSString stringWithUTF8String:title.c_str()]; + + //NP: we should find some gentle way to do this + path = "file://localhost" + path; + NSString *nsDefaultPath = [NSString stringWithUTF8String:path.c_str()]; + // Call the Objective-C method using Objective-C syntax + NSString *nsPath = [FileDialog ClassOpenFileDialog:nsTitle withArg2:nsDefaultPath]; + string stdPath = [nsPath UTF8String]; + + return stdPath; + } -string SaveFileDialog(string title) -{ - NSString *nsTitle = [NSString stringWithUTF8String:title.c_str()]; + string SaveFileDialog(std::string path, string title) + { + NSString *nsTitle = [NSString stringWithUTF8String:title.c_str()]; + + //NP: we should find some gentle way to do this + path = "file://localhost" + path; + NSString *nsDefaultPath = [NSString stringWithUTF8String:path.c_str()]; + // Call the Objective-C method using Objective-C syntax + NSString *nsPath = [FileDialog ClassSaveFileDialog:nsTitle withArg2:nsDefaultPath]; + string stdPath = [nsPath UTF8String]; + + return stdPath; + } - // Call the Objective-C method using Objective-C syntax - NSString *path = [FileDialog ClassSaveFileDialog : nsTitle]; - string stdPath = [path UTF8String]; - - return stdPath; -} -} + string ChooseFolderDialog(std::string path, string title) + { + NSString *nsTitle = [NSString stringWithUTF8String:title.c_str()]; + + //NP: we should find some gentle way to do this + path = "file://localhost" + path; + NSString *nsDefaultPath = [NSString stringWithUTF8String:path.c_str()]; + // Call the Objective-C method using Objective-C syntax + NSString *nsPath = [FileDialog ClassChooseFolderDialog:nsTitle withArg2:nsDefaultPath]; + + string stdPath = [nsPath UTF8String]; + + return stdPath; + } +}// namespace ARDOUR // ====== Objective-C functions called from C++ functions ====== // // On open saved session -+ (NSString*) ClassOpenFileDialog:(NSString*) title ++ (NSString*) ClassOpenFileDialog:(NSString *)title withArg2:(NSString *)path { // Create a File Open Dialog class. NSOpenPanel* openDlg = [NSOpenPanel openPanel]; @@ -59,6 +80,7 @@ string SaveFileDialog(string title) [openDlg setAllowedFileTypes:fileTypesArray]; [openDlg setAllowsMultipleSelection:FALSE]; [openDlg setTitle:title]; + [openDlg setDirectoryURL : [NSURL URLWithString:path]]; // Display the dialog box. If the OK pressed, // process the files. @@ -76,11 +98,12 @@ string SaveFileDialog(string title) } // On create new session -+ (NSString*) ClassSaveFileDialog:(NSString*) title ++ (NSString*) ClassSaveFileDialog:(NSString *)title withArg2:(NSString *)path { // Create a File Open Dialog class. NSSavePanel* saveDlg = [NSSavePanel savePanel]; [saveDlg setTitle:title]; + [saveDlg setDirectoryURL : [NSURL URLWithString:path]]; // Display the dialog box. If the OK pressed, // process the files. @@ -96,4 +119,29 @@ string SaveFileDialog(string title) return @""; } ++ (NSString*) ClassChooseFolderDialog:(NSString *)title withArg2:(NSString *)path +{ + // Create a File Open Dialog class. + NSOpenPanel* openDlg = [NSOpenPanel openPanel]; + + [openDlg setCanChooseDirectories:YES]; + [openDlg setAllowsMultipleSelection:FALSE]; + [openDlg setTitle:title]; + [openDlg setDirectoryURL : [NSURL URLWithString:path]]; + + // Display the dialog box. If the OK pressed, + // process the files. + if ( [openDlg runModal] == NSOKButton ) + { + // Gets first selected file + NSArray *files = [openDlg URLs]; + NSURL *saveURL = [files objectAtIndex:0]; + NSString *filePath = [saveURL path]; + + return filePath; + } + + return @""; +} + @end diff --git a/gtk2_ardour/OpenFileDialogProxy.h b/gtk2_ardour/OpenFileDialogProxy.h index f430d713bb..9711fc07c8 100644 --- a/gtk2_ardour/OpenFileDialogProxy.h +++ b/gtk2_ardour/OpenFileDialogProxy.h @@ -16,14 +16,16 @@ namespace ARDOUR // This is the C "trampoline" function that will be used // to invoke a specific Objective-C method FROM C++ #ifdef __APPLE__ - std::string SaveFileDialog(std::string title = "Save"); - std::string OpenFileDialog(std::string title = "Open"); + std::string SaveFileDialog(std::string path = "", std::string title = "Save"); + std::string OpenFileDialog(std::string path = "", std::string title = "Open"); + std::string ChooseFolderDialog(std::string path = "", std::string title = "Choose Folder"); #endif // OS Windows specific functions #ifdef _WIN32 bool SaveFileDialog(std::string& fileName, std::string title = "Save"); bool OpenFileDialog(std::string& fileName, std::string title = "Open"); + bool ChooseFolderDialog(std::string& fileName, std::string title = "Choose Folder"); #endif } #endif diff --git a/gtk2_ardour/session_dialog.logic.cc b/gtk2_ardour/session_dialog.logic.cc index cd00c3bb9c..35bca5e928 100644 --- a/gtk2_ardour/session_dialog.logic.cc +++ b/gtk2_ardour/session_dialog.logic.cc @@ -43,6 +43,7 @@ #include "ardour/session_state_utils.h" #include "ardour/template_utils.h" #include "ardour/filename_extensions.h" +#include "ardour/rc_configuration.h" #include "ardour_ui.h" #include "session_dialog.h" @@ -142,7 +143,7 @@ SessionDialog::on_new_session (WavesButton*) { #ifdef __APPLE__ set_keep_above(false); - _selected_session_full_name = ARDOUR::SaveFileDialog(_("Create New Session")); + _selected_session_full_name = ARDOUR::SaveFileDialog(Config->get_default_open_path(),_("Create New Session")); set_keep_above(true); if(_selected_session_full_name.size() >= 1) { @@ -324,7 +325,7 @@ SessionDialog::on_open_saved_session (WavesButton*) #ifdef __APPLE__ set_keep_above(false); - _selected_session_full_name = ARDOUR::OpenFileDialog(_("Select Saved Session")); + _selected_session_full_name = ARDOUR::OpenFileDialog(Config->get_default_open_path(), _("Select Saved Session")); set_keep_above(true); if(_selected_session_full_name.size() >= 1) { diff --git a/gtk2_ardour/tracks_control_panel.cc b/gtk2_ardour/tracks_control_panel.cc index 8404b07bc1..ea64dcb304 100644 --- a/gtk2_ardour/tracks_control_panel.cc +++ b/gtk2_ardour/tracks_control_panel.cc @@ -83,8 +83,10 @@ TracksControlPanel::TracksControlPanel () , _sample_rate_combo (named_children ().get_combo_box_text ("sample_rate_combo")) , _buffer_size_combo (named_children ().get_combo_box_text ("buffer_size_combo")) , _latency_label (named_children ().get_label("latency_label")) + , _default_open_path (named_children ().get_label("default_open_path")) , _multi_out_button(named_children ().get_waves_button ("multi_out_button")) , _stereo_out_button(named_children ().get_waves_button ("stereo_out_button")) + , _brows_button(named_children ().get_waves_button("brows_default_folder")) , _have_control (false) , _ignore_changes (0) { diff --git a/gtk2_ardour/tracks_control_panel.h b/gtk2_ardour/tracks_control_panel.h index c144418a7a..072af9b4dc 100644 --- a/gtk2_ardour/tracks_control_panel.h +++ b/gtk2_ardour/tracks_control_panel.h @@ -62,11 +62,13 @@ class TracksControlPanel : public WavesDialog, public PBD::ScopedConnectionList WavesButton& _name_track_after_driver_button; WavesButton& _reset_track_names_button; WavesButton& _yes_button; + WavesButton& _brows_button; Gtk::ComboBoxText& _engine_combo; Gtk::ComboBoxText& _device_combo; Gtk::ComboBoxText& _sample_rate_combo; Gtk::ComboBoxText& _buffer_size_combo; Gtk::Label& _latency_label; + Gtk::Label& _default_open_path; #include "tracks_control_panel.logic.h" }; diff --git a/gtk2_ardour/tracks_control_panel.logic.cc b/gtk2_ardour/tracks_control_panel.logic.cc index 064877d49b..ce553ffcd7 100644 --- a/gtk2_ardour/tracks_control_panel.logic.cc +++ b/gtk2_ardour/tracks_control_panel.logic.cc @@ -35,6 +35,8 @@ #include "i18n.h" #include "pbd/convert.h" +#include "OpenFileDialogProxy.h" + using namespace ARDOUR; using namespace Gtk; using namespace Gtkmm2ext; @@ -58,6 +60,7 @@ TracksControlPanel::init () _multi_out_button.signal_clicked.connect(sigc::mem_fun (*this, &TracksControlPanel::on_multi_out)); _stereo_out_button.signal_clicked.connect(sigc::mem_fun (*this, &TracksControlPanel::on_stereo_out)); + _brows_button.signal_clicked.connect(sigc::mem_fun (*this, &TracksControlPanel::on_brows_button)); EngineStateController::instance ()->EngineRunning.connect (running_connection, MISSING_INVALIDATOR, boost::bind (&TracksControlPanel::engine_running, this), gui_context()); EngineStateController::instance ()->EngineStopped.connect (stopped_connection, MISSING_INVALIDATOR, boost::bind (&TracksControlPanel::engine_stopped, this), gui_context()); @@ -84,6 +87,8 @@ TracksControlPanel::init () populate_output_channels(); _audio_settings_tab_button.set_active(true); + + _default_open_path.set_text(Config->get_default_open_path()); } DeviceConnectionControl& TracksControlPanel::add_device_capture_control(std::string device_capture_name, bool active, uint16_t capture_number, std::string track_name) @@ -524,7 +529,6 @@ TracksControlPanel::on_multi_out (WavesButton*) Config->set_output_auto_connect(AutoConnectPhysical); } - void TracksControlPanel::on_stereo_out (WavesButton*) { @@ -535,12 +539,55 @@ TracksControlPanel::on_stereo_out (WavesButton*) Config->set_output_auto_connect(AutoConnectMaster); } +void +TracksControlPanel::on_brows_button (WavesButton*) +{ + using namespace std; + +#ifdef __APPLE__ + set_keep_above(false); + _default_path_name = ARDOUR::ChooseFolderDialog(Config->get_default_open_path(), _("Choose Default Path")); + set_keep_above(true); + + if( !_default_path_name.empty() ) + _default_open_path.set_text(_default_path_name); + else + _default_open_path.set_text(Config->get_default_open_path()); + + return; +#endif + +#ifdef _WIN32 + /*set_keep_above(false); + string fileTitle; + if ( ARDOUR::OpenFileDialog(fileTitle, _("Choose Default Path")) ) { + set_keep_above(true); + _default_path_name = fileTitle; + } + + using namespace std; + cout<get_default_open_path()); + */ + return; +#endif // _WIN32 +} + void TracksControlPanel::on_ok (WavesButton*) { hide(); EngineStateController::instance()->push_current_state_to_backend(true); response(Gtk::RESPONSE_OK); + + Config->set_default_open_path(_default_path_name); + Config->save_state(); } @@ -548,7 +595,8 @@ void TracksControlPanel::on_cancel (WavesButton*) { hide(); - response(Gtk::RESPONSE_CANCEL); + response(Gtk::RESPONSE_CANCEL); + _default_open_path.set_text(Config->get_default_open_path()); } @@ -557,6 +605,9 @@ TracksControlPanel::on_apply (WavesButton*) { EngineStateController::instance()->push_current_state_to_backend(true); response(Gtk::RESPONSE_APPLY); + + Config->set_default_open_path(_default_path_name); + Config->save_state(); } diff --git a/gtk2_ardour/tracks_control_panel.logic.h b/gtk2_ardour/tracks_control_panel.logic.h index 530d8243a7..ec89f65e38 100644 --- a/gtk2_ardour/tracks_control_panel.logic.h +++ b/gtk2_ardour/tracks_control_panel.logic.h @@ -17,6 +17,8 @@ */ +#include + // class TracksControlPanel : public WavesDialog { public: @@ -74,6 +76,7 @@ void on_control_panel (WavesButton*); void on_multi_out (WavesButton*); void on_stereo_out (WavesButton*); + void on_brows_button (WavesButton*); void on_ok(WavesButton*); void on_cancel(WavesButton*); void on_apply(WavesButton*); @@ -117,6 +120,8 @@ uint32_t get_input_latency () const { return 0; }; uint32_t get_output_latency () const { return 0; }; + std::string _default_path_name; + void show_buffer_duration (); //}; diff --git a/gtk2_ardour/ui/tracks_preferences.xml b/gtk2_ardour/ui/tracks_preferences.xml index f8ec228632..d7c53fe343 100644 --- a/gtk2_ardour/ui/tracks_preferences.xml +++ b/gtk2_ardour/ui/tracks_preferences.xml @@ -236,6 +236,14 @@