2015-12-06 10:18:31 +00:00
|
|
|
|
|
|
|
#include "state.hpp"
|
|
|
|
|
|
|
|
#include <stdexcept>
|
2015-12-06 11:06:28 +00:00
|
|
|
#include <algorithm>
|
2015-12-08 16:21:58 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include "intsetting.hpp"
|
2015-12-06 10:18:31 +00:00
|
|
|
|
|
|
|
CSMPrefs::State *CSMPrefs::State::sThis = 0;
|
|
|
|
|
|
|
|
void CSMPrefs::State::load()
|
|
|
|
{
|
|
|
|
// default settings file
|
|
|
|
boost::filesystem::path local = mConfigurationManager.getLocalPath() / mConfigFile;
|
|
|
|
boost::filesystem::path global = mConfigurationManager.getGlobalPath() / mConfigFile;
|
|
|
|
|
|
|
|
if (boost::filesystem::exists (local))
|
|
|
|
mSettings.loadDefault (local.string());
|
|
|
|
else if (boost::filesystem::exists (global))
|
|
|
|
mSettings.loadDefault (global.string());
|
|
|
|
else
|
|
|
|
throw std::runtime_error ("No default settings file found! Make sure the file \"opencs.ini\" was properly installed.");
|
|
|
|
|
|
|
|
// user settings file
|
|
|
|
boost::filesystem::path user = mConfigurationManager.getUserConfigPath() / mConfigFile;
|
|
|
|
|
|
|
|
if (boost::filesystem::exists (user))
|
|
|
|
mSettings.loadUser (user.string());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSMPrefs::State::declare()
|
|
|
|
{
|
2015-12-08 08:56:42 +00:00
|
|
|
declareCategory ("Windows");
|
2015-12-08 16:21:58 +00:00
|
|
|
declareInt ("default-width", "Default window width", 800).
|
|
|
|
setTooltip ("Newly opened top-level windows will open with this width.").
|
|
|
|
setMin (80);
|
|
|
|
declareInt ("default-height", "Default window height", 600).
|
|
|
|
setTooltip ("Newly opened top-level windows will open with this height.").
|
|
|
|
setMin (80);
|
|
|
|
// reuse
|
|
|
|
// show-statusbar
|
|
|
|
declareInt ("max-subviews", "Maximum number of subviews per top-level window", 256).
|
|
|
|
setTooltip ("If the maximum number is reached and a new subview is opened "
|
|
|
|
"it will be placed into a new top-level window.").
|
|
|
|
setRange (1, 256);
|
|
|
|
// hide-subview
|
|
|
|
declareInt ("minimum-width", "Minimum subview width", 325).
|
|
|
|
setTooltip ("Minimum width of subviews.").
|
|
|
|
setRange (50, 10000);
|
|
|
|
// mainwindow-scrollbar
|
|
|
|
// grow-limit
|
2015-12-06 10:18:31 +00:00
|
|
|
|
2015-12-08 08:56:42 +00:00
|
|
|
declareCategory ("Records");
|
2015-12-06 11:06:28 +00:00
|
|
|
|
2015-12-08 08:56:42 +00:00
|
|
|
declareCategory ("ID Tables");
|
2015-12-06 11:06:28 +00:00
|
|
|
|
2015-12-08 08:56:42 +00:00
|
|
|
declareCategory ("ID Dialogues");
|
2015-12-06 11:06:28 +00:00
|
|
|
|
2015-12-08 08:56:42 +00:00
|
|
|
declareCategory ("Reports");
|
2015-12-06 11:06:28 +00:00
|
|
|
|
2015-12-08 08:56:42 +00:00
|
|
|
declareCategory ("Search & Replace");
|
2015-12-08 16:21:58 +00:00
|
|
|
declareInt ("char-before", "Characters before search string", 10).
|
|
|
|
setTooltip ("Maximum number of character to display in search result before the searched text");
|
|
|
|
declareInt ("char-after", "Characters after search string", 10).
|
|
|
|
setTooltip ("Maximum number of character to display in search result after the searched text");
|
|
|
|
// auto-delete
|
2015-12-06 11:06:28 +00:00
|
|
|
|
2015-12-08 08:56:42 +00:00
|
|
|
declareCategory ("Scripts");
|
2015-12-08 16:21:58 +00:00
|
|
|
// show-linenum
|
|
|
|
// mono-font
|
|
|
|
// warnings
|
|
|
|
// toolbar
|
|
|
|
declareInt ("compile-delay", "Delay between updating of source errors", 100).
|
|
|
|
setTooltip ("Delay in milliseconds").
|
|
|
|
setRange (0, 10000);
|
|
|
|
declareInt ("error-height", "Initial height of the error panel", 100).
|
|
|
|
setRange (100, 10000);
|
|
|
|
// syntax-colouring
|
2015-12-06 11:06:28 +00:00
|
|
|
|
2015-12-08 08:56:42 +00:00
|
|
|
declareCategory ("General Input");
|
2015-12-06 11:06:28 +00:00
|
|
|
|
2015-12-08 08:56:42 +00:00
|
|
|
declareCategory ("3D Scene Input");
|
2015-12-06 11:06:28 +00:00
|
|
|
|
2015-12-08 08:56:42 +00:00
|
|
|
declareCategory ("Tooltips");
|
2015-12-08 16:21:58 +00:00
|
|
|
// scene
|
|
|
|
// scene-hide-basic
|
|
|
|
declareInt ("scene-delay", "Tooltip delay in milliseconds", 500).
|
|
|
|
setMin (1);
|
2015-12-06 11:06:28 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 08:56:42 +00:00
|
|
|
void CSMPrefs::State::declareCategory (const std::string& key)
|
2015-12-06 11:06:28 +00:00
|
|
|
{
|
|
|
|
std::map<std::string, Category>::iterator iter = mCategories.find (key);
|
|
|
|
|
|
|
|
if (iter!=mCategories.end())
|
|
|
|
{
|
|
|
|
mCurrentCategory = iter;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mCurrentCategory =
|
2015-12-08 08:56:42 +00:00
|
|
|
mCategories.insert (std::make_pair (key, Category (this, key))).first;
|
2015-12-06 11:06:28 +00:00
|
|
|
}
|
2015-12-06 10:18:31 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 16:21:58 +00:00
|
|
|
CSMPrefs::IntSetting& CSMPrefs::State::declareInt (const std::string& key,
|
|
|
|
const std::string& label, int default_)
|
|
|
|
{
|
|
|
|
if (mCurrentCategory==mCategories.end())
|
|
|
|
throw std::logic_error ("no category for setting");
|
|
|
|
|
|
|
|
std::ostringstream stream;
|
|
|
|
stream << default_;
|
|
|
|
setDefault (key, stream.str());
|
|
|
|
|
|
|
|
default_ = mSettings.getInt (key, mCurrentCategory->second.getKey());
|
|
|
|
|
|
|
|
CSMPrefs::IntSetting *setting =
|
|
|
|
new CSMPrefs::IntSetting (&mCurrentCategory->second, &mSettings, key, label, default_);
|
|
|
|
|
|
|
|
mCurrentCategory->second.addSetting (setting);
|
|
|
|
|
|
|
|
return *setting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSMPrefs::State::setDefault (const std::string& key, const std::string& default_)
|
|
|
|
{
|
|
|
|
Settings::CategorySetting fullKey (mCurrentCategory->second.getKey(), key);
|
|
|
|
|
|
|
|
Settings::CategorySettingValueMap::iterator iter =
|
|
|
|
mSettings.mDefaultSettings.find (fullKey);
|
|
|
|
|
|
|
|
if (iter==mSettings.mDefaultSettings.end())
|
|
|
|
mSettings.mDefaultSettings.insert (std::make_pair (fullKey, default_));
|
|
|
|
}
|
|
|
|
|
2015-12-06 10:18:31 +00:00
|
|
|
CSMPrefs::State::State (const Files::ConfigurationManager& configurationManager)
|
2015-12-06 11:06:28 +00:00
|
|
|
: mConfigFile ("opencs.ini"), mConfigurationManager (configurationManager),
|
|
|
|
mCurrentCategory (mCategories.end())
|
2015-12-06 10:18:31 +00:00
|
|
|
{
|
|
|
|
if (sThis)
|
|
|
|
throw std::logic_error ("An instance of CSMPRefs::State already exists");
|
|
|
|
|
|
|
|
load();
|
|
|
|
declare();
|
|
|
|
|
|
|
|
sThis = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSMPrefs::State::~State()
|
|
|
|
{
|
|
|
|
sThis = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSMPrefs::State::save()
|
|
|
|
{
|
|
|
|
boost::filesystem::path user = mConfigurationManager.getUserConfigPath() / mConfigFile;
|
|
|
|
mSettings.saveUser (user.string());
|
|
|
|
}
|
|
|
|
|
2015-12-08 08:56:42 +00:00
|
|
|
CSMPrefs::State::Iterator CSMPrefs::State::begin()
|
2015-12-06 11:06:28 +00:00
|
|
|
{
|
2015-12-08 08:56:42 +00:00
|
|
|
return mCategories.begin();
|
|
|
|
}
|
2015-12-06 11:06:28 +00:00
|
|
|
|
2015-12-08 08:56:42 +00:00
|
|
|
CSMPrefs::State::Iterator CSMPrefs::State::end()
|
|
|
|
{
|
|
|
|
return mCategories.end();
|
2015-12-06 11:06:28 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 11:04:45 +00:00
|
|
|
CSMPrefs::Category& CSMPrefs::State::getCategory (const std::string& key)
|
|
|
|
{
|
|
|
|
Iterator iter = mCategories.find (key);
|
|
|
|
|
|
|
|
if (iter==mCategories.end())
|
|
|
|
throw std::logic_error ("Invalid user settings category: " + key);
|
|
|
|
|
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
|
2015-12-08 16:21:58 +00:00
|
|
|
void CSMPrefs::State::update (const Setting& setting)
|
|
|
|
{
|
|
|
|
emit (settingChanged (setting));
|
|
|
|
}
|
|
|
|
|
2015-12-06 10:18:31 +00:00
|
|
|
CSMPrefs::State& CSMPrefs::State::get()
|
|
|
|
{
|
|
|
|
if (!sThis)
|
|
|
|
throw std::logic_error ("No instance of CSMPrefs::State");
|
|
|
|
|
|
|
|
return *sThis;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CSMPrefs::State& CSMPrefs::get()
|
|
|
|
{
|
|
|
|
return State::get();
|
|
|
|
}
|