2012-10-17 15:14:03 +04:00
|
|
|
#ifndef input_handler_hh_INCLUDED
|
|
|
|
#define input_handler_hh_INCLUDED
|
2012-06-06 03:15:19 +04:00
|
|
|
|
|
|
|
#include "keys.hh"
|
|
|
|
#include "completion.hh"
|
2012-08-16 00:36:45 +04:00
|
|
|
#include "utils.hh"
|
2012-09-03 16:22:02 +04:00
|
|
|
#include "string.hh"
|
2013-01-28 16:48:34 +04:00
|
|
|
#include "context.hh"
|
2012-06-06 03:15:19 +04:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
class Editor;
|
|
|
|
|
2012-12-14 22:38:11 +04:00
|
|
|
enum class MenuEvent
|
|
|
|
{
|
|
|
|
Select,
|
|
|
|
Abort,
|
|
|
|
Validate
|
|
|
|
};
|
|
|
|
using MenuCallback = std::function<void (int, MenuEvent, Context&)>;
|
2012-12-05 22:22:40 +04:00
|
|
|
|
|
|
|
enum class PromptEvent
|
|
|
|
{
|
|
|
|
Change,
|
|
|
|
Abort,
|
|
|
|
Validate
|
|
|
|
};
|
|
|
|
using PromptCallback = std::function<void (const String&, PromptEvent, Context&)>;
|
2012-09-05 02:21:19 +04:00
|
|
|
using KeyCallback = std::function<void (const Key&, Context&)>;
|
2012-09-03 16:22:02 +04:00
|
|
|
|
2012-10-17 15:14:03 +04:00
|
|
|
class InputMode;
|
2012-09-26 16:22:24 +04:00
|
|
|
enum class InsertMode : unsigned;
|
2012-09-24 21:39:40 +04:00
|
|
|
|
2012-10-17 15:14:03 +04:00
|
|
|
class InputHandler : public SafeCountable
|
2012-06-06 03:15:19 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-01-28 16:48:34 +04:00
|
|
|
InputHandler(UserInterface& ui);
|
2012-10-17 15:14:03 +04:00
|
|
|
~InputHandler();
|
2012-09-03 16:22:02 +04:00
|
|
|
|
2013-01-17 17:27:32 +04:00
|
|
|
// switch to insert mode
|
2013-01-29 16:49:01 +04:00
|
|
|
void insert(InsertMode mode);
|
2013-01-17 17:27:32 +04:00
|
|
|
// repeat last insert mode key sequence
|
2013-01-29 16:49:01 +04:00
|
|
|
void repeat_last_insert();
|
2012-09-05 16:27:14 +04:00
|
|
|
|
2013-01-17 17:27:32 +04:00
|
|
|
// enter prompt mode, callback is called on each change,
|
|
|
|
// abort or validation with corresponding PromptEvent value
|
|
|
|
// returns to normal mode after validation if callback does
|
|
|
|
// not change the mode itself
|
2012-09-03 16:22:02 +04:00
|
|
|
void prompt(const String& prompt, Completer completer,
|
2013-01-29 16:49:01 +04:00
|
|
|
PromptCallback callback);
|
2012-06-06 03:15:19 +04:00
|
|
|
|
2013-01-17 17:27:32 +04:00
|
|
|
// enter menu mode, callback is called on each selection change,
|
|
|
|
// abort or validation with corresponding MenuEvent value
|
|
|
|
// returns to normal mode after validation if callback does
|
|
|
|
// not change the mode itself
|
2012-09-03 16:22:02 +04:00
|
|
|
void menu(const memoryview<String>& choices,
|
2013-01-29 16:49:01 +04:00
|
|
|
MenuCallback callback);
|
2012-09-24 21:24:27 +04:00
|
|
|
|
2013-01-17 17:27:32 +04:00
|
|
|
// execute callback on next keypress and returns to normal mode
|
|
|
|
// if callback does not change the mode itself
|
2012-09-05 02:21:19 +04:00
|
|
|
void on_next_key(KeyCallback callback);
|
|
|
|
|
2013-01-17 17:27:32 +04:00
|
|
|
// read and process all inputs available in context
|
|
|
|
// user interface
|
2013-01-29 16:49:01 +04:00
|
|
|
void handle_available_inputs();
|
2012-08-30 23:53:22 +04:00
|
|
|
|
2013-01-28 16:48:34 +04:00
|
|
|
Context& context() { return m_context; }
|
2012-09-03 16:22:02 +04:00
|
|
|
private:
|
2013-01-28 16:48:34 +04:00
|
|
|
Context m_context;
|
2012-10-17 15:14:03 +04:00
|
|
|
friend class InputMode;
|
|
|
|
std::unique_ptr<InputMode> m_mode;
|
2012-11-27 21:52:43 +04:00
|
|
|
std::vector<std::unique_ptr<InputMode>> m_mode_trash;
|
2013-02-18 17:07:30 +04:00
|
|
|
|
|
|
|
using Insertion = std::pair<InsertMode, std::vector<Key>>;
|
|
|
|
Insertion m_last_insert = {InsertMode::Insert, {}};
|
2012-06-06 03:15:19 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct prompt_aborted {};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-17 15:14:03 +04:00
|
|
|
#endif // input_handler_hh_INCLUDED
|