Change autoinfo option to be an integer, allowing different levels

This commit is contained in:
Maxime Coste 2014-07-08 20:24:51 +01:00
parent 81d3eadd09
commit 4c3bd68876
3 changed files with 19 additions and 17 deletions

View File

@ -964,6 +964,19 @@ const ParameterDesc context_wrap_params = {
ParameterDesc::Flags::SwitchesOnlyAtStart, 1 ParameterDesc::Flags::SwitchesOnlyAtStart, 1
}; };
template<typename T>
struct DisableOption {
DisableOption(Context& context, const char* name)
: m_option(context.options()[name]),
m_prev_value(m_option.get<T>())
{ m_option.set(T{}); }
~DisableOption() { m_option.set(m_prev_value); }
Option& m_option;
T m_prev_value;
};
template<typename Func> template<typename Func>
void context_wrap(const ParametersParser& parser, Context& context, Func func) void context_wrap(const ParametersParser& parser, Context& context, Func func)
{ {
@ -975,20 +988,9 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func)
GlobalHooks::instance().enable_user_hooks(); GlobalHooks::instance().enable_user_hooks();
}); });
struct DisableOption { DisableOption<int> disable_autoinfo(context, "autoinfo");
DisableOption(Context& context, const char* name) DisableOption<bool> disable_autoshowcompl(context, "autoshowcompl");
: m_option(context.options()[name]), DisableOption<bool> disable_incsearch(context, "incsearch");
m_prev_value(m_option.get<bool>())
{ m_option.set(false); }
~DisableOption() { m_option.set(m_prev_value); }
Option& m_option;
bool m_prev_value;
};
DisableOption disable_autoinfo(context, "autoinfo");
DisableOption disable_autoshowcompl(context, "autoshowcompl");
DisableOption disable_incsearch(context, "incsearch");
ClientManager& cm = ClientManager::instance(); ClientManager& cm = ClientManager::instance();

View File

@ -107,7 +107,7 @@ void repeat_last_insert(Context& context, int)
bool show_auto_info_ifn(const String& title, const String& info, bool show_auto_info_ifn(const String& title, const String& info,
const Context& context) const Context& context)
{ {
if (not context.options()["autoinfo"].get<bool>() or not context.has_ui()) if (context.options()["autoinfo"].get<int>() < 1 or not context.has_ui())
return false; return false;
ColorPair col = get_color("Information"); ColorPair col = get_color("Information");
CharCoord pos = context.window().dimensions(); CharCoord pos = context.window().dimensions();
@ -348,7 +348,7 @@ void command(Context& context, int)
if (context.has_ui()) if (context.has_ui())
{ {
context.ui().info_hide(); context.ui().info_hide();
if (event == PromptEvent::Change and context.options()["autoinfo"].get<bool>()) if (event == PromptEvent::Change and context.options()["autoinfo"].get<int>() > 0)
{ {
auto info = CommandManager::instance().command_info(cmdline); auto info = CommandManager::instance().command_info(cmdline);
ColorPair col = get_color("Information"); ColorPair col = get_color("Information");

View File

@ -145,7 +145,7 @@ GlobalOptions::GlobalOptions()
true); true);
declare_option("autoinfo", declare_option("autoinfo",
"automatically display contextual help", "automatically display contextual help",
true); 1);
declare_option("autoshowcompl", declare_option("autoshowcompl",
"automatically display possible completions for prompts", "automatically display possible completions for prompts",
true); true);