Add support for boolean options

This commit is contained in:
Maxime Coste 2013-03-05 19:03:42 +01:00
parent fac222a427
commit 09cf5acb23
3 changed files with 19 additions and 4 deletions

View File

@ -377,7 +377,7 @@ public:
DisplayCoord menu_pos{ context().ui().dimensions().line, 0_char }; DisplayCoord menu_pos{ context().ui().dimensions().line, 0_char };
context().ui().menu_show(candidates, menu_pos, MenuStyle::Prompt); context().ui().menu_show(candidates, menu_pos, MenuStyle::Prompt);
bool use_common_prefix = context().options()["complete_prefix"].get<int>(); bool use_common_prefix = context().options()["complete_prefix"].get<bool>();
String prefix = use_common_prefix ? common_prefix(candidates) : String(); String prefix = use_common_prefix ? common_prefix(candidates) : String();
if (m_completions.end - m_completions.start > prefix.length()) if (m_completions.end - m_completions.start > prefix.length())
prefix = line.substr(m_completions.start, prefix = line.substr(m_completions.start,

View File

@ -176,7 +176,7 @@ void do_search(Context& context)
RegisterManager::instance()['/'] = ex; RegisterManager::instance()['/'] = ex;
context.push_jump(); context.push_jump();
} }
else if (ex.empty() or not context.options()["incsearch"].get<int>()) else if (ex.empty() or not context.options()["incsearch"].get<bool>())
return; return;
context.editor().select(std::bind(select_next_match<forward>, _1, ex), mode); context.editor().select(std::bind(select_next_match<forward>, _1, ex), mode);

View File

@ -54,6 +54,21 @@ template class TypedOption<int>;
template const int& Option::get<int>() const; template const int& Option::get<int>() const;
template void Option::set<int>(const int&); template void Option::set<int>(const int&);
// TypedOption<bool> specializations;
template<> String TypedOption<bool>::get_as_string() const { return m_value ? "true" : "false"; }
template<> void TypedOption<bool>::set_from_string(const String& str)
{
if (str == "true" or str == "yes")
m_value = true;
else if (str == "false" or str == "no")
m_value = false;
else
throw runtime_error("boolean values are either true, yes, false or no");
}
template class TypedOption<bool>;
template const bool& Option::get<bool>() const;
template void Option::set<bool>(const bool&);
OptionManager::OptionManager(OptionManager& parent) OptionManager::OptionManager(OptionManager& parent)
: m_parent(&parent) : m_parent(&parent)
{ {
@ -164,8 +179,8 @@ GlobalOptions::GlobalOptions()
declare_option<String>("eolformat", "lf"); declare_option<String>("eolformat", "lf");
declare_option<String>("BOM", "no"); declare_option<String>("BOM", "no");
declare_option<String>("shell", "sh"); declare_option<String>("shell", "sh");
declare_option<int>("complete_prefix", 1); declare_option<bool>("complete_prefix", true);
declare_option<int>("incsearch", 1); declare_option<bool>("incsearch", true);
declare_option<String>("ignored_files", R"(^(\..*|.*\.(o|so|a)))$)"); declare_option<String>("ignored_files", R"(^(\..*|.*\.(o|so|a)))$)");
declare_option<String>("filetype", ""); declare_option<String>("filetype", "");
} }