Browse Source

Attempt to set default folder for win dialogs

merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
daaa1a958e
  1. 2
      src/CMakeLists.txt
  2. 18
      src/dialogs.h
  3. 30
      src/dialogs_win.cc

2
src/CMakeLists.txt

@ -106,6 +106,7 @@ include_directories(
${LIBCLANG_INCLUDE_DIRS} ${LIBCLANG_INCLUDE_DIRS}
${ASPELL_INCLUDE_DIR} ${ASPELL_INCLUDE_DIR}
../libclangmm/src ../libclangmm/src
"/usr/x86_64-w64-mingw32/include"
) )
link_directories( link_directories(
@ -114,6 +115,7 @@ link_directories(
${Boost_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS}
# ${PYTHON_INCLUDE_DIRS} # ${PYTHON_INCLUDE_DIRS}
${LIBCLANG_LIBRARY_DIRS} ${LIBCLANG_LIBRARY_DIRS}
"/usr/x86_64-w64-mingw32/lib"
) )
# set_target_properties(${module} # set_target_properties(${module}

18
src/dialogs.h

@ -38,8 +38,14 @@ private:
class CommonDialog { class CommonDialog {
public: public:
CommonDialog(CLSID type); 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 add_option(unsigned option);
void set_title(const std::string &title); void set_title(const std::string &title);
/** Sets the extensions the browser can find */
void set_file_extensions(const std::vector<std::string> 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(); std::string show();
private: private:
@ -49,18 +55,12 @@ private:
class OpenDialog : public CommonDialog { class OpenDialog : public CommonDialog {
public: public:
OpenDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileOpenDialog) { OpenDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileOpenDialog);
set_title(title);
add_option(option);
}
}; };
class SaveDialog : public CommonDialog { class SaveDialog : public CommonDialog {
public: public:
SaveDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileSaveDialog) { SaveDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileSaveDialog);
set_title(title);
add_option(option);
}
}; };
#endif // __WIN32 #endif // __WIN32
#endif // JUCI_DIALOG_H_ #endif // JUCI_DIALOG_H_

30
src/dialogs_win.cc

@ -60,6 +60,19 @@ void CommonDialog::add_option(unsigned option) {
check(dialog->SetOptions(options | option), "Failed to set options"); check(dialog->SetOptions(options | option), "Failed to set options");
} }
void CommonDialog::set_file_extensions(const std::vector<std::string> &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() { std::string CommonDialog::show() {
try { try {
check(dialog->Show(nullptr), "Failed to show dialog"); check(dialog->Show(nullptr), "Failed to show dialog");
@ -73,7 +86,22 @@ std::string CommonDialog::show() {
return ""; 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() { std::string Dialog::select_folder() {
return (OpenDialog("Select folder", FOS_PICKFOLDERS)).show(); return (OpenDialog("Select folder", FOS_PICKFOLDERS)).show();
} }

Loading…
Cancel
Save