Browse Source

Vista implementation of pick folder

merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
ddeeb19989
  1. 6
      src/CMakeLists.txt
  2. 81
      src/dialogs_win.cc

6
src/CMakeLists.txt

@ -93,18 +93,18 @@ set(source_files juci.h
cmake.cc)
if(MSYS)
list(APPEND source_files terminal_win.cc dialogs_win.cc)
list(APPEND source_files terminal_win.cc)
list(APPEND source_files dialogs_win.cc)
message("MSYS detected")
else()
list(APPEND source_files terminal.cc dialogs.cc)
list(APPEND source_files terminal.cc)
list(APPEND source_files dialogs.cc)
message("UNIX detected")
endif()
if(${validation})
add_executable(${project_name} ${source_files})
# add_library(${module} SHARED
# api
# api_ext)

81
src/dialogs_win.cc

@ -1,45 +1,78 @@
#include "dialogs.h"
#include <windows.h>
#include <shobjidl.h>
#include <memory>
#include <exception>
#include <singletons.h>
#include "singletons.h"
#include <sstream>
#ifndef check(__fun__)
#ifndef check
#define MESSAGE "An error occurred when trying open windows dialog"
#define check(__fun__) auto __hr__ = __fun__; if(FAILED(__hr__)) Singleton::terminal()->print(MESSAGE)
HRESULT __hr__;
#define check(__fun__) __hr__ = __fun__; if(FAILED(__hr__)) Singleton::terminal()->print(MESSAGE)
#endif
class win_string {
public:
win_string() : str(nullptr) { }
~win_string() { CoTaskMemFree(static_cast<void*>(str)); }
std::string operator()(){
std::string res;
if (str != nullptr) {
std::wstringstream ss;
ss << str;
res = std::string(ss.str().begin(), ss.str().end());
}
return res;
}
wchar_t** operator&() { return &str; }
private:
wchar_t* str;
};
std::string Dialog::select_folder() {
IFileOpenDialog *dialog = nullptr;
check(CoCreateInstance(CLSID_FileOpenDialog, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&dialog)));
DWORD options;
check(dialog->GetOptions(&options));
class CommonDialog {
public:
CommonDialog() : dialog(nullptr) {
check(CoCreateInstance(CLSID_FileOpenDialog, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&dialog)));
check(dialog->GetOptions(&options));
}
CommonDialog(const std::string &title, unsigned option) : CommonDialog() {
set_title(title);
add_option(option);
}
void set_title(const std::string &title) { check(dialog->SetTitle(title)); }
void add_option(unsigned option) { check(dialog->SetOptions(options | option)); }
std::string show() {
check(dialog->Show(nullptr));
IShellItem *result = nullptr;
check(dialog->GetResult(&result));
win_string str;
check(result->GetDisplayName(SIGDN_FILESYSPATH, &str));;
result->Release();
return str();
}
private:
IFileOpenDialog * dialog;
DWORD options;
};
std::string Dialog::select_folder() {
return (CommonDialog("Please select a folder", FOS_PICKFOLDERS)).show();
}
/*
std::string Dialog::new_file() {
return open_dialog("Please create a new file",
{std::make_pair("Cancel", Gtk::RESPONSECANCEL), std::make_pair("Save", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_SAVE);
return (CommonDialog("Please select a folder", FOS_PICKFOLDERS)).show();
}
std::string Dialog::new_folder() {
return open_dialog("Please create a new folder",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Create", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER);
return (CommonDialog("Please select a folder", FOS_PICKFOLDERS)).show();
}
std::string Dialog::select_file() {
return open_dialog("Please choose a folder",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Select", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_OPEN);
return (CommonDialog("Please select a folder", FOS_PICKFOLDERS)).show();
}
std::string Dialog::save_file() {
return open_dialog("Please choose a file",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Save", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_OPEN);
}
*/
return (CommonDialog("Please select a folder", FOS_PICKFOLDERS)).show();
}
Loading…
Cancel
Save