From 6bdfbc05645e8775546cce4a4123362ea937927d Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 3 Nov 2015 22:00:15 +0100 Subject: [PATCH] Minor changes. --- src/config.cc | 8 ++-- src/config.h | 4 +- src/dialogs_win.cc | 97 +++++++++++++++++++++++----------------------- 3 files changed, 55 insertions(+), 54 deletions(-) diff --git a/src/config.cc b/src/config.cc index faac2ba..94f9552 100644 --- a/src/config.cc +++ b/src/config.cc @@ -80,8 +80,8 @@ void Config::retrieve_config() { for (auto &i : keybindings_pt) { menu.keys[i.first] = i.second.get_value(); } - GenerateSource(); - GenerateDirectoryFilter(); + get_source(); + get_directory_filter(); window.theme_name=cfg.get("gtk_theme.name"); window.theme_variant=cfg.get("gtk_theme.variant"); @@ -140,7 +140,7 @@ void Config::update_config_file() { } } -void Config::GenerateSource() { +void Config::get_source() { auto source_json = cfg.get_child("source"); source.style=source_json.get("style"); @@ -175,7 +175,7 @@ void Config::GenerateSource() { } } -void Config::GenerateDirectoryFilter() { +void Config::get_directory_filter() { boost::property_tree::ptree dir_json = cfg.get_child("directoryfilter"); boost::property_tree::ptree ignore_json = dir_json.get_child("ignore"); boost::property_tree::ptree except_json = dir_json.get_child("exceptions"); diff --git a/src/config.h b/src/config.h index 84886b4..71c9866 100644 --- a/src/config.h +++ b/src/config.h @@ -80,8 +80,8 @@ private: void retrieve_config(); bool check_config_file(const boost::property_tree::ptree &default_cfg, std::string parent_path=""); void update_config_file(); - void GenerateSource(); - void GenerateDirectoryFilter(); + void get_source(); + void get_directory_filter(); boost::property_tree::ptree cfg; boost::filesystem::path home; diff --git a/src/dialogs_win.cc b/src/dialogs_win.cc index 554cfd5..967ba67 100644 --- a/src/dialogs_win.cc +++ b/src/dialogs_win.cc @@ -17,56 +17,11 @@ class Win32Dialog { public: Win32Dialog() {}; - bool init(CLSID type) { - if(CoCreateInstance(type, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&dialog))!=S_OK) - return false; - if(dialog->GetOptions(&options)!=S_OK) - return false; - return true; - } - ~Win32Dialog() { if(dialog!=nullptr) dialog->Release(); } - /** available options are listed at https://msdn.microsoft.com/en-gb/library/windows/desktop/dn457282(v=vs.85).aspx */ - bool add_option(unsigned option) { - if(dialog->SetOptions(options | option)!=S_OK) - return false; - return true; - } - - bool set_title(const std::wstring &title) { - if(dialog->SetTitle(title.c_str())!=S_OK) - return false; - return true; - } - - /** Sets the extensions the browser can find */ - bool set_default_file_extension(const std::wstring &file_extension) { - if(dialog->SetDefaultExtension(file_extension.c_str())!=S_OK) - return false; - return true; - } - /** Sets the directory to start browsing */ - bool set_folder(const std::wstring &directory_path) { - std::wstring path=directory_path; - size_t pos=0; - while((pos=path.find(L'/', pos))!=std::wstring::npos) {//TODO: issue bug report on boost::filesystem::path::native on MSYS2 - path.replace(pos, 1, L"\\"); - pos++; - } - - IShellItem *folder = nullptr; - if(SHCreateItemFromParsingName(path.c_str(), nullptr, IID_PPV_ARGS(&folder))!=S_OK) - return false; - if(dialog->SetFolder(folder)!=S_OK) - return false; - folder->Release(); - return true; - } - /** Returns the selected item's path as a string */ std::string open(const std::wstring &title, unsigned option=0) { if(!init(CLSID_FileOpenDialog)) @@ -111,6 +66,55 @@ public: } private: + IFileDialog *dialog=nullptr; + DWORD options; + + bool init(CLSID type) { + if(CoCreateInstance(type, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&dialog))!=S_OK) + return false; + if(dialog->GetOptions(&options)!=S_OK) + return false; + return true; + } + + /** available options are listed at https://msdn.microsoft.com/en-gb/library/windows/desktop/dn457282(v=vs.85).aspx */ + bool add_option(unsigned option) { + if(dialog->SetOptions(options | option)!=S_OK) + return false; + return true; + } + + bool set_title(const std::wstring &title) { + if(dialog->SetTitle(title.c_str())!=S_OK) + return false; + return true; + } + + /** Sets the extensions the browser can find */ + bool set_default_file_extension(const std::wstring &file_extension) { + if(dialog->SetDefaultExtension(file_extension.c_str())!=S_OK) + return false; + return true; + } + + /** Sets the directory to start browsing */ + bool set_folder(const std::wstring &directory_path) { + std::wstring path=directory_path; + size_t pos=0; + while((pos=path.find(L'/', pos))!=std::wstring::npos) {//TODO: issue bug report on boost::filesystem::path::native on MSYS2 + path.replace(pos, 1, L"\\"); + pos++; + } + + IShellItem *folder = nullptr; + if(SHCreateItemFromParsingName(path.c_str(), nullptr, IID_PPV_ARGS(&folder))!=S_OK) + return false; + if(dialog->SetFolder(folder)!=S_OK) + return false; + folder->Release(); + return true; + } + std::string show() { if(dialog->Show(nullptr)!=S_OK) return ""; @@ -127,9 +131,6 @@ private: CoTaskMemFree(file_path); return file_path_string; } - - IFileDialog *dialog=nullptr; - DWORD options; }; std::string Dialog::open_folder() {