20 : settingInfo (commandController.getOpenMSXInfoCommand())
21 , setCompleter (commandController)
22 , incrCompleter (commandController, *this,
"incr")
23 , unsetCompleter(commandController, *this,
"unset")
29 assert(settings.empty());
34 assert(!settings.contains(
setting.getFullNameObj()));
35 settings.emplace_noDuplicateCheck(&
setting);
40 const auto& name =
setting.getFullNameObj();
41 assert(settings.contains(name));
47 if (
auto it = settings.find(name); it !=
end(settings)) {
50 if (name.starts_with(
"::")) {
52 if (
auto it = settings.find(name.substr(2)); it !=
end(settings)) {
57 if (
auto it = settings.find(
tmpStrCat(
"::", name)); it !=
end(settings)) {
66 auto size = prefix.size() + baseName.size();
67 VLA(
char, fullname, size);
70 return findSetting(std::string_view(fullname.data(), size));
75BaseSetting& SettingsManager::getByName(std::string_view cmd, std::string_view name)
const
80 throw CommandException(cmd,
": ", name,
": no such setting");
83std::vector<std::string> SettingsManager::getTabSettingNames()
const
85 std::vector<std::string> result;
86 result.reserve(settings.size() * 2);
87 for (
const auto* s : settings) {
88 std::string_view name = s->getFullName();
89 result.emplace_back(name);
90 if (name.starts_with(
"::")) {
91 result.emplace_back(name.substr(2));
93 result.push_back(
strCat(
"::", name));
102 for (
auto* s : settings) {
103 if (!s->needLoadSave())
continue;
110 s->setValue(s->getDefaultValue());
113 s->setValue(s->getDefaultValue());
121SettingsManager::SettingInfo::SettingInfo(
InfoCommand& openMSXInfoCommand)
122 :
InfoTopic(openMSXInfoCommand,
"setting")
126void SettingsManager::SettingInfo::execute(
127 std::span<const TclObject> tokens, TclObject& result)
const
129 auto& manager =
OUTER(SettingsManager, settingInfo);
130 switch (tokens.size()) {
134 [](
auto* p) { return p->getFullNameObj(); }));
137 const auto& settingName = tokens[2].getString();
138 const auto*
setting = manager.findSetting(settingName);
140 throw CommandException(
"No such setting: ", settingName);
144 }
catch (MSXException& e) {
145 throw CommandException(
e.getMessage());
151 throw CommandException(
"Too many parameters.");
155std::string SettingsManager::SettingInfo::help(std::span<const TclObject> )
const
157 return "openmsx_info setting : "
158 "returns list of all settings\n"
159 "openmsx_info setting <name> : "
160 "returns info on a specific setting\n";
163void SettingsManager::SettingInfo::tabCompletion(std::vector<std::string>& tokens)
const
165 if (tokens.size() == 3) {
167 const auto& manager =
OUTER(SettingsManager, settingInfo);
168 completeString(tokens, manager.getTabSettingNames());
175SettingsManager::SetCompleter::SetCompleter(
176 CommandController& commandController_)
177 : CommandCompleter(commandController_,
"set")
181std::string SettingsManager::SetCompleter::help(std::span<const TclObject> tokens)
const
183 if (tokens.size() == 2) {
184 const auto& manager =
OUTER(SettingsManager, setCompleter);
185 return std::string(manager.getByName(
"set", tokens[1].getString()).getDescription());
187 return "Set or query the value of a openMSX setting or Tcl variable\n"
188 " set <setting> shows current value\n"
189 " set <setting> <value> set a new value\n"
190 "Use 'help set <setting>' to get more info on a specific\n"
191 "openMSX setting.\n";
194void SettingsManager::SetCompleter::tabCompletion(std::vector<std::string>& tokens)
const
196 const auto& manager =
OUTER(SettingsManager, setCompleter);
197 switch (tokens.size()) {
200 completeString(tokens, manager.getTabSettingNames(),
false);
205 if (
const auto*
setting = manager.findSetting(tokens[1])) {
215SettingsManager::SettingCompleter::SettingCompleter(
216 CommandController& commandController_, SettingsManager& manager_,
217 const std::string& name_)
218 : CommandCompleter(commandController_, name_)
223std::string SettingsManager::SettingCompleter::help(std::span<const TclObject> )
const
228void SettingsManager::SettingCompleter::tabCompletion(std::vector<std::string>& tokens)
const
230 if (tokens.size() == 2) {
232 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 copy(InputRange &&range, OutputIter out)
constexpr auto transform(Range &&range, UnaryOp op)
#define OUTER(type, member)
TemporaryString tmpStrCat(Ts &&... ts)
#define VLA(TYPE, NAME, LENGTH)
constexpr auto end(const zstring_view &x)