From fa94e468a70e86a688eeff7fd11d002d5956f83b Mon Sep 17 00:00:00 2001 From: Nikolay Polyanovskii Date: Wed, 21 May 2014 10:58:00 -0500 Subject: [PATCH] [SUMMARY] On OS Windows in new_session/open_session dialogs in case of not valid default_path set initial path on current user's home directory [Reviewed] GZharun [git-p4: depot-paths = "//Abdaw/dev_main/tracks/": change = 462434] --- gtk2_ardour/OpenFileDialog.cc | 32 ++++++++++++++++++++--- gtk2_ardour/OpenFileDialogProxy.h | 2 +- gtk2_ardour/tracks_control_panel.logic.cc | 3 ++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/gtk2_ardour/OpenFileDialog.cc b/gtk2_ardour/OpenFileDialog.cc index 6bb5569ff8..b373fe5d3c 100644 --- a/gtk2_ardour/OpenFileDialog.cc +++ b/gtk2_ardour/OpenFileDialog.cc @@ -8,6 +8,8 @@ #include +#include "glibmm/miscutils.h" + using namespace std; namespace ARDOUR { @@ -21,8 +23,19 @@ bool SaveFileDialog(std::string& fileName, std::string path, std::string title) ofn.lpstrTitle = title.c_str(); ofn.Flags = OFN_OVERWRITEPROMPT; - if( !path.empty() ) + // 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(); + ofn.lpstrInitialDir = path.c_str(); + } // Run dialog if(GetSaveFileName(&ofn)) @@ -44,8 +57,19 @@ bool OpenFileDialog(std::string& fileName, std::string path, std::string title) ofn.lpstrTitle = title.c_str(); ofn.Flags = OFN_PATHMUSTEXIST; - if( !path.empty() ) + // 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(); + ofn.lpstrInitialDir = path.c_str(); + } if( GetOpenFileName(&ofn) ) { @@ -56,7 +80,7 @@ bool OpenFileDialog(std::string& fileName, std::string path, std::string title) return false; } -bool ChooseFolderDialog(std::string& selectedPath, std::string title) +bool ChooseFolderDialog(std::string& selectedPath, std::string path, std::string title) { BROWSEINFO bi; memset(&bi, 0, sizeof(bi)); @@ -66,7 +90,7 @@ bool ChooseFolderDialog(std::string& selectedPath, std::string title) OleInitialize(NULL); LPITEMIDLIST pIDL = SHBrowseForFolder(&bi); - + if (pIDL == NULL) { return false; diff --git a/gtk2_ardour/OpenFileDialogProxy.h b/gtk2_ardour/OpenFileDialogProxy.h index 6bbe310932..c1da67ac7c 100644 --- a/gtk2_ardour/OpenFileDialogProxy.h +++ b/gtk2_ardour/OpenFileDialogProxy.h @@ -25,7 +25,7 @@ namespace ARDOUR #ifdef _WIN32 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"); + bool ChooseFolderDialog(std::string& selectedPath, std::string path = "", std::string title = "Choose Folder"); #endif } #endif diff --git a/gtk2_ardour/tracks_control_panel.logic.cc b/gtk2_ardour/tracks_control_panel.logic.cc index 1794b5d41d..3b0370a57d 100644 --- a/gtk2_ardour/tracks_control_panel.logic.cc +++ b/gtk2_ardour/tracks_control_panel.logic.cc @@ -592,7 +592,8 @@ TracksControlPanel::on_brows_button (WavesButton*) #ifdef _WIN32 set_keep_above(false); string fileTitle; - if ( ARDOUR::ChooseFolderDialog(fileTitle, _("Choose Default Path")) ) { + // if path was chosen in dialog + if ( ARDOUR::ChooseFolderDialog(fileTitle, Config->get_default_open_path(), _("Choose Default Path")) ) { set_keep_above(true); _default_path_name = fileTitle; }