From 41a72dbecf3de7513aec0c46e4d9491d75c714af Mon Sep 17 00:00:00 2001 From: Nikolay Polyanovskii Date: Wed, 21 May 2014 08:27:14 -0500 Subject: [PATCH] [Summary] choose default save/open folder on Windows [Review] GZharun [git-p4: depot-paths = "//Abdaw/dev_main/tracks/": change = 462392] --- gtk2_ardour/OpenFileDialog.cc | 51 +++++++++++++++++++---- gtk2_ardour/OpenFileDialogProxy.h | 6 +-- gtk2_ardour/session_dialog.logic.cc | 4 +- gtk2_ardour/tracks_control_panel.logic.cc | 18 ++++---- gtk2_ardour/wscript | 2 +- 5 files changed, 59 insertions(+), 22 deletions(-) diff --git a/gtk2_ardour/OpenFileDialog.cc b/gtk2_ardour/OpenFileDialog.cc index 7817709cde..6bb5569ff8 100644 --- a/gtk2_ardour/OpenFileDialog.cc +++ b/gtk2_ardour/OpenFileDialog.cc @@ -1,16 +1,17 @@ #include "OpenFileDialogProxy.h" -#include - -#ifdef _WIN32 #include #include -#endif +#include + +#include + +#include using namespace std; namespace ARDOUR { -bool SaveFileDialog(std::string& fileName, std::string title) +bool SaveFileDialog(std::string& fileName, std::string path, std::string title) { TCHAR szFilePathName[_MAX_PATH] = ""; OPENFILENAME ofn = {0}; @@ -20,6 +21,10 @@ bool SaveFileDialog(std::string& fileName, std::string title) ofn.lpstrTitle = title.c_str(); ofn.Flags = OFN_OVERWRITEPROMPT; + if( !path.empty() ) + ofn.lpstrInitialDir = path.c_str(); + + // Run dialog if(GetSaveFileName(&ofn)) { fileName = ofn.lpstrFile; @@ -29,7 +34,7 @@ bool SaveFileDialog(std::string& fileName, std::string title) return false; } -bool OpenFileDialog(std::string& fileName, std::string title) +bool OpenFileDialog(std::string& fileName, std::string path, std::string title) { TCHAR szFilePathName[_MAX_PATH] = ""; OPENFILENAME ofn = {0}; @@ -39,6 +44,9 @@ bool OpenFileDialog(std::string& fileName, std::string title) ofn.lpstrTitle = title.c_str(); ofn.Flags = OFN_PATHMUSTEXIST; + if( !path.empty() ) + ofn.lpstrInitialDir = path.c_str(); + if( GetOpenFileName(&ofn) ) { fileName = ofn.lpstrFile; @@ -48,4 +56,33 @@ bool OpenFileDialog(std::string& fileName, std::string title) return false; } -} \ No newline at end of file +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 \ No newline at end of file diff --git a/gtk2_ardour/OpenFileDialogProxy.h b/gtk2_ardour/OpenFileDialogProxy.h index 9711fc07c8..6bbe310932 100644 --- a/gtk2_ardour/OpenFileDialogProxy.h +++ b/gtk2_ardour/OpenFileDialogProxy.h @@ -23,9 +23,9 @@ namespace ARDOUR // OS Windows specific functions #ifdef _WIN32 - bool SaveFileDialog(std::string& fileName, std::string title = "Save"); - bool OpenFileDialog(std::string& fileName, std::string title = "Open"); - bool ChooseFolderDialog(std::string& fileName, std::string title = "Choose Folder"); + bool SaveFileDialog(std::string& fileName, std::string path = "", std::string title = "Save"); + bool OpenFileDialog(std::string& fileName, std::string path = "", std::string title = "Open"); + bool ChooseFolderDialog(std::string& selectedPath, std::string title = "Choose Folder"); #endif } #endif diff --git a/gtk2_ardour/session_dialog.logic.cc b/gtk2_ardour/session_dialog.logic.cc index 35bca5e928..65e7fc1af1 100644 --- a/gtk2_ardour/session_dialog.logic.cc +++ b/gtk2_ardour/session_dialog.logic.cc @@ -163,7 +163,7 @@ SessionDialog::on_new_session (WavesButton*) set_keep_above(false); string fileTitle; // Open the file save dialog, and choose the file name - if ( ARDOUR::SaveFileDialog(fileTitle, _("Create New Session")) ) { + if ( ARDOUR::SaveFileDialog(fileTitle, Config->get_default_open_path(), _("Create New Session")) ) { set_keep_above(true); _selected_session_full_name = fileTitle; for (size_t i = 0; i < MAX_RECENT_SESSION_COUNTS; i++) { @@ -344,7 +344,7 @@ SessionDialog::on_open_saved_session (WavesButton*) set_keep_above(false); // Open the file save dialog, and choose the file name string fileName; - if (OpenFileDialog(fileName, _("Select Saved Session"))) { + if (OpenFileDialog(fileName, Config->get_default_open_path(), _("Select Saved Session"))) { set_keep_above(true); _selected_session_full_name = fileName; for (size_t i = 0; i < MAX_RECENT_SESSION_COUNTS; i++) { diff --git a/gtk2_ardour/tracks_control_panel.logic.cc b/gtk2_ardour/tracks_control_panel.logic.cc index 3be556f9bc..1794b5d41d 100644 --- a/gtk2_ardour/tracks_control_panel.logic.cc +++ b/gtk2_ardour/tracks_control_panel.logic.cc @@ -411,14 +411,19 @@ void TracksControlPanel::device_changed (bool show_confirm_dial/*=true*/) msg.set_position (Gtk::WIN_POS_MOUSE); + set_keep_above(false); + switch (msg.run()) { case RESPONSE_NO: // set _ignore_changes flag to ignore changes in combo-box callbacks PBD::Unwinder protect_ignore_changes (_ignore_changes, _ignore_changes + 1); _device_combo.set_active_text (EngineStateController::instance()->get_current_device_name()); + set_keep_above(true); return; - } + } + + set_keep_above(true); } if (EngineStateController::instance()->set_new_device_as_current(device_name) ) @@ -585,23 +590,18 @@ TracksControlPanel::on_brows_button (WavesButton*) #endif #ifdef _WIN32 - /*set_keep_above(false); + set_keep_above(false); string fileTitle; - if ( ARDOUR::OpenFileDialog(fileTitle, _("Choose Default Path")) ) { + if ( ARDOUR::ChooseFolderDialog(fileTitle, _("Choose Default Path")) ) { set_keep_above(true); _default_path_name = fileTitle; } - - using namespace std; - cout<get_default_open_path()); - */ + return; #endif // _WIN32 } diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index a4307a3b73..d84b556ab7 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -459,7 +459,7 @@ def build(bld): obj.source += [ 'cocoacarbon.mm', 'bundle_env_cocoa.cc' ] elif bld.env['build_target'] == 'mingw': obj.source += [ 'bundle_env_mingw.cc' ] - obj.lib = 'comdlg32' + obj.lib = 'comdlg32 Shell32' else: obj.source += [ 'bundle_env_linux.cc' ]