2014-05-13 08:53:17 -05:00
|
|
|
#include "OpenFileDialogProxy.h"
|
|
|
|
|
|
|
|
|
|
#include <Windows.h>
|
|
|
|
|
#include <commdlg.h>
|
2014-05-21 08:27:14 -05:00
|
|
|
#include <ShlObj.h>
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
#include <string>
|
2014-05-13 08:53:17 -05:00
|
|
|
|
2014-05-21 10:58:00 -05:00
|
|
|
#include "glibmm/miscutils.h"
|
|
|
|
|
|
2014-05-13 08:53:17 -05:00
|
|
|
using namespace std;
|
|
|
|
|
namespace ARDOUR
|
|
|
|
|
{
|
2014-05-21 08:27:14 -05:00
|
|
|
bool SaveFileDialog(std::string& fileName, std::string path, std::string title)
|
2014-05-13 08:53:17 -05:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
2014-05-21 10:58:00 -05:00
|
|
|
// Check on valid path
|
|
|
|
|
WIN32_FIND_DATA FindFileData;
|
|
|
|
|
HANDLE handle = FindFirstFile(path.c_str(), &FindFileData) ;
|
|
|
|
|
int found = (handle != INVALID_HANDLE_VALUE);
|
|
|
|
|
|
|
|
|
|
// if path is valid
|
|
|
|
|
if( found )
|
2014-05-21 08:27:14 -05:00
|
|
|
ofn.lpstrInitialDir = path.c_str();
|
2014-05-21 10:58:00 -05:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
path = Glib::get_home_dir();
|
|
|
|
|
ofn.lpstrInitialDir = path.c_str();
|
|
|
|
|
}
|
2014-05-21 08:27:14 -05:00
|
|
|
|
|
|
|
|
// Run dialog
|
2014-05-13 08:53:17 -05:00
|
|
|
if(GetSaveFileName(&ofn))
|
|
|
|
|
{
|
|
|
|
|
fileName = ofn.lpstrFile;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 08:27:14 -05:00
|
|
|
bool OpenFileDialog(std::string& fileName, std::string path, std::string title)
|
2014-05-13 08:53:17 -05:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
2014-05-21 10:58:00 -05:00
|
|
|
// Check on valid path
|
|
|
|
|
WIN32_FIND_DATA FindFileData;
|
|
|
|
|
HANDLE handle = FindFirstFile(path.c_str(), &FindFileData) ;
|
|
|
|
|
int found = (handle != INVALID_HANDLE_VALUE);
|
|
|
|
|
|
|
|
|
|
// if path is valid
|
|
|
|
|
if( found )
|
|
|
|
|
ofn.lpstrInitialDir = path.c_str();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
path = Glib::get_home_dir();
|
2014-05-21 08:27:14 -05:00
|
|
|
ofn.lpstrInitialDir = path.c_str();
|
2014-05-21 10:58:00 -05:00
|
|
|
}
|
2014-05-21 08:27:14 -05:00
|
|
|
|
2014-05-13 08:53:17 -05:00
|
|
|
if( GetOpenFileName(&ofn) )
|
|
|
|
|
{
|
|
|
|
|
fileName = ofn.lpstrFile;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 10:58:00 -05:00
|
|
|
bool ChooseFolderDialog(std::string& selectedPath, std::string path, std::string title)
|
2014-05-21 08:27:14 -05:00
|
|
|
{
|
|
|
|
|
BROWSEINFO bi;
|
|
|
|
|
memset(&bi, 0, sizeof(bi));
|
|
|
|
|
|
|
|
|
|
bi.lpszTitle = title.c_str();
|
2014-05-21 12:43:31 -05:00
|
|
|
bi.ulFlags = BIF_NEWDIALOGSTYLE;
|
2014-05-21 08:27:14 -05:00
|
|
|
|
|
|
|
|
OleInitialize(NULL);
|
|
|
|
|
|
|
|
|
|
LPITEMIDLIST pIDL = SHBrowseForFolder(&bi);
|
2014-05-21 10:58:00 -05:00
|
|
|
|
2014-05-21 08:27:14 -05:00
|
|
|
if (pIDL == NULL)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TCHAR *buffer = new TCHAR[MAX_PATH];
|
|
|
|
|
if(!SHGetPathFromIDList(pIDL, buffer) != 0)
|
|
|
|
|
{
|
|
|
|
|
CoTaskMemFree(pIDL);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
selectedPath = buffer;
|
|
|
|
|
|
|
|
|
|
CoTaskMemFree(pIDL);
|
|
|
|
|
OleUninitialize();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace ARDOUR
|