mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-26 00:17:49 +01:00
[Summary] Implemented dialog for multi selection. Added ability to choose required file types.
[Reviewed on Windows] VKamyshniy
This commit is contained in:
parent
22c6dcd975
commit
0e07fdadac
3 changed files with 144 additions and 10 deletions
|
|
@ -21,17 +21,18 @@
|
|||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ====== "trampoline" functions to invoke Objective-C method ====== */
|
||||
string
|
||||
ARDOUR::open_file_dialog (std::string initial_path, string title)
|
||||
std::string
|
||||
ARDOUR::open_file_dialog (std::string initial_path, std::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
|
||||
|
|
@ -41,8 +42,38 @@ ARDOUR::open_file_dialog (std::string initial_path, string title)
|
|||
return stdPath;
|
||||
}
|
||||
|
||||
string
|
||||
ARDOUR::save_file_dialog (std::string initial_path, string title)
|
||||
std::vector<std::string>
|
||||
ARDOUR::open_file_dialog (std::vector<std::string> extantions, std::string initial_path, std::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()];
|
||||
|
||||
id fileTypesArray = [NSMutableArray new];
|
||||
|
||||
for (auto str : extantions) {
|
||||
id nsstr = [NSString stringWithUTF8String:str.c_str()];
|
||||
[fileTypesArray addObject:nsstr];
|
||||
}
|
||||
|
||||
NSArray *nsPathes = [FileDialog class_open_file_dialog:nsTitle withArg2:nsDefaultPath withArg3:fileTypesArray];
|
||||
|
||||
std::vector<std::string> stdPathes;
|
||||
|
||||
int count = [nsPathes count];
|
||||
for (int i=0; i<count; i++) {
|
||||
NSURL *saveURL = [nsPathes objectAtIndex:i];
|
||||
NSString *filePath = [saveURL path];
|
||||
string stdPath = [filePath UTF8String];
|
||||
stdPathes.push_back (stdPath);
|
||||
}
|
||||
|
||||
// Returns pathes to selected files
|
||||
return stdPathes;
|
||||
}
|
||||
|
||||
std::string
|
||||
ARDOUR::save_file_dialog (std::string initial_path, std::string title)
|
||||
{
|
||||
NSString *nsTitle = [NSString stringWithUTF8String:title.c_str()];
|
||||
|
||||
|
|
@ -55,8 +86,8 @@ ARDOUR::save_file_dialog (std::string initial_path, string title)
|
|||
return stdPath;
|
||||
}
|
||||
|
||||
string
|
||||
ARDOUR::choose_folder_dialog(std::string initial_path, string title)
|
||||
std::string
|
||||
ARDOUR::choose_folder_dialog(std::string initial_path, std::string title)
|
||||
{
|
||||
NSString *nsTitle = [NSString stringWithUTF8String:title.c_str()];
|
||||
|
||||
|
|
@ -113,6 +144,39 @@ ARDOUR::choose_folder_dialog(std::string initial_path, string title)
|
|||
return @"";
|
||||
}
|
||||
|
||||
/* On choose many files */
|
||||
+ (NSArray*) class_open_file_dialog:(NSString *)title withArg2:(NSString *)initial_path withArg3:(NSArray*) fileTypesArray
|
||||
{
|
||||
// Create a File Open Dialog class.
|
||||
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
|
||||
|
||||
[openDlg setCanChooseFiles:YES];
|
||||
[openDlg setAllowedFileTypes:fileTypesArray];
|
||||
[openDlg setAllowsMultipleSelection:TRUE];
|
||||
[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];
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
/* On create new session */
|
||||
+ (NSString*) class_save_file_dialog:(NSString *)title withArg2:(NSString *)initial_path
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ namespace ARDOUR
|
|||
{
|
||||
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::vector<std::string> open_file_dialog (std::vector<std::string> extantions, std::string initial_path = "", std::string title = _("Open"));
|
||||
std::string choose_folder_dialog (std::string initial_path = "", std::string title = _("Choose Folder"));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,11 +25,13 @@
|
|||
|
||||
#include <glibmm/miscutils.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "open_file_dialog_proxy.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
string
|
||||
std::string
|
||||
ARDOUR::save_file_dialog (std::string initial_path, std::string title)
|
||||
{
|
||||
TCHAR szFilePathName[_MAX_PATH] = "";
|
||||
|
|
@ -62,7 +64,7 @@ ARDOUR::save_file_dialog (std::string initial_path, std::string title)
|
|||
return string();
|
||||
}
|
||||
|
||||
string
|
||||
std::string
|
||||
ARDOUR::open_file_dialog (std::string initial_path, std::string title)
|
||||
{
|
||||
TCHAR szFilePathName[_MAX_PATH] = "";
|
||||
|
|
@ -94,7 +96,74 @@ ARDOUR::open_file_dialog (std::string initial_path, std::string title)
|
|||
return string ();
|
||||
}
|
||||
|
||||
string
|
||||
std::vector<std::string>
|
||||
ARDOUR::open_file_dialog (std::vector<std::string> extentions, std::string initial_path, std::string title)
|
||||
{
|
||||
TCHAR szFilePathName[_MAX_PATH] = "";
|
||||
OPENFILENAME ofn = {0};
|
||||
ofn.lStructSize = sizeof(OPENFILENAME);
|
||||
ofn.lpstrFile = szFilePathName; // This will hold the file name
|
||||
ofn.nMaxFile = _MAX_PATH;
|
||||
ofn.lpstrTitle = title.c_str();
|
||||
ofn.Flags = OFN_PATHMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER;
|
||||
|
||||
// Create filter for required file types
|
||||
std::string filter;
|
||||
for (int i = 0; i < extentions.size(); ++i) {
|
||||
filter += "*."+extentions[i]+";";
|
||||
}
|
||||
|
||||
char c_filter[2+filter.size()+2];
|
||||
c_filter[0] = ' ';
|
||||
c_filter[1] = '\0';
|
||||
strcpy (c_filter+2, filter.c_str ());
|
||||
c_filter[filter.size()+3] = '\0';
|
||||
|
||||
ofn.lpstrFilter = c_filter;
|
||||
|
||||
// Check on valid path
|
||||
WIN32_FIND_DATA FindFileData;
|
||||
HANDLE handle = FindFirstFile(initial_path.c_str(), &FindFileData) ;
|
||||
int found = (handle != INVALID_HANDLE_VALUE);
|
||||
|
||||
// if path is valid
|
||||
if (found) {
|
||||
ofn.lpstrInitialDir = initial_path.c_str();
|
||||
} else {
|
||||
initial_path = Glib::get_home_dir();
|
||||
ofn.lpstrInitialDir = initial_path.c_str();
|
||||
}
|
||||
|
||||
std::vector<std::string> file_pathes;
|
||||
|
||||
if (GetOpenFileName(&ofn)) {
|
||||
|
||||
std::string directory_path = ofn.lpstrFile;
|
||||
std::string path;
|
||||
char* ptr = ofn.lpstrFile;
|
||||
|
||||
bool many_files = (ofn.lpstrFile [strlen (ofn.lpstrFile) + 1] != 0);
|
||||
|
||||
if (ofn.lpstrFile [strlen (ofn.lpstrFile) + 1] != 0) { // Many files
|
||||
for (char *current_name = ofn.lpstrFile + strlen (ofn.lpstrFile) + 1;
|
||||
*current_name;
|
||||
current_name += strlen (current_name) + 1) {
|
||||
file_pathes.push_back (ofn.lpstrFile);
|
||||
std::string& current_file_path = file_pathes.back ();
|
||||
current_file_path += "\\";
|
||||
current_file_path += current_name;
|
||||
}
|
||||
} else {
|
||||
file_pathes.push_back (ofn.lpstrFile); // single file selected
|
||||
}
|
||||
|
||||
return file_pathes;
|
||||
}
|
||||
|
||||
return file_pathes;
|
||||
}
|
||||
|
||||
std::string
|
||||
ARDOUR::choose_folder_dialog (std::string /* initial_path */, std::string title)
|
||||
{
|
||||
BROWSEINFO bi;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue