diff --git a/gtk2_ardour/open_file_dialog.mm b/gtk2_ardour/open_file_dialog.mm new file mode 100644 index 0000000000..f4d30c5eeb --- /dev/null +++ b/gtk2_ardour/open_file_dialog.mm @@ -0,0 +1,168 @@ +// +// OpenFileDialog.m +// Tracks +// +// Created by User on 5/8/14. +// +// + +#import "open_file_dialog.h" +#import + +#include + +#include + +using namespace std; + +@implementation FileDialog + +namespace ARDOUR +{ + // ====== C "trampoline" functions to invoke Objective-C method ====== // + string open_file_dialog(std::string initial_path, string title) + { + 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 + NSString *nsPath = [FileDialog class_open_file_dialog:nsTitle withArg2:nsDefaultPath]; + string stdPath = [nsPath UTF8String]; + + return stdPath; + } + + string save_file_dialog(std::string initial_path, string title) + { + 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 + NSString *nsPath = [FileDialog class_save_file_dialog:nsTitle withArg2:nsDefaultPath]; + string stdPath = [nsPath UTF8String]; + + return stdPath; + } + + string choose_folder_dialog(std::string initial_path, string title) + { + 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 + NSString *nsPath = [FileDialog class_choose_folder_dialog:nsTitle withArg2:nsDefaultPath]; + + string stdPath = [nsPath UTF8String]; + + return stdPath; + } +}// namespace ARDOUR + +// ====== Objective-C functions called from C++ functions ====== // + +// On open saved session ++ (NSString*) class_open_file_dialog:(NSString *)title withArg2:(NSString *)initial_path +{ + // Create a File Open Dialog class. + NSOpenPanel* openDlg = [NSOpenPanel openPanel]; + + // Set array of file types + NSArray *fileTypesArray; + fileTypesArray = [NSArray arrayWithObjects:@"ardour", nil]; + + [openDlg setCanChooseFiles:YES]; + [openDlg setAllowedFileTypes:fileTypesArray]; + [openDlg setAllowsMultipleSelection:FALSE]; + [openDlg setTitle:title]; + + NSFileManager *fm = [[NSFileManager alloc] init]; + BOOL isDir; + BOOL exists = [fm fileExistsAtPath:initial_path isDirectory:&isDir]; + + if(!exists) + initial_path = NSHomeDirectory(); + + [openDlg setDirectoryURL : [NSURL fileURLWithPath:initial_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 @""; +} + +// On create new session ++ (NSString*) class_save_file_dialog:(NSString *)title withArg2:(NSString *)initial_path +{ + // Create a File Open Dialog class. + NSSavePanel* saveDlg = [NSSavePanel savePanel]; + [saveDlg setTitle:title]; + + 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]]; + + // 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]; + + return filePath; + } + + return @""; +} + ++ (NSString*) class_choose_folder_dialog:(NSString *)title withArg2:(NSString *)initial_path +{ + // Create a File Open Dialog class. + NSOpenPanel* openDlg = [NSOpenPanel openPanel]; + + [openDlg setCanChooseDirectories:YES]; + [openDlg setAllowsMultipleSelection:FALSE]; + [openDlg setTitle:title]; + + NSFileManager *fm = [[NSFileManager alloc] init]; + BOOL isDir; + BOOL exists = [fm fileExistsAtPath:initial_path isDirectory:&isDir]; + + if(!exists) + initial_path = NSHomeDirectory(); + + [openDlg setDirectoryURL : [NSURL fileURLWithPath:initial_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/open_file_dialog_proxy.h b/gtk2_ardour/open_file_dialog_proxy.h index ab43f8b9a9..611d5bc83a 100644 --- a/gtk2_ardour/open_file_dialog_proxy.h +++ b/gtk2_ardour/open_file_dialog_proxy.h @@ -16,9 +16,9 @@ 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 initial_path = "", std::string title = "Save"); - std::string OpenFileDialog(std::string initial_path = "", std::string title = "Open"); - std::string ChooseFolderDialog(std::string initial_path = "", std::string title = "Choose Folder"); + std::string save_file_dialog(std::string initial_path = "", std::string title = "Save"); + std::string open_file_dialog(std::string initial_path = "", std::string title = "Open"); + std::string choose_folder_dialog(std::string initial_path = "", std::string title = "Choose Folder"); #endif // OS Windows specific functions diff --git a/gtk2_ardour/session_dialog.logic.cc b/gtk2_ardour/session_dialog.logic.cc index e291fce004..a177548977 100644 --- a/gtk2_ardour/session_dialog.logic.cc +++ b/gtk2_ardour/session_dialog.logic.cc @@ -143,7 +143,7 @@ SessionDialog::on_new_session (WavesButton*) { #ifdef __APPLE__ set_keep_above(false); - _selected_session_full_name = ARDOUR::SaveFileDialog(Config->get_default_open_path(),_("Create New Session")); + _selected_session_full_name = ARDOUR::save_file_dialog(Config->get_default_open_path(),_("Create New Session")); set_keep_above(true); if(_selected_session_full_name.size() >= 1) { @@ -325,7 +325,7 @@ SessionDialog::on_open_saved_session (WavesButton*) #ifdef __APPLE__ set_keep_above(false); - _selected_session_full_name = ARDOUR::OpenFileDialog(Config->get_default_open_path(), _("Select Saved Session")); + _selected_session_full_name = ARDOUR::open_file_dialog(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.logic.cc b/gtk2_ardour/tracks_control_panel.logic.cc index 5536aba13e..49c3ed5c9f 100644 --- a/gtk2_ardour/tracks_control_panel.logic.cc +++ b/gtk2_ardour/tracks_control_panel.logic.cc @@ -578,7 +578,7 @@ TracksControlPanel::on_browse_button (WavesButton*) #ifdef __APPLE__ set_keep_above(false); - _default_path_name = ARDOUR::ChooseFolderDialog(Config->get_default_open_path(), _("Choose Default Path")); + _default_path_name = ARDOUR::choose_folder_dialog(Config->get_default_open_path(), _("Choose Default Path")); set_keep_above(true); if( !_default_path_name.empty() ) diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index e30a366e4c..cddd0fa8e5 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -266,7 +266,7 @@ gtk2_ardour_sources = [ ] if sys.platform == 'darwin': - gtk2_ardour_sources.append('OpenFileDialog.mm') + gtk2_ardour_sources.append('open_file_dialog.mm') else: gtk2_ardour_sources.append('open_file_dialog.cc')