mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-05-09 12:24:04 -05:00
DolphinQt: Add an optional default value to ConfigUserPath constructor
The optional default value is used to implement `ConfigUserPath::Reset()`. Since `ConfigUserPath` must not be empty, there was no easy way to reset these paths to their default value. With this change users of `ConfigUserPath` can now set the default path. At the moment users of `ConfigUserPath` must place a reset button and connect a callback to `ConfigUserPath::Reset` on their own.
This commit is contained in:
parent
296e81a8a3
commit
514beb2081
|
|
@ -13,13 +13,21 @@
|
|||
|
||||
ConfigUserPath::ConfigUserPath(const unsigned int dir_index,
|
||||
const Config::Info<std::string>& setting)
|
||||
: ConfigUserPath(dir_index, setting, nullptr)
|
||||
: ConfigUserPath(dir_index, setting, "", nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
ConfigUserPath::ConfigUserPath(const unsigned int dir_index,
|
||||
const Config::Info<std::string>& setting, Config::Layer* layer)
|
||||
: ConfigText(setting, layer), m_dir_index(dir_index)
|
||||
const Config::Info<std::string>& setting,
|
||||
const std::string default_value)
|
||||
: ConfigUserPath(dir_index, setting, default_value, nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
ConfigUserPath::ConfigUserPath(const unsigned int dir_index,
|
||||
const Config::Info<std::string>& setting,
|
||||
const std::string default_value, Config::Layer* layer)
|
||||
: ConfigText(setting, layer), m_dir_index(dir_index), m_default_value(default_value)
|
||||
{
|
||||
OnConfigChanged();
|
||||
|
||||
|
|
@ -57,3 +65,14 @@ void ConfigUserPath::OnConfigChanged()
|
|||
{
|
||||
RefreshText();
|
||||
}
|
||||
|
||||
void ConfigUserPath::Reset()
|
||||
{
|
||||
if (m_default_value.empty())
|
||||
return;
|
||||
|
||||
File::SetUserPath(m_dir_index, m_default_value);
|
||||
SaveValue(m_setting, m_default_value);
|
||||
|
||||
RefreshText();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,10 @@ class ConfigUserPath final : public ConfigText
|
|||
public:
|
||||
ConfigUserPath(const unsigned int dir_index, const Config::Info<std::string>& setting);
|
||||
ConfigUserPath(const unsigned int dir_index, const Config::Info<std::string>& setting,
|
||||
Config::Layer* layer);
|
||||
std::string default_value);
|
||||
ConfigUserPath(const unsigned int dir_index, const Config::Info<std::string>& setting,
|
||||
std::string default_value, Config::Layer* layer);
|
||||
void Reset();
|
||||
|
||||
protected:
|
||||
void OnConfigChanged() override;
|
||||
|
|
@ -25,4 +28,5 @@ private:
|
|||
void Update();
|
||||
|
||||
const unsigned int m_dir_index;
|
||||
const std::string m_default_value;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user