Browse Source

Intermediate commit, please ignore

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

3
src/CMakeLists.txt

@ -28,7 +28,8 @@ find_package(LibClang REQUIRED)
#find_package(PythonLibs 2.7)
#find_package(Boost 1.55 COMPONENTS python thread log system filesystem REQUIRED)
find_package(Boost 1.55 COMPONENTS thread log system filesystem REQUIRED)
find_package(Boost 1.55 COMPONENTS thread log system filesystem locale REQUIRED)
pkg_check_modules(GTKMM gtkmm-3.0 REQUIRED) # The name GTKMM is set here for the variables abouve

12
src/dialogs.h

@ -21,6 +21,7 @@ class Dialog {
#include <memory>
#include <sstream>
#include <codecvt>
#include <vector>
class WinString {
public:
@ -29,10 +30,11 @@ public:
~WinString() { CoTaskMemFree(static_cast<void*>(str)); }
std::string operator()();
wchar_t** operator&() { return &str; }
static std::wstring s2ws(const std::string& str);
static std::string ws2s(const std::wstring& wstr);
private:
wchar_t* str;
std::wstring s2ws(const std::string& str);
std::string ws2s(const std::wstring& wstr);
};
class CommonDialog {
@ -42,7 +44,7 @@ public:
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<std::string> file_extensions);
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 */
@ -55,11 +57,11 @@ private:
class OpenDialog : public CommonDialog {
public:
OpenDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileOpenDialog);
OpenDialog(const std::string &title, unsigned option);
};
class SaveDialog : public CommonDialog {
public:
SaveDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileSaveDialog);
SaveDialog(const std::string &title, unsigned option);
};
#endif // __WIN32

28
src/dialogs_win.cc

@ -1,7 +1,7 @@
#ifdef _WIN32
#include "dialogs.h"
#include "singletons.h"
#include <boost/locale.hpp>
#ifndef check
HRESULT __hr__;
#define check(__fun__, error_message) \
@ -29,17 +29,12 @@ std::string WinString::operator()() {
return res;
}
// http://stackoverflow.com/questions/4804298/how-to-convert-wstring-into-string
std::wstring WinString::s2ws(const std::string& str) {
typedef std::codecvt_utf8<wchar_t> convert_typeX;
std::wstring_convert<convert_typeX, wchar_t> converterX;
return converterX.from_bytes(str);
return boost::locale::conv::utf_to_utf<wchar_t>(str);
}
std::string WinString::ws2s(const std::wstring& wstr) {
typedef std::codecvt_utf8<wchar_t> convert_typeX;
std::wstring_convert<convert_typeX, wchar_t> converterX;
return converterX.to_bytes(wstr);
return boost::locale::conv::utf_to_utf<char>(wstr);
}
// WINSTRING }
@ -51,9 +46,7 @@ CommonDialog::CommonDialog(CLSID type) : dialog(nullptr) {
}
void CommonDialog::set_title(const std::string &title) {
auto tmp = std::wstring(title.begin(), title.end());
auto t = tmp.data();
check(dialog->SetTitle(t), "Failed to set dialog title");
check(dialog->SetTitle(), "Failed to set dialog title");
}
void CommonDialog::add_option(unsigned option) {
@ -65,10 +58,11 @@ void CommonDialog::set_file_extensions(const std::vector<std::string> &file_exte
}
void CommonDialog::set_default_folder(const std::string &directory_path) {
std::cout << directory_path << std::endl;
IShellItem * folder = nullptr;
WinString str;
&str = (str.s2ws(directory_path)).data();
check(SHCreateItemFromParsingName(&str, NULL, IID_PPV_ARGS(&folder)), "Failed to create string");
auto dir = WinString::s2ws(directory_path);
std::wcout << dir << std::endl;
check(SHCreateItemFromParsingName(dir.data(), nullptr, IID_PPV_ARGS(&folder)), "Failed to create string");
check(dialog->SetDefaultFolder(folder), "Failed to set default folder");
folder->Release();
}
@ -87,18 +81,18 @@ std::string CommonDialog::show() {
}
}
OpenDialog::OpenDialog(const std::string &title, unsigned option) : CommonDialog(CLSID_FileOpenDialog); {
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);
set_default_folder(dirs.empty() ? boost::filesystem::current_path().string() : dirs.string());
}
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);
set_default_folder(dirs.empty() ? boost::filesystem::current_path().string() : dirs.string());
}
// DIALOGS }}

Loading…
Cancel
Save