From f8cadc0c573b0e91b7542f26415e5c5cddcc5305 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 14 Nov 2013 20:51:25 +0000 Subject: [PATCH] move Client::m_name to context, no more need for DraftUI --- src/client.cc | 10 +++++----- src/client.hh | 6 +----- src/client_manager.cc | 6 +++--- src/commands.cc | 29 +++++------------------------ src/context.cc | 5 +++-- src/context.hh | 7 ++++++- src/main.cc | 2 +- 7 files changed, 24 insertions(+), 41 deletions(-) diff --git a/src/client.cc b/src/client.cc index 96f91ac73..f75a14634 100644 --- a/src/client.cc +++ b/src/client.cc @@ -1103,9 +1103,9 @@ void InputMode::reset_normal_mode() m_input_handler.reset_normal_mode(); } -InputHandler::InputHandler(Editor& editor) +InputHandler::InputHandler(Editor& editor, String name) : m_mode(new InputModes::Normal(*this)), - m_context(*this, editor) + m_context(*this, editor, std::move(name)) { } @@ -1221,7 +1221,7 @@ void InputHandler::clear_mode_trash() } Client::Client(std::unique_ptr&& ui, Editor& editor, String name) - : m_input_handler(editor), m_ui(std::move(ui)), m_name(name) + : m_input_handler(editor, std::move(name)), m_ui(std::move(ui)) { context().set_client(*this); } @@ -1260,8 +1260,8 @@ DisplayLine Client::generate_mode_line() const oss << " [recording (" << m_input_handler.recording_reg() << ")]"; if (context().buffer().flags() & Buffer::Flags::New) oss << " [new file]"; - oss << " [" << m_input_handler.mode().description() << "]" << " - " << name() - << "@[" << Server::instance().session() << "]"; + oss << " [" << m_input_handler.mode().description() << "]" << " - " + << context().name() << "@[" << Server::instance().session() << "]"; return { oss.str(), get_color("StatusLine") }; } diff --git a/src/client.hh b/src/client.hh index 7edbce15d..37e1ee153 100644 --- a/src/client.hh +++ b/src/client.hh @@ -38,7 +38,7 @@ enum class InsertMode : unsigned; class InputHandler : public SafeCountable { public: - InputHandler(Editor& editor); + InputHandler(Editor& editor, String name = ""); ~InputHandler(); // switch to insert mode @@ -105,9 +105,6 @@ public: // handle all the keys currently available in the user interface void handle_available_input(); - const String& name() const { return m_name; } - void set_name(String name) { m_name = std::move(name); } - void print_status(DisplayLine status_line); void redraw_ifn(); @@ -126,7 +123,6 @@ private: std::unique_ptr m_ui; - String m_name; DisplayLine m_status_line; }; diff --git a/src/client_manager.cc b/src/client_manager.cc index 24454eac7..745a3f4b5 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -110,7 +110,7 @@ void ClientManager::ensure_no_client_uses_buffer(Buffer& buffer) continue; if (client->context().editor().is_editing()) - throw runtime_error("client '" + client->name() + "' is inserting in '" + + throw runtime_error("client '" + client->context().name() + "' is inserting in '" + buffer.display_name() + '\''); // change client context to edit the first buffer which is not the @@ -135,7 +135,7 @@ void ClientManager::ensure_no_client_uses_buffer(Buffer& buffer) bool ClientManager::validate_client_name(const String& name) const { auto it = find_if(m_clients, [&](const std::unique_ptr& client) - { return client->name() == name; }); + { return client->context().name() == name; }); return it == m_clients.end(); } @@ -143,7 +143,7 @@ Client& ClientManager::get_client(const String& name) { for (auto& client : m_clients) { - if (client->name() == name) + if (client->context().name() == name) return *client; } throw runtime_error("no client named: " + name); diff --git a/src/commands.cc b/src/commands.cc index 43dd430a4..42546a485 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -531,24 +531,6 @@ void map_key(CommandParameters params, Context& context) keymaps.map_key(key[0], keymap_mode, std::move(mapping)); } -class DraftUI : public UserInterface -{ -public: - void menu_show(memoryview, DisplayCoord, ColorPair, ColorPair, MenuStyle) override {} - void menu_select(int) override {} - void menu_hide() override {} - - void info_show(const String&, const String&, DisplayCoord, ColorPair, MenuStyle) override {} - void info_hide() override {} - - void draw(const DisplayBuffer&, const DisplayLine&, const DisplayLine&) override {} - DisplayCoord dimensions() override { return {0,0}; } - bool is_key_available() override { return false; } - Key get_key() override { return 'a'; } - - void set_input_callback(InputCallback) override {} -}; - template void context_wrap(CommandParameters params, Context& context, Func func) { @@ -562,8 +544,7 @@ void context_wrap(CommandParameters params, Context& context, Func func) if (parser.has_option("draft")) { Editor& editor = real_context.editor(); - Client client(std::unique_ptr(new DraftUI()), editor, - real_context.has_client() ? real_context.client().name() : ""); + InputHandler input_handler(editor, real_context.name()); DynamicSelectionList sels{editor.buffer(), editor.selections()}; auto restore_sels = on_scope_end([&]{ editor.select(sels); }); @@ -572,11 +553,11 @@ void context_wrap(CommandParameters params, Context& context, Func func) for (auto& sel : sels) { editor.select(sel); - func(parser, client.context()); + func(parser, input_handler.context()); } } else - func(parser, client.context()); + func(parser, input_handler.context()); } else { @@ -715,8 +696,8 @@ void set_client_name(CommandParameters params, Context& context) ParametersParser parser(params, OptionMap{}, ParametersParser::Flags::None, 1, 1); if (ClientManager::instance().validate_client_name(params[0])) - context.client().set_name(params[0]); - else if (context.client().name() != params[0]) + context.set_name(params[0]); + else if (context.name() != params[0]) throw runtime_error("client name '" + params[0] + "' is not unique"); } diff --git a/src/context.cc b/src/context.cc index 137b8213d..d43e85ac5 100644 --- a/src/context.cc +++ b/src/context.cc @@ -9,8 +9,9 @@ namespace Kakoune Context::Context() = default; -Context::Context(InputHandler& input_handler, Editor& editor) - : m_input_handler(&input_handler), m_editor(&editor) {} +Context::Context(InputHandler& input_handler, Editor& editor, String name) + : m_input_handler(&input_handler), m_editor(&editor), + m_name(std::move(name)) {} Context::~Context() = default; diff --git a/src/context.hh b/src/context.hh index 967ebaf3a..b4362eafa 100644 --- a/src/context.hh +++ b/src/context.hh @@ -25,7 +25,7 @@ class Context { public: Context(); - Context(InputHandler& input_handler, Editor& editor); + Context(InputHandler& input_handler, Editor& editor, String name = ""); ~Context(); Context(const Context&) = delete; @@ -64,11 +64,16 @@ public: const DynamicSelectionList& jump_backward(); void forget_jumps_to_buffer(Buffer& buffer); + const String& name() const { return m_name; } + void set_name(String name) { m_name = std::move(name); } + private: safe_ptr m_editor; safe_ptr m_input_handler; safe_ptr m_client; + String m_name; + using JumpList = std::vector; JumpList m_jump_list; JumpList::iterator m_current_jump = m_jump_list.begin(); diff --git a/src/main.cc b/src/main.cc index 17c4f6918..bb693903f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -102,7 +102,7 @@ void register_env_vars() }, { "client", [](const String& name, const Context& context) - { return context.client().name(); } + { return context.name(); } }, { "cursor_line", [](const String& name, const Context& context)