commit d6ccad991ecc7f553573db76c51a441d7b8bb08a
parent 080306254c48918ac0f9f77c41c19f5500476435
Author: cfillion <cfillion@users.noreply.github.com>
Date: Tue, 7 Jun 2016 15:56:12 -0400
config: add restore default settings feature
Diffstat:
3 files changed, 45 insertions(+), 17 deletions(-)
diff --git a/src/config.cpp b/src/config.cpp
@@ -55,6 +55,36 @@ Config::Config()
{
}
+void Config::reset()
+{
+ m_install = {false, false};
+ m_browser = {0};
+
+ const vector<pair<string,string> > repos = {
+ {"ReaTeam Scripts",
+ "https://github.com/ReaTeam/ReaScripts/raw/master/index.xml"},
+ {"ReaTeam JSFX",
+ "https://github.com/ReaTeam/JSFX/raw/master/index.xml"},
+ {"MPL Scripts",
+ "https://github.com/MichaelPilyavskiy/ReaScripts/raw/master/index.xml"},
+ {"X-Raym Scripts",
+ "https://github.com/X-Raym/REAPER-ReaScripts/raw/master/index.xml"},
+ };
+
+ restoreSelfRemote();
+
+ for(const auto &pair : repos) {
+ Remote remote = m_remotes.get(pair.first);
+
+ if(!remote)
+ remote.setEnabled(false); // disable by default
+
+ remote.setName(pair.first);
+ remote.setUrl(pair.second);
+ m_remotes.add(remote);
+ }
+}
+
void Config::migrate()
{
const unsigned int version = getUInt(GENERAL_GRP, VERSION_KEY);
@@ -62,18 +92,7 @@ void Config::migrate()
switch(version) {
case 0:
m_isFirstRun = true;
-
- m_remotes.add({"ReaTeam Scripts",
- "https://github.com/ReaTeam/ReaScripts/raw/master/index.xml", false});
-
- m_remotes.add({"ReaTeam JSFX",
- "https://github.com/ReaTeam/JSFX/raw/master/index.xml", false});
-
- m_remotes.add({"MPL Scripts",
- "https://github.com/MichaelPilyavskiy/ReaScripts/raw/master/index.xml", false});
-
- m_remotes.add({"X-Raym Scripts",
- "https://github.com/X-Raym/REAPER-ReaScripts/raw/master/index.xml", false});
+ reset();
break;
default:
// configuration is up-to-date, don't write anything now
@@ -100,7 +119,6 @@ void Config::read(const Path &path)
};
readRemotes();
- restoreSelfRemote();
migrate();
}
@@ -170,9 +188,10 @@ void Config::setString(const auto_char *group,
make_autostring(val).c_str(), m_path.c_str());
}
-unsigned int Config::getUInt(const auto_char *group, const auto_string &key) const
+unsigned int Config::getUInt(const auto_char *group,
+ const auto_string &key, const unsigned int fallback) const
{
- return GetPrivateProfileInt(group, key.c_str(), 0, m_path.c_str());
+ return GetPrivateProfileInt(group, key.c_str(), fallback, m_path.c_str());
}
void Config::setUInt(const auto_char *group, const auto_string &key,
diff --git a/src/config.hpp b/src/config.hpp
@@ -38,6 +38,7 @@ class Config {
public:
Config();
+ void reset();
void read(const Path &);
void write();
@@ -49,7 +50,7 @@ public:
private:
std::string getString(const auto_char *, const auto_string &) const;
void setString(const auto_char *, const auto_string &, const std::string &) const;
- unsigned int getUInt(const auto_char *, const auto_string &) const;
+ unsigned int getUInt(const auto_char *, const auto_string &, unsigned int = 0) const;
void setUInt(const auto_char *, const auto_string &, unsigned int) const;
void deleteKey(const auto_char *, const auto_string &) const;
void cleanupArray(const auto_char *, const auto_string &,
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -33,7 +33,7 @@ using namespace std;
enum { ACTION_ENABLE = 80, ACTION_DISABLE, ACTION_UNINSTALL, ACTION_ABOUT,
ACTION_REFRESH, ACTION_COPYURL, ACTION_SELECT, ACTION_UNSELECT,
- ACTION_AUTOINSTALL, ACTION_BLEEDINGEDGE };
+ ACTION_AUTOINSTALL, ACTION_BLEEDINGEDGE, ACTION_RESETCONFIG };
Manager::Manager(ReaPack *reapack)
: Dialog(IDD_CONFIG_DIALOG),
@@ -92,6 +92,10 @@ void Manager::onCommand(const int id, int)
case ACTION_BLEEDINGEDGE:
toggle(m_bleedingEdge, m_config->install()->bleedingEdge);
break;
+ case ACTION_RESETCONFIG:
+ m_config->reset();
+ refresh();
+ break;
case ACTION_SELECT:
m_list->selectAll();
SetFocus(m_list->handle());
@@ -369,6 +373,10 @@ void Manager::options()
if(m_bleedingEdge.value_or(m_config->install()->bleedingEdge))
menu.check(index);
+ menu.addSeparator();
+
+ menu.addAction(AUTO_STR("&Restore default settings"), ACTION_RESETCONFIG);
+
menu.show(rect.left, rect.bottom - 1, handle());
}