From 74a33ab98d674e50b81932bf6e594f67b2007103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 29 Dec 2023 01:13:37 +0100 Subject: [PATCH] Add new FolderChooserChoice --- Common/UI/PopupScreens.cpp | 24 ++++++++++++++++++++++++ Common/UI/PopupScreens.h | 13 +++++++++++++ 2 files changed, 37 insertions(+) diff --git a/Common/UI/PopupScreens.cpp b/Common/UI/PopupScreens.cpp index d1b1f1abbe8f..4e056573a22d 100644 --- a/Common/UI/PopupScreens.cpp +++ b/Common/UI/PopupScreens.cpp @@ -692,4 +692,28 @@ std::string FileChooserChoice::ValueText() const { return path.GetFilename(); } +FolderChooserChoice::FolderChooserChoice(std::string *value, const std::string &text, LayoutParams *layoutParams) + : AbstractChoiceWithValueDisplay(text, layoutParams), value_(value) { + OnClick.Add([=](UI::EventParams &) { + System_BrowseForFolder(text_, [=](const std::string &returnValue, int) { + if (*value_ != returnValue) { + *value = returnValue; + UI::EventParams e{}; + e.s = *value; + OnChange.Trigger(e); + } + }); + return UI::EVENT_DONE; + }); +} + +std::string FolderChooserChoice::ValueText() const { + if (value_->empty()) { + auto di = GetI18NCategory(I18NCat::DIALOG); + return di->T("Default"); + } + Path path(*value_); + return path.GetFilename(); +} + } // namespace diff --git a/Common/UI/PopupScreens.h b/Common/UI/PopupScreens.h index 5acfad8d73c2..8e237bca2329 100644 --- a/Common/UI/PopupScreens.h +++ b/Common/UI/PopupScreens.h @@ -436,4 +436,17 @@ class FileChooserChoice : public AbstractChoiceWithValueDisplay { BrowseFileType fileType_; }; +class FolderChooserChoice : public AbstractChoiceWithValueDisplay { +public: + FolderChooserChoice(std::string *value, const std::string &title, LayoutParams *layoutParams = nullptr); + std::string ValueText() const override; + + Event OnChange; + +private: + std::string *value_; + BrowseFileType fileType_; +}; + + } // namespace UI