GH-1223 fix override settings

They now work more like passthrough settings, except not passing through set and reset
This commit is contained in:
Petr Mrázek 2015-09-04 02:10:29 +02:00
parent 151a0ca11e
commit cd108fd029
8 changed files with 88 additions and 37 deletions

View File

@ -119,11 +119,13 @@ void InstanceSettingsPage::applySettings()
if (custcmd) if (custcmd)
{ {
m_settings->set("PreLaunchCommand", ui->preLaunchCmdTextBox->text()); m_settings->set("PreLaunchCommand", ui->preLaunchCmdTextBox->text());
m_settings->set("WrapperCommand", ui->preLaunchCmdTextBox->text());
m_settings->set("PostExitCommand", ui->postExitCmdTextBox->text()); m_settings->set("PostExitCommand", ui->postExitCmdTextBox->text());
} }
else else
{ {
m_settings->reset("PreLaunchCommand"); m_settings->reset("PreLaunchCommand");
m_settings->reset("WrapperCommand");
m_settings->reset("PostExitCommand"); m_settings->reset("PostExitCommand");
} }
} }
@ -161,6 +163,7 @@ void InstanceSettingsPage::loadSettings()
// Custom Commands // Custom Commands
ui->customCommandsGroupBox->setChecked(m_settings->get("OverrideCommands").toBool()); ui->customCommandsGroupBox->setChecked(m_settings->get("OverrideCommands").toBool());
ui->preLaunchCmdTextBox->setText(m_settings->get("PreLaunchCommand").toString()); ui->preLaunchCmdTextBox->setText(m_settings->get("PreLaunchCommand").toString());
ui->wrapperCmdTextBox->setText(m_settings->get("WrapperCommand").toString());
ui->postExitCmdTextBox->setText(m_settings->get("PostExitCommand").toString()); ui->postExitCmdTextBox->setText(m_settings->get("PostExitCommand").toString());
} }

View File

@ -45,7 +45,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="title"> <property name="title">
<string>Java installation</string> <string>Java ins&amp;tallation</string>
</property> </property>
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
@ -87,7 +87,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="title"> <property name="title">
<string>Memory</string> <string>Memor&amp;y</string>
</property> </property>
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
@ -305,7 +305,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="title"> <property name="title">
<string>Console Settings</string> <string>Conso&amp;le Settings</string>
</property> </property>
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
@ -357,7 +357,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="title"> <property name="title">
<string>Custom Commands</string> <string>Cus&amp;tom Commands</string>
</property> </property>
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
@ -366,16 +366,16 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="1"> <item row="2" column="0">
<widget class="QLineEdit" name="preLaunchCmdTextBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelPostExitCmd"> <widget class="QLabel" name="labelPostExitCmd">
<property name="text"> <property name="text">
<string>Post-exit command:</string> <string>Post-exit command:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<widget class="QLineEdit" name="preLaunchCmdTextBox"/>
</item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="labelPreLaunchCmd"> <widget class="QLabel" name="labelPreLaunchCmd">
<property name="text"> <property name="text">
@ -383,9 +383,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="2" column="1">
<widget class="QLineEdit" name="postExitCmdTextBox"/> <widget class="QLineEdit" name="postExitCmdTextBox"/>
</item> </item>
<item row="1" column="0">
<widget class="QLabel" name="labelWrapperCmd">
<property name="text">
<string>Wrapper command:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="wrapperCmdTextBox"/>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -446,6 +456,7 @@
<tabstop>autoCloseConsoleCheck</tabstop> <tabstop>autoCloseConsoleCheck</tabstop>
<tabstop>customCommandsGroupBox</tabstop> <tabstop>customCommandsGroupBox</tabstop>
<tabstop>preLaunchCmdTextBox</tabstop> <tabstop>preLaunchCmdTextBox</tabstop>
<tabstop>wrapperCmdTextBox</tabstop>
<tabstop>postExitCmdTextBox</tabstop> <tabstop>postExitCmdTextBox</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>

View File

