Do not pass a context to InputHandler methods

This commit is contained in:
Maxime Coste 2013-01-29 13:49:01 +01:00
parent 94bbf47cd4
commit 38a67e72bc
5 changed files with 23 additions and 28 deletions

View File

@ -53,7 +53,7 @@ void ClientManager::create_client(std::unique_ptr<UserInterface>&& ui,
context->ui().set_input_callback([context, this]() { context->ui().set_input_callback([context, this]() {
try try
{ {
context->input_handler().handle_available_inputs(*context); context->input_handler().handle_available_inputs();
context->window().forget_timestamp(); context->window().forget_timestamp();
} }
catch (Kakoune::runtime_error& error) catch (Kakoune::runtime_error& error)

View File

@ -532,7 +532,7 @@ void exec_keys(const KeyList& keys, Context& context)
InputHandler batch_input_handler(batch_ui); InputHandler batch_input_handler(batch_ui);
batch_input_handler.context().change_editor(context.editor()); batch_input_handler.context().change_editor(context.editor());
batch_input_handler.handle_available_inputs(batch_input_handler.context()); batch_input_handler.handle_available_inputs();
context.change_editor(batch_input_handler.context().editor()); context.change_editor(batch_input_handler.context().editor());
} }
@ -618,7 +618,7 @@ void menu(const CommandParameters& params, Context& context)
CommandManager::instance().execute(commands[choice], context); CommandManager::instance().execute(commands[choice], context);
if (event == MenuEvent::Select and choice >= 0 and choice < select_cmds.size()) if (event == MenuEvent::Select and choice >= 0 and choice < select_cmds.size())
CommandManager::instance().execute(select_cmds[choice], context); CommandManager::instance().execute(select_cmds[choice], context);
}, context); });
} }
void info(const CommandParameters& params, Context& context) void info(const CommandParameters& params, Context& context)

View File

