Skip to content

Commit

Permalink
Add new FolderChooserChoice
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Dec 29, 2023
1 parent e6bc3d8 commit 74a33ab
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Common/UI/PopupScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions Common/UI/PopupScreens.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 74a33ab

Please sign in to comment.