19 : settingInfo (commandController.getOpenMSXInfoCommand())
20 , setCompleter (commandController)
21 , incrCompleter (commandController, *this,
"incr")
22 , unsetCompleter(commandController, *this,
"unset")
28 assert(settings.empty());
33 assert(!settings.contains(
setting.getFullNameObj()));
34 settings.emplace_noDuplicateCheck(&
setting);
39 const auto& name =
setting.getFullNameObj();
40 assert(settings.contains(name));
46 if (
auto it = settings.find(name); it !=
end(settings)) {
49 if (name.starts_with(
"::")) {
51 if (
auto it = settings.find(name.substr(2)); it !=
end(settings)) {
56 if (
auto it = settings.find(
tmpStrCat(
"::", name)); it !=
end(settings)) {
70BaseSetting& SettingsManager::getByName(std::string_view cmd, std::string_view name)
const
75 throw CommandException(cmd,
": ", name,
": no such setting");
78std::vector<std::string> SettingsManager::getTabSettingNames()
const
80 std::vector<std::string> result;
81 result.reserve(
size_t(settings.size()) * 2);
82 for (
const auto* s : settings) {
83 std::string_view name = s->getFullName();
84 result.emplace_back(name);
85 if (name.starts_with(
"::")) {
86 result.emplace_back(name.substr(2));
88 result.push_back(
strCat(
"::", name));
97 for (
auto* s : settings) {
98 if (!s->needLoadSave())
continue;
105 s->setValue(s->getDefaultValue());
108 s->setValue(s->getDefaultValue());
116SettingsManager::SettingInfo::SettingInfo(
InfoCommand& openMSXInfoCommand)
117 :
InfoTopic(openMSXInfoCommand,
"setting")
121void SettingsManager::SettingInfo::execute(
122 std::span<const TclObject> tokens, TclObject& result)
const
124 auto& manager =
OUTER(SettingsManager, settingInfo);
125 switch (tokens.size()) {
129 [](
auto* p) { return p->getFullNameObj(); }));
132 const auto& settingName = tokens[2].getString();
133 const auto*
setting = manager.findSetting(settingName);
135 throw CommandException(
"No such setting: ", settingName);
139 }
catch (MSXException& e) {
140 throw CommandException(
e.getMessage());
146 throw CommandException(
"Too many parameters.");
150std::string SettingsManager::SettingInfo::help(std::span<const TclObject> )
const
152 return "openmsx_info setting : "
153 "returns list of all settings\n"
154 "openmsx_info setting <name> : "
155 "returns info on a specific setting\n";
158void SettingsManager::SettingInfo::tabCompletion(std::vector<std::string>& tokens)
const
160 if (tokens.size() == 3) {
162 const auto& manager =
OUTER(SettingsManager, settingInfo);
163 completeString(tokens, manager.getTabSettingNames());
170SettingsManager::SetCompleter::SetCompleter(
171 CommandController& commandController_)
172 : CommandCompleter(commandController_,
"set")
176std::string SettingsManager::SetCompleter::help(std::span<const TclObject> tokens)
const
178 if (tokens.size() == 2) {
179 const auto& manager =
OUTER(SettingsManager, setCompleter);
180 return std::string(manager.getByName(
"set", tokens[1].getString()).getDescription());
182 return "Set or query the value of a openMSX setting or Tcl variable\n"
183 " set <setting> shows current value\n"
184 " set <setting> <value> set a new value\n"
185 "Use 'help set <setting>' to get more info on a specific\n"
186 "openMSX setting.\n";
189void SettingsManager::SetCompleter::tabCompletion(std::vector<std::string>& tokens)
const
191 const auto& manager =
OUTER(SettingsManager, setCompleter);
192 switch (tokens.size()) {
195 completeString(tokens, manager.getTabSettingNames(),
false);
200 if (
const auto*
setting = manager.findSetting(tokens[1])) {
210SettingsManager::SettingCompleter::SettingCompleter(
211 CommandController& commandController_, SettingsManager& manager_,
212 const std::string& name_)
213 : CommandCompleter(commandController_, name_)
218std::string SettingsManager::SettingCompleter::help(std::span<const TclObject> )
const
223void SettingsManager::SettingCompleter::tabCompletion(std::vector<std::string>& tokens)
const
225 if (tokens.size() == 2) {
227 completeString(tokens, manager.getTabSettingNames());
void info(TclObject &result) const
For SettingInfo.
virtual void tabCompletion(std::vector< std::string > &tokens) const =0
Complete a partly typed value.
const std::string * getValueForSetting(std::string_view setting) const
BaseSetting * findSetting(std::string_view name) const
Find the setting with given name.
void loadSettings(const SettingsConfig &config) const
void unregisterSetting(BaseSetting &setting)
SettingsManager(GlobalCommandController &commandController)
void registerSetting(BaseSetting &setting)
This file implemented 3 utility functions:
constexpr auto transform(Range &&range, UnaryOp op)
#define OUTER(type, member)
TemporaryString tmpStrCat(Ts &&... ts)
constexpr auto end(const zstring_view &x)