@ -617,17 +617,15 @@ InputHandler::~InputHandler()
{ {
} }
void InputHandler::insert(Context& context, InsertMode mode) void InputHandler::insert(InsertMode mode)
{ {
assert(&context == &m_context);
m_mode_trash.emplace_back(std::move(m_mode)); m_mode_trash.emplace_back(std::move(m_mode));
m_mode.reset(new InputModes::Insert(*this, mode)); m_mode.reset(new InputModes::Insert(*this, mode));
} }
void InputHandler::repeat_last_insert(Context& context) void InputHandler::repeat_last_insert()
{ {
assert(&context == &m_context); Context::Insertion& last_insert = m_context.last_insert();
Context::Insertion& last_insert = context.last_insert();
if (last_insert.second.empty()) if (last_insert.second.empty())
return; return;
@ -643,17 +641,15 @@ void InputHandler::repeat_last_insert(Context& context)
} }
void InputHandler::prompt(const String& prompt, Completer completer, void InputHandler::prompt(const String& prompt, Completer completer,
PromptCallback callback, Context& context) PromptCallback callback)
{ {
assert(&context == &m_context);
m_mode_trash.emplace_back(std::move(m_mode)); m_mode_trash.emplace_back(std::move(m_mode));
m_mode.reset(new InputModes::Prompt(*this, prompt, completer, callback)); m_mode.reset(new InputModes::Prompt(*this, prompt, completer, callback));
} }
void InputHandler::menu(const memoryview<String>& choices, void InputHandler::menu(const memoryview<String>& choices,
MenuCallback callback, Context& context) MenuCallback callback)
{ {
assert(&context == &m_context);
m_mode_trash.emplace_back(std::move(m_mode)); m_mode_trash.emplace_back(std::move(m_mode));
m_mode.reset(new InputModes::Menu(*this, choices, callback)); m_mode.reset(new InputModes::Menu(*this, choices, callback));
} }
@ -669,13 +665,12 @@ bool is_valid(const Key& key)
return key != Key::Invalid and key.key <= 0x10FFFF; return key != Key::Invalid and key.key <= 0x10FFFF;
} }
void InputHandler::handle_available_inputs(Context& context) void InputHandler::handle_available_inputs()
{ {
assert(&context == &m_context);
m_mode_trash.clear(); m_mode_trash.clear();
while (context.ui().is_key_available()) while (m_context.ui().is_key_available())
{ {
Key key = context.ui().get_key(); Key key = m_context.ui().get_key();
if (is_valid(key)) if (is_valid(key))
m_mode->on_key(key); m_mode->on_key(key);
m_mode_trash.clear(); m_mode_trash.clear();

View File

@ -39,23 +39,23 @@ public:
~InputHandler(); ~InputHandler();
// switch to insert mode // switch to insert mode
void insert(Context& context, InsertMode mode); void insert(InsertMode mode);
// repeat last insert mode key sequence // repeat last insert mode key sequence
void repeat_last_insert(Context& context); void repeat_last_insert();
// enter prompt mode, callback is called on each change, // enter prompt mode, callback is called on each change,
// abort or validation with corresponding PromptEvent value // abort or validation with corresponding PromptEvent value
// returns to normal mode after validation if callback does // returns to normal mode after validation if callback does
// not change the mode itself // not change the mode itself
void prompt(const String& prompt, Completer completer, void prompt(const String& prompt, Completer completer,
PromptCallback callback, Context& context); PromptCallback callback);
// enter menu mode, callback is called on each selection change, // enter menu mode, callback is called on each selection change,
// abort or validation with corresponding MenuEvent value // abort or validation with corresponding MenuEvent value
// returns to normal mode after validation if callback does // returns to normal mode after validation if callback does
// not change the mode itself // not change the mode itself
void menu(const memoryview<String>& choices, void menu(const memoryview<String>& choices,
MenuCallback callback, Context& context); MenuCallback callback);
// execute callback on next keypress and returns to normal mode // execute callback on next keypress and returns to normal mode
// if callback does not change the mode itself // if callback does not change the mode itself
@ -63,7 +63,7 @@ public:
// read and process all inputs available in context // read and process all inputs available in context
// user interface // user interface
void handle_available_inputs(Context& context); void handle_available_inputs();
Context& context() { return m_context; } Context& context() { return m_context; }
private: private:

View File

@ -43,12 +43,12 @@ namespace Kakoune
template<InsertMode mode> template<InsertMode mode>
void do_insert(Context& context) void do_insert(Context& context)
{ {
context.input_handler().insert(context, mode); context.input_handler().insert(mode);
} }
void do_repeat_insert(Context& context) void do_repeat_insert(Context& context)
{ {
context.input_handler().repeat_last_insert(context); context.input_handler().repeat_last_insert();
} }
template<SelectMode mode> template<SelectMode mode>
@ -113,7 +113,7 @@ void do_command(Context& context)
[](const String& cmdline, PromptEvent event, Context& context) { [](const String& cmdline, PromptEvent event, Context& context) {
if (event == PromptEvent::Validate) if (event == PromptEvent::Validate)
CommandManager::instance().execute(cmdline, context); CommandManager::instance().execute(cmdline, context);
}, context); });
} }
void do_pipe(Context& context) void do_pipe(Context& context)
@ -130,7 +130,7 @@ void do_pipe(Context& context)
strings.push_back(ShellManager::instance().pipe({sel.begin(), sel.end()}, strings.push_back(ShellManager::instance().pipe({sel.begin(), sel.end()},
cmdline, context, {}, {})); cmdline, context, {}, {}));
editor.insert(strings, InsertMode::Replace); editor.insert(strings, InsertMode::Replace);
}, context); });
} }
template<SelectMode mode, bool forward> template<SelectMode mode, bool forward>
@ -169,7 +169,7 @@ void do_search(Context& context)
throw; throw;
} }
}, context); });
} }
template<SelectMode mode, bool forward> template<SelectMode mode, bool forward>
@ -253,7 +253,7 @@ void do_select_regex(Context& context)
[](const String& ex, PromptEvent event, Context& context) { [](const String& ex, PromptEvent event, Context& context) {
if (event == PromptEvent::Validate and not ex.empty()) if (event == PromptEvent::Validate and not ex.empty())
context.editor().multi_select(std::bind(select_all_matches, _1, ex)); context.editor().multi_select(std::bind(select_all_matches, _1, ex));
}, context); });
} }
void do_split_regex(Context& context) void do_split_regex(Context& context)
@ -262,7 +262,7 @@ void do_split_regex(Context& context)
[](const String& ex, PromptEvent event, Context& context) { [](const String& ex, PromptEvent event, Context& context) {
if (event == PromptEvent::Validate and not ex.empty()) if (event == PromptEvent::Validate and not ex.empty())
context.editor().multi_select(std::bind(split_selection, _1, ex)); context.editor().multi_select(std::bind(split_selection, _1, ex));
}, context); });
} }
void do_join(Context& context) void do_join(Context& context)