Browse Source

Minor changes.

merge-requests/365/head
eidheim 10 years ago
parent
commit
6bdfbc0564
  1. 8
      src/config.cc
  2. 4
      src/config.h
  3. 97
      src/dialogs_win.cc

8
src/config.cc

@ -80,8 +80,8 @@ void Config::retrieve_config() {
for (auto &i : keybindings_pt) { for (auto &i : keybindings_pt) {
menu.keys[i.first] = i.second.get_value<std::string>(); menu.keys[i.first] = i.second.get_value<std::string>();
} }
GenerateSource(); get_source();
GenerateDirectoryFilter(); get_directory_filter();
window.theme_name=cfg.get<std::string>("gtk_theme.name"); window.theme_name=cfg.get<std::string>("gtk_theme.name");
window.theme_variant=cfg.get<std::string>("gtk_theme.variant"); window.theme_variant=cfg.get<std::string>("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"); auto source_json = cfg.get_child("source");
source.style=source_json.get<std::string>("style"); source.style=source_json.get<std::string>("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 dir_json = cfg.get_child("directoryfilter");
boost::property_tree::ptree ignore_json = dir_json.get_child("ignore"); boost::property_tree::ptree ignore_json = dir_json.get_child("ignore");
boost::property_tree::ptree except_json = dir_json.get_child("exceptions"); boost::property_tree::ptree except_json = dir_json.get_child("exceptions");

4
src/config.h

@ -80,8 +80,8 @@ private:
void retrieve_config(); void retrieve_config();
bool check_config_file(const boost::property_tree::ptree &default_cfg, std::string parent_path=""); bool check_config_file(const boost::property_tree::ptree &default_cfg, std::string parent_path="");
void update_config_file(); void update_config_file();
void GenerateSource(); void get_source();
void GenerateDirectoryFilter(); void get_directory_filter();
boost::property_tree::ptree cfg; boost::property_tree::ptree cfg;
boost::filesystem::path home; boost::filesystem::path home;

97
src/dialogs_win.cc

@ -17,56 +17,11 @@ class Win32Dialog {
public: public:
Win32Dialog() {}; 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() { ~Win32Dialog() {
if(dialog!=nullptr) if(dialog!=nullptr)
dialog->Release(); 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 */ /** Returns the selected item's path as a string */
std::string open(const std::wstring &title, unsigned option=0) { std::string open(const std::wstring &title, unsigned option=0) {
if(!init(CLSID_FileOpenDialog)) if(!init(CLSID_FileOpenDialog))
@ -111,6 +66,55 @@ public:
} }
private: 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() { std::string show() {
if(dialog->Show(nullptr)!=S_OK) if(dialog->Show(nullptr)!=S_OK)
return ""; return "";
@ -127,9 +131,6 @@ private:
CoTaskMemFree(file_path); CoTaskMemFree(file_path);
return file_path_string; return file_path_string;
} }
IFileDialog *dialog=nullptr;
DWORD options;
}; };
std::string Dialog::open_folder() { std::string Dialog::open_folder() {

Loading…
Cancel
Save