diff --git a/libs/ui/source/file_dialog.cpp b/libs/ui/source/file_dialog.cpp index 6e995f5b..df52ec10 100644 --- a/libs/ui/source/file_dialog.cpp +++ b/libs/ui/source/file_dialog.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include @@ -145,6 +147,17 @@ namespace psemek::ui auto common_paths_label = options.element_factory.make_label(""); + auto common_paths = util::to_shared(util::common_directories()); + { + std::string str; + int index = 0; + for (auto const & dir : *common_paths) + { + str += util::to_string("[link:", index++, "]", escape(dir.first), "[/link]\n"); + } + common_paths_label->set_tagged_text(str); + } + auto current_path_label = options.element_factory.make_label(""); current_path_label->set_valign(label::valignment::center); @@ -321,6 +334,10 @@ namespace psemek::ui } }; + common_paths_label->on_link_click([common_paths, set_path_callback](std::string const & link){ + int index = util::from_string(link); + (*set_path_callback)((*common_paths)[index].second); + }); path_edit->on_text_changed([=](std::u32string_view const & text_u32){ std::string text = util::to_utf8(std::u32string(text_u32)); diff --git a/libs/util/include/psemek/util/common_directories.hpp b/libs/util/include/psemek/util/common_directories.hpp new file mode 100644 index 00000000..feefc955 --- /dev/null +++ b/libs/util/include/psemek/util/common_directories.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +namespace psemek::util +{ + + std::vector> common_directories(); + +} diff --git a/libs/util/source/common_directories.cpp b/libs/util/source/common_directories.cpp new file mode 100644 index 00000000..933a194e --- /dev/null +++ b/libs/util/source/common_directories.cpp @@ -0,0 +1,51 @@ +#include + +#include + +#ifdef _WIN32 +#include +#endif + +namespace psemek::util +{ + + std::vector> common_directories() + { + std::vector> result; + +#ifdef __linux__ + { + std::filesystem::path path = std::getenv("HOME"); + if (!path.empty()) + result.push_back({"Home", path}); + } + + result.push_back({"Root", "/"}); +#endif + +#ifdef _WIN32 + { + std::filesystem::path path = std::getenv("USERPROFILE"); + if (!path.empty()) + result.push_back({"Home", path}); + } + + { + auto drives = GetLogicalDrives(); + for (int i = 0; i < 26; ++i) + { + if ((drives & (1 << i)) == 0) continue; + + char name[3] = "A:"; + char path[4] = "A:\\"; + name[0] = 'A' + i; + path[0] = name[0]; + result.push_back({name, path}); + } + } +#endif + + return result; + } + +}