mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-19 02:36:27 +01:00
Common/Config: Add a utility class to suppress config change callbacks.
This commit is contained in:
parent
2a3c075330
commit
bbc6bf5294
@ -12,6 +12,7 @@ namespace Config
|
|||||||
{
|
{
|
||||||
static Layers s_layers;
|
static Layers s_layers;
|
||||||
static std::list<ConfigChangedCallback> s_callbacks;
|
static std::list<ConfigChangedCallback> s_callbacks;
|
||||||
|
static u32 s_callback_guards = 0;
|
||||||
|
|
||||||
Layers* GetLayers()
|
Layers* GetLayers()
|
||||||
{
|
{
|
||||||
@ -53,6 +54,9 @@ void AddConfigChangedCallback(ConfigChangedCallback func)
|
|||||||
|
|
||||||
void InvokeConfigChangedCallbacks()
|
void InvokeConfigChangedCallbacks()
|
||||||
{
|
{
|
||||||
|
if (s_callback_guards)
|
||||||
|
return;
|
||||||
|
|
||||||
for (const auto& callback : s_callbacks)
|
for (const auto& callback : s_callbacks)
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
@ -137,4 +141,18 @@ LayerType GetActiveLayerForConfig(const ConfigLocation& config)
|
|||||||
// If config is not present in any layer, base layer is considered active.
|
// If config is not present in any layer, base layer is considered active.
|
||||||
return LayerType::Base;
|
return LayerType::Base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigChangeCallbackGuard::ConfigChangeCallbackGuard()
|
||||||
|
{
|
||||||
|
++s_callback_guards;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigChangeCallbackGuard::~ConfigChangeCallbackGuard()
|
||||||
|
{
|
||||||
|
if (--s_callback_guards)
|
||||||
|
return;
|
||||||
|
|
||||||
|
InvokeConfigChangedCallbacks();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Config
|
||||||
|
@ -96,4 +96,15 @@ void SetBaseOrCurrent(const ConfigInfo<T>& info, const std::common_type_t<T>& va
|
|||||||
else
|
else
|
||||||
Set<T>(LayerType::CurrentRun, info, value);
|
Set<T>(LayerType::CurrentRun, info, value);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// Used to defer InvokeConfigChangedCallbacks until after the completion of many config changes.
|
||||||
|
class ConfigChangeCallbackGuard
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ConfigChangeCallbackGuard();
|
||||||
|
~ConfigChangeCallbackGuard();
|
||||||
|
|
||||||
|
ConfigChangeCallbackGuard(const ConfigChangeCallbackGuard&) = delete;
|
||||||
|
ConfigChangeCallbackGuard& operator=(const ConfigChangeCallbackGuard&) = delete;
|
||||||
|
};
|
||||||
|
} // namespace Config
|
||||||
|
@ -173,6 +173,8 @@ LogManager::~LogManager()
|
|||||||
|
|
||||||
void LogManager::SaveSettings()
|
void LogManager::SaveSettings()
|
||||||
{
|
{
|
||||||
|
Config::ConfigChangeCallbackGuard config_guard;
|
||||||
|
|
||||||
Config::SetBaseOrCurrent(LOGGER_WRITE_TO_FILE, IsListenerEnabled(LogListener::FILE_LISTENER));
|
Config::SetBaseOrCurrent(LOGGER_WRITE_TO_FILE, IsListenerEnabled(LogListener::FILE_LISTENER));
|
||||||
Config::SetBaseOrCurrent(LOGGER_WRITE_TO_CONSOLE,
|
Config::SetBaseOrCurrent(LOGGER_WRITE_TO_CONSOLE,
|
||||||
IsListenerEnabled(LogListener::CONSOLE_LISTENER));
|
IsListenerEnabled(LogListener::CONSOLE_LISTENER));
|
||||||
|
@ -1008,6 +1008,8 @@ std::shared_ptr<const UICommon::GameFile> NetPlayDialog::FindGameFile(const std:
|
|||||||
|
|
||||||
void NetPlayDialog::SaveSettings()
|
void NetPlayDialog::SaveSettings()
|
||||||
{
|
{
|
||||||
|
Config::ConfigChangeCallbackGuard config_guard;
|
||||||
|
|
||||||
if (m_host_input_authority)
|
if (m_host_input_authority)
|
||||||
{
|
{
|
||||||
if (!IsHosting())
|
if (!IsHosting())
|
||||||
|
@ -203,6 +203,8 @@ void NetPlaySetupDialog::ConnectWidgets()
|
|||||||
|
|
||||||
void NetPlaySetupDialog::SaveSettings()
|
void NetPlaySetupDialog::SaveSettings()
|
||||||
{
|
{
|
||||||
|
Config::ConfigChangeCallbackGuard config_guard;
|
||||||
|
|
||||||
Config::SetBaseOrCurrent(Config::NETPLAY_NICKNAME, m_nickname_edit->text().toStdString());
|
Config::SetBaseOrCurrent(Config::NETPLAY_NICKNAME, m_nickname_edit->text().toStdString());
|
||||||
Config::SetBaseOrCurrent(m_connection_type->currentIndex() == 0 ? Config::NETPLAY_ADDRESS :
|
Config::SetBaseOrCurrent(m_connection_type->currentIndex() == 0 ? Config::NETPLAY_ADDRESS :
|
||||||
Config::NETPLAY_HOST_CODE,
|
Config::NETPLAY_HOST_CODE,
|
||||||
|
@ -332,6 +332,8 @@ void GameCubePane::LoadSettings()
|
|||||||
|
|
||||||
void GameCubePane::SaveSettings()
|
void GameCubePane::SaveSettings()
|
||||||
{
|
{
|
||||||
|
Config::ConfigChangeCallbackGuard config_guard;
|
||||||
|
|
||||||
SConfig& params = SConfig::GetInstance();
|
SConfig& params = SConfig::GetInstance();
|
||||||
|
|
||||||
// IPL Settings
|
// IPL Settings
|
||||||
|
@ -282,6 +282,8 @@ static QString UpdateTrackFromIndex(int index)
|
|||||||
|
|
||||||
void GeneralPane::OnSaveConfig()
|
void GeneralPane::OnSaveConfig()
|
||||||
{
|
{
|
||||||
|
Config::ConfigChangeCallbackGuard config_guard;
|
||||||
|
|
||||||
auto& settings = SConfig::GetInstance();
|
auto& settings = SConfig::GetInstance();
|
||||||
if (AutoUpdateChecker::SystemSupportsAutoUpdates())
|
if (AutoUpdateChecker::SystemSupportsAutoUpdates())
|
||||||
{
|
{
|
||||||
|
@ -221,6 +221,8 @@ void WiiPane::LoadConfig()
|
|||||||
|
|
||||||
void WiiPane::OnSaveConfig()
|
void WiiPane::OnSaveConfig()
|
||||||
{
|
{
|
||||||
|
Config::ConfigChangeCallbackGuard config_guard;
|
||||||
|
|
||||||
Config::SetBase(Config::SYSCONF_SCREENSAVER, m_screensaver_checkbox->isChecked());
|
Config::SetBase(Config::SYSCONF_SCREENSAVER, m_screensaver_checkbox->isChecked());
|
||||||
Config::SetBase(Config::SYSCONF_PAL60, m_pal60_mode_checkbox->isChecked());
|
Config::SetBase(Config::SYSCONF_PAL60, m_pal60_mode_checkbox->isChecked());
|
||||||
Settings::Instance().SetUSBKeyboardConnected(m_connect_keyboard_checkbox->isChecked());
|
Settings::Instance().SetUSBKeyboardConnected(m_connect_keyboard_checkbox->isChecked());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user