@ -40,16 +40,16 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s
m_settings->registerSetting("lastLaunchTime", 0); m_settings->registerSetting("lastLaunchTime", 0);
// Custom Commands // Custom Commands
m_settings->registerSetting({"OverrideCommands","OverrideLaunchCmd"}, false); auto commandSetting = m_settings->registerSetting({"OverrideCommands","OverrideLaunchCmd"}, false);
m_settings->registerOverride(globalSettings->getSetting("PreLaunchCommand")); m_settings->registerOverride(globalSettings->getSetting("PreLaunchCommand"), commandSetting);
m_settings->registerOverride(globalSettings->getSetting("WrapperCommand")); m_settings->registerOverride(globalSettings->getSetting("WrapperCommand"), commandSetting);
m_settings->registerOverride(globalSettings->getSetting("PostExitCommand")); m_settings->registerOverride(globalSettings->getSetting("PostExitCommand"), commandSetting);
// Console // Console
m_settings->registerSetting("OverrideConsole", false); auto consoleSetting = m_settings->registerSetting("OverrideConsole", false);
m_settings->registerOverride(globalSettings->getSetting("ShowConsole")); m_settings->registerOverride(globalSettings->getSetting("ShowConsole"), consoleSetting);
m_settings->registerOverride(globalSettings->getSetting("AutoCloseConsole")); m_settings->registerOverride(globalSettings->getSetting("AutoCloseConsole"), consoleSetting);
m_settings->registerOverride(globalSettings->getSetting("LogPrePostOutput")); m_settings->registerOverride(globalSettings->getSetting("LogPrePostOutput"), consoleSetting);
} }
QString BaseInstance::getPreLaunchCommand() QString BaseInstance::getPreLaunchCommand()

View File

@ -39,26 +39,30 @@ MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsO
// Java Settings // Java Settings
auto javaOverride = m_settings->registerSetting("OverrideJava", false); auto javaOverride = m_settings->registerSetting("OverrideJava", false);
auto locationOverride = m_settings->registerSetting("OverrideJavaLocation", false); auto locationOverride = m_settings->registerSetting("OverrideJavaLocation", false);
auto argsOverride = m_settings->registerSetting("OverrideJavaArgs", false);
// combinations
auto javaOrLocation = std::make_shared<OrSetting>("JavaOrLocationOverride", javaOverride, locationOverride); auto javaOrLocation = std::make_shared<OrSetting>("JavaOrLocationOverride", javaOverride, locationOverride);
m_settings->registerSetting("OverrideJavaArgs", false); auto javaOrArgs = std::make_shared<OrSetting>("JavaOrArgsOverride", javaOverride, argsOverride);
m_settings->registerOverride(globalSettings->getSetting("JavaPath"));
m_settings->registerOverride(globalSettings->getSetting("JvmArgs")); m_settings->registerOverride(globalSettings->getSetting("JavaPath"), javaOrLocation);
m_settings->registerOverride(globalSettings->getSetting("JvmArgs"), javaOrArgs);
// special! // special!
m_settings->registerPassthrough(globalSettings->getSetting("JavaTimestamp"), javaOrLocation); m_settings->registerPassthrough(globalSettings->getSetting("JavaTimestamp"), javaOrLocation);
m_settings->registerPassthrough(globalSettings->getSetting("JavaVersion"), javaOrLocation); m_settings->registerPassthrough(globalSettings->getSetting("JavaVersion"), javaOrLocation);
// Window Size // Window Size
m_settings->registerSetting("OverrideWindow", false); auto windowSetting = m_settings->registerSetting("OverrideWindow", false);
m_settings->registerOverride(globalSettings->getSetting("LaunchMaximized")); m_settings->registerOverride(globalSettings->getSetting("LaunchMaximized"), windowSetting);
m_settings->registerOverride(globalSettings->getSetting("MinecraftWinWidth")); m_settings->registerOverride(globalSettings->getSetting("MinecraftWinWidth"), windowSetting);
m_settings->registerOverride(globalSettings->getSetting("MinecraftWinHeight")); m_settings->registerOverride(globalSettings->getSetting("MinecraftWinHeight"), windowSetting);
// Memory // Memory
m_settings->registerSetting("OverrideMemory", false); auto memorySetting = m_settings->registerSetting("OverrideMemory", false);
m_settings->registerOverride(globalSettings->getSetting("MinMemAlloc")); m_settings->registerOverride(globalSettings->getSetting("MinMemAlloc"), memorySetting);
m_settings->registerOverride(globalSettings->getSetting("MaxMemAlloc")); m_settings->registerOverride(globalSettings->getSetting("MaxMemAlloc"), memorySetting);
m_settings->registerOverride(globalSettings->getSetting("PermGen")); m_settings->registerOverride(globalSettings->getSetting("PermGen"), memorySetting);
} }
QString MinecraftInstance::minecraftRoot() const QString MinecraftInstance::minecraftRoot() const

