Browse Source

Change implementation to Vista and up

merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
9df5547505
  1. 39
      src/dialogs_win.cc

39
src/dialogs_win.cc

@ -1,33 +1,26 @@
#include "dialogs.h" #include "dialogs.h"
#include <windows.h> #include <shobjidl.h>
#include <shlobj.h> #include <memory>
#include <exception>
#include <singletons.h>
#ifndef check(__fun__)
#define MESSAGE "An error occurred when trying open windows dialog"
#define check(__fun__) auto __hr__ = __fun__; if(FAILED(__hr__)) Singleton::terminal()->print(MESSAGE)
#endif
std::string Dialog::select_folder() { std::string Dialog::select_folder() {
char selected_folder[MAX_PATH]; IFileOpenDialog *dialog = nullptr;
char init_path[MAX_PATH]; check(CoCreateInstance(CLSID_FileOpenDialog, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&dialog)));
auto title = "Please select a folder"; DWORD options;
selected_folder[0] = 0; check(dialog->GetOptions(&options));
init_path[0] = 0;
BROWSEINFOA browse;
browse.hwndOwner = 0;
browse.pidlRoot = NULL;
browse.lpszTitle = title;
browse.pszDisplayName = init_path;
browse.ulFlags = 0;
browse.lpfn = NULL;
auto result = SHBrowseForFolder(&browse);
if(result)
SHGetPathFromIDListA(result, selected_folder);
std::string dir(selected_folder);
return dir;
} }
/* /*
std::string Dialog::new_file() { std::string Dialog::new_file() {
return open_dialog("Please create a new file", return open_dialog("Please create a new file",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL), std::make_pair("Save", Gtk::RESPONSE_OK)}, {std::make_pair("Cancel", Gtk::RESPONSECANCEL), std::make_pair("Save", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_SAVE); Gtk::FILE_CHOOSER_ACTION_SAVE);
} }

Loading…
Cancel
Save