cherry pick 3aeb5a27bd4772ede0f31ea579bc031ca2019235 from old ardour-merge branch and hand resolve

This commit is contained in:
Paul Davis 2014-08-07 11:57:10 -04:00
parent ae26a2cc45
commit 018770adda
7 changed files with 202 additions and 241 deletions

View file

@ -1,113 +0,0 @@
#include "open_file_dialog_proxy.h"
#include <Windows.h>
#include <commdlg.h>
#include <ShlObj.h>
#include <iostream>
#include <string>
#include "glibmm/miscutils.h"
using namespace std;
namespace ARDOUR
{
bool save_file_dialog(std::string& file_name, 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_OVERWRITEPROMPT;
// 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();
}
// Run dialog
if(GetSaveFileName(&ofn))
{
file_name = ofn.lpstrFile;
return true;
}
return false;
}
bool open_file_dialog(std::string& file_name, 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;
// 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();
}
if( GetOpenFileName(&ofn) )
{
file_name = ofn.lpstrFile;
return true;
}
return false;
}
bool choose_folder_dialog(std::string& selected_path, std::string title)
{
BROWSEINFO bi;
memset(&bi, 0, sizeof(bi));
bi.lpszTitle = title.c_str();
bi.ulFlags = BIF_NEWDIALOGSTYLE;
OleInitialize(NULL);
LPITEMIDLIST pIDL = SHBrowseForFolder(&bi);
if (pIDL == NULL)
{
return false;
}
TCHAR *buffer = new TCHAR[MAX_PATH];
if(!SHGetPathFromIDList(pIDL, buffer) != 0)
{
CoTaskMemFree(pIDL);
return false;
}
selected_path = buffer;
CoTaskMemFree(pIDL);
OleUninitialize();
return true;
}
} // namespace ARDOUR

View file

@ -1,10 +1,21 @@
//
// OpenFileDialog.m
// Tracks
//
// Created by User on 5/8/14.
//
//
/*
Copyright (C) 2014 Waves Audio Ltd.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#import "open_file_dialog.h"
#import <Cocoa/Cocoa.h>
@ -15,13 +26,10 @@
using namespace std;
@implementation FileDialog
namespace ARDOUR
/* ====== "trampoline" functions to invoke Objective-C method ====== */
string
ARDOUR::open_file_dialog (std::string initial_path, string title)
{
// ====== 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
@ -31,10 +39,11 @@ namespace ARDOUR
string stdPath = [nsPath UTF8String];
return stdPath;
}
}
string save_file_dialog(std::string initial_path, string title)
{
string
ARDOUR::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
@ -44,10 +53,11 @@ namespace ARDOUR
string stdPath = [nsPath UTF8String];
return stdPath;
}
}
string choose_folder_dialog(std::string initial_path, string title)
{
string
ARDOUR::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
@ -59,11 +69,12 @@ namespace ARDOUR
return stdPath;
}
}// namespace ARDOUR
// ====== Objective-C functions called from C++ functions ====== //
/* ====== Objective-C functions called from C++ functions ====== */
// On open saved session
@implementation FileDialog
/* On open saved session */
+ (NSString*) class_open_file_dialog:(NSString *)title withArg2:(NSString *)initial_path
{
// Create a File Open Dialog class.
@ -102,7 +113,7 @@ namespace ARDOUR
return @"";
}
// On create new session
/* On create new session */
+ (NSString*) class_save_file_dialog:(NSString *)title withArg2:(NSString *)initial_path
{
// Create a File Open Dialog class.

View file

@ -1,31 +1,33 @@
//
// open_file_dialog_proxy.h
// Tracks
//
// Created by User on 5/12/14.
//
//
/*
Copyright (C) 2014 Waves Audio Ltd.
#ifndef Tracks_OpenFileDialogProxy_h
#define Tracks_OpenFileDialogProxy_h
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef Tracks_OpenFileDialog_h
#define Tracks_OpenFileDialog_h
#include <string>
#include "i18n.h"
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 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
#ifdef _WIN32
bool save_file_dialog(std::string& file_name, std::string initial_path = "", std::string title = "Save");
bool open_file_dialog(std::string& file_name, std::string initial_path = "", std::string title = "Open");
bool choose_folder_dialog(std::string& selected_path, std::string title = "Choose Folder");
#endif
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
#endif /* Tracks_OpenFileDialog_h */

View file

@ -0,0 +1,124 @@
/*
Copyright (C) 2014 Waves Audio Ltd.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <Windows.h>
#include <commdlg.h>
#include <ShlObj.h>
#include <iostream>
#include <string>
#include <glibmm/miscutils.h>
#include "open_file_dialog_proxy.h"
using namespace std;
string
ARDOUR::save_file_dialog (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_OVERWRITEPROMPT;
// 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();
}
// Run dialog
if (GetSaveFileName(&ofn)) {
return ofn.lpstrFile;
}
return string();
}
string
ARDOUR::open_file_dialog (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;
// 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();
}
if (GetOpenFileName(&ofn)) {
return ofn.lpstrFile;
}
return string ();
}
string
ARDOUR::choose_folder_dialog (std::string /* initial_path */, std::string title)
{
BROWSEINFO bi;
memset(&bi, 0, sizeof(bi));
bi.lpszTitle = title.c_str();
bi.ulFlags = BIF_NEWDIALOGSTYLE;
OleInitialize(NULL);
LPITEMIDLIST pIDL = SHBrowseForFolder(&bi);
if (pIDL == NULL) {
return string ();
}
TCHAR *buffer = new TCHAR[MAX_PATH];
if (!SHGetPathFromIDList(pIDL, buffer) != 0) {
CoTaskMemFree(pIDL);
return string ();
}
string selected_path = buffer;
CoTaskMemFree(pIDL);
OleUninitialize();
return selected_path;
}

View file

@ -148,62 +148,19 @@ SessionDialog::session_selected ()
void
SessionDialog::on_new_session (WavesButton*)
{
#ifdef __APPLE__
set_keep_above(false);
string temp_session_full_file_name = ARDOUR::save_file_dialog(Config->get_default_session_parent_dir(),_("Create New Session"));
_selected_session_full_file_name = ARDOUR::save_file_dialog(Config->get_default_session_parent_dir(),_("Create New Session"));
set_keep_above(true);
if(!temp_session_full_file_name.empty()) {
_selected_session_full_name = temp_session_full_file_name;
for (size_t i = 0; i < MAX_RECENT_SESSION_COUNTS; i++) {
_recent_session_button[i]->set_active (false);
}
hide();
_selection_type = NewSession;
response (Gtk::RESPONSE_ACCEPT);
if (!_selected_session_full_name.empty()) {
for (size_t i = 0; i < MAX_RECENT_SESSION_COUNTS; i++) {
_recent_session_button[i]->set_active (false);
}
hide();
_selection_type = NewSession;
response (Gtk::RESPONSE_ACCEPT);
}
return;
#endif
#ifdef _WIN32
set_keep_above(false);
string fileTitle;
// Open the file save dialog, and choose the file name
if ( ARDOUR::save_file_dialog(fileTitle, Config->get_default_session_parent_dir(), _("Create New Session")) ) {
set_keep_above(true);
_selected_session_full_name = fileTitle;
for (size_t i = 0; i < MAX_RECENT_SESSION_COUNTS; i++) {
_recent_session_button[i]->set_active (false);
}
hide();
_selection_type = NewSession;
response (Gtk::RESPONSE_ACCEPT);
}
return;
#endif // _WIN32
Gtk::FileChooserDialog dialog(*this, _("Create New Session"), Gtk::FILE_CHOOSER_ACTION_SAVE);
dialog.add_button ("CANCEL", Gtk::RESPONSE_CANCEL);
dialog.add_button ("OK", Gtk::RESPONSE_OK);
set_keep_above(false);
int responce = dialog.run ();
set_keep_above(true);
if (responce == Gtk::RESPONSE_OK) {
_selected_session_full_name = dialog.get_filename ();
for (size_t i = 0; i < MAX_RECENT_SESSION_COUNTS; i++) {
_recent_session_button[i]->set_active (false);
}
hide();
_selection_type = NewSession;
response (Gtk::RESPONSE_ACCEPT);
}
}
void
@ -435,4 +392,4 @@ SessionDialog::on_system_configuration (WavesButton* clicked_button)
_system_configuration_dialog->run();
redisplay_system_configuration ();
set_keep_above(true);
}
}

View file

@ -1269,37 +1269,15 @@ TracksControlPanel::on_browse_button (WavesButton*)
{
using namespace std;
#ifdef __APPLE__
set_keep_above(false);
set_keep_above (false);
_default_path_name = ARDOUR::choose_folder_dialog(Config->get_default_session_parent_dir(), _("Choose Default Path"));
set_keep_above(true);
set_keep_above (true);
if( !_default_path_name.empty() )
if (!_default_path_name.empty()) {
_default_open_path.set_text(_default_path_name);
else
} else {
_default_open_path.set_text(Config->get_default_session_parent_dir());
return;
#endif
#ifdef _WIN32
string fileTitle;
set_keep_above(false);
bool result = ARDOUR::choose_folder_dialog(fileTitle, _("Choose Default Path"));
set_keep_above(true);
// if path was chosen in dialog
if (result) {
_default_path_name = fileTitle;
}
if (!_default_path_name.empty())
_default_open_path.set_text(_default_path_name);
else
_default_open_path.set_text(Config->get_default_session_parent_dir());
return;
#endif // _WIN32
}
}
void

View file

@ -272,8 +272,10 @@ gtk2_ardour_sources = [
if sys.platform == 'darwin':
gtk2_ardour_sources.append('open_file_dialog.mm')
elif sys.platform == 'mingw' or sys.platform == 'msvc':
gtk2_ardour_sources.append('open_file_dialog_windows.cc')
else:
gtk2_ardour_sources.append('open_file_dialog.cc')
gtk2_ardour_sources.append('open_file_dialog_nix.cc')
def options(opt):
autowaf.set_options(opt)