View File

@ -15,16 +15,40 @@
#include "OverrideSetting.h" #include "OverrideSetting.h"
OverrideSetting::OverrideSetting(std::shared_ptr<Setting> other) OverrideSetting::OverrideSetting(std::shared_ptr<Setting> other, std::shared_ptr<Setting> gate)
: Setting(other->configKeys(), QVariant()) : Setting(other->configKeys(), QVariant())
{ {
Q_ASSERT(other);
Q_ASSERT(gate);
m_other = other; m_other = other;
m_gate = gate;
}
bool OverrideSetting::isOverriding() const
{
return m_gate->get().toBool();
} }
QVariant OverrideSetting::defValue() const QVariant OverrideSetting::defValue() const
{ {
if (m_other) return m_other->get();
return m_other->get(); }
else
return QVariant(); QVariant OverrideSetting::get() const
{
if(isOverriding())
{
return Setting::get();
}
return m_other->get();
}
void OverrideSetting::reset()
{
Setting::reset();
}
void OverrideSetting::set(QVariant value)
{
Setting::set(value);
} }

View File

@ -30,10 +30,17 @@ class OverrideSetting : public Setting
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit OverrideSetting(std::shared_ptr<Setting> other); explicit OverrideSetting(std::shared_ptr<Setting> overriden, std::shared_ptr<Setting> gate);
virtual QVariant defValue() const; virtual QVariant defValue() const;
virtual QVariant get() const;
virtual void set (QVariant value);
virtual void reset();
private:
bool isOverriding() const;
protected: protected:
std::shared_ptr<Setting> m_other; std::shared_ptr<Setting> m_other;
std::shared_ptr<Setting> m_gate;
}; };

View File

@ -30,7 +30,8 @@ SettingsObject::~SettingsObject()
m_settings.clear(); m_settings.clear();
} }
std::shared_ptr<Setting> SettingsObject::registerOverride(std::shared_ptr<Setting> original) std::shared_ptr<Setting> SettingsObject::registerOverride(std::shared_ptr<Setting> original,
std::shared_ptr<Setting> gate)
{ {
if (contains(original->id())) if (contains(original->id()))
{ {
@ -38,7 +39,7 @@ std::shared_ptr<Setting> SettingsObject::registerOverride(std::shared_ptr<Settin
.arg(original->id()); .arg(original->id());
return nullptr; // Fail return nullptr; // Fail
} }
auto override = std::make_shared<OverrideSetting>(original); auto override = std::make_shared<OverrideSetting>(original, gate);
override->m_storage = this; override->m_storage = this;
connectSignals(*override); connectSignals(*override);
m_settings.insert(override->id(), override); m_settings.insert(override->id(), override);

View File

@ -62,12 +62,13 @@ public:
virtual ~SettingsObject(); virtual ~SettingsObject();
/*! /*!
* Registers an override setting for the given original setting in this settings object * Registers an override setting for the given original setting in this settings object
* gate decides if the passthrough (true) or the original (false) is used for value
* *
* This will fail if there is already a setting with the same ID as * This will fail if there is already a setting with the same ID as
* the one that is being registered. * the one that is being registered.
* \return A valid Setting shared pointer if successful. * \return A valid Setting shared pointer if successful.
*/ */
std::shared_ptr<Setting> registerOverride(std::shared_ptr<Setting> original); std::shared_ptr<Setting> registerOverride(std::shared_ptr<Setting> original, std::shared_ptr<Setting> gate);
/*! /*!
* Registers a passthorugh setting for the given original setting in this settings object * Registers a passthorugh setting for the given original setting in this settings object