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
|
|
|
|
|
|
|
|
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 08:27:14 -05:00
|
|
|
if( !path.empty() )
|
|
|
|
|
ofn.lpstrInitialDir = path.c_str();
|
|
|
|
|
|
|
|
|
|
// 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 08:27:14 -05:00
|
|
|
if( !path.empty() )
|
|
|
|
|
ofn.lpstrInitialDir = path.c_str();
|
|
|
|
|
|
2014-05-13 08:53:17 -05:00
|
|
|
if( GetOpenFileName(&ofn) )
|
|
|
|
|
{
|
|
|
|
|
fileName = ofn.lpstrFile;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 08:27:14 -05:00
|
|
|
bool ChooseFolderDialog(std::string& selectedPath, std::string title)
|
|
|
|
|
{
|
|
|
|
|
BROWSEINFO bi;
|
|
|
|
|
memset(&bi, 0, sizeof(bi));
|
|
|
|
|
|
|
|
|
|
bi.lpszTitle = title.c_str();
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
selectedPath = buffer;
|
|
|
|
|
|
|
|
|
|
CoTaskMemFree(pIDL);
|
|
|
|
|
OleUninitialize();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace ARDOUR
|