Add new FolderChooserChoice

This commit is contained in:
Henrik Rydgård 2023-12-29 01:13:37 +01:00
parent e6bc3d83f8
commit 74a33ab98d
2 changed files with 37 additions and 0 deletions

View File

@ -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

View File

@ -436,4 +436,17 @@ private:
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