From daaa1a958e69e83cf84fa74093be52658a06ee0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Sun, 1 Nov 2015 20:24:39 +0100 Subject: [PATCH] Attempt to set default folder for win dialogs --- src/CMakeLists.txt | 2 ++ src/dialogs.h | 18 +++++++++--------- src/dialogs_win.cc | 30 +++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2da1c6f..e66417f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -106,6 +106,7 @@ include_directories( ${LIBCLANG_INCLUDE_DIRS} ${ASPELL_INCLUDE_DIR} ../libclangmm/src + "/usr/x86_64-w64-mingw32/include" ) link_directories( @@ -114,6 +115,7 @@ link_directories( ${Boost_LIBRARY_DIRS} # ${PYTHON_INCLUDE_DIRS} ${LIBCLANG_LIBRARY_DIRS} + "/usr/x86_64-w64-mingw32/lib" ) # set_target_properties(${module} diff --git a/src/dialogs.h b/src/dialogs.h index 086a93b..92638f5 100644 --- a/src/dialogs.h +++ b/src/dialogs.h @@ -38,8 +38,14 @@ private: class CommonDialog { public: CommonDialog(CLSID type); + /** available options are listed https://msdn.microsoft.com/en-gb/library/windows/desktop/dn457282(v=vs.85).aspx */ void add_option(unsigned option); void set_title(const std::string &title); + /** Sets the extensions the browser can find */ + void set_file_extensions(const std::vector file_extensions); + /** Sets the directory to start browsing */ + void set_default_folder(const std::string &directory_path); + /** Returns the selected item's path as a string */ std::string show(); private: @@ -49,18 +55,12 @@ private: class OpenDialog : public CommonDialog { public: - OpenDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileOpenDialog) { - set_title(title); - add_option(option); - } + OpenDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileOpenDialog); }; - class SaveDialog : public CommonDialog { public: - SaveDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileSaveDialog) { - set_title(title); - add_option(option); - } + SaveDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileSaveDialog); }; + #endif // __WIN32 #endif // JUCI_DIALOG_H_ diff --git a/src/dialogs_win.cc b/src/dialogs_win.cc index d7b2791..22db8fa 100644 --- a/src/dialogs_win.cc +++ b/src/dialogs_win.cc @@ -60,6 +60,19 @@ void CommonDialog::add_option(unsigned option) { check(dialog->SetOptions(options | option), "Failed to set options"); } +void CommonDialog::set_file_extensions(const std::vector &file_extensions) { + return; +} + +void CommonDialog::set_default_folder(const std::string &directory_path) { + IShellItem * folder = nullptr; + WinString str; + &str = (str.s2ws(directory_path)).data(); + check(SHCreateItemFromParsingName(&str, NULL, IID_PPV_ARGS(&folder)), "Failed to create string"); + check(dialog->SetDefaultFolder(folder), "Failed to set default folder"); + folder->Release(); +} + std::string CommonDialog::show() { try { check(dialog->Show(nullptr), "Failed to show dialog"); @@ -73,7 +86,22 @@ std::string CommonDialog::show() { return ""; } } -// COMMON_DIALOG }} + +OpenDialog::OpenDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileOpenDialog); { + set_title(title); + add_option(option); + auto dirs = Singleton::directories()->current_path; + set_default_folder(dirs.empty() ? boost::filesystem::current_path() : dirs); +} + +SaveDialog::SaveDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileSaveDialog) { + set_title(title); + add_option(option); + auto dirs = Singleton::directories()->current_path; + set_default_folder(dirs.empty() ? boost::filesystem::current_path() : dirs); +} + +// DIALOGS }} std::string Dialog::select_folder() { return (OpenDialog("Select folder", FOS_PICKFOLDERS)).show(); }