move Client::m_name to context, no more need for DraftUI

This commit is contained in:
Maxime Coste 2013-11-14 20:51:25 +00:00
parent ad275d1d1c
commit f8cadc0c57
7 changed files with 24 additions and 41 deletions

View File

@ -1103,9 +1103,9 @@ void InputMode::reset_normal_mode()
m_input_handler.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_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<UserInterface>&& ui, Editor& editor, String name) Client::Client(std::unique_ptr<UserInterface>&& 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); context().set_client(*this);
} }
@ -1260,8 +1260,8 @@ DisplayLine Client::generate_mode_line() const
oss << " [recording (" << m_input_handler.recording_reg() << ")]"; oss << " [recording (" << m_input_handler.recording_reg() << ")]";
if (context().buffer().flags() & Buffer::Flags::New) if (context().buffer().flags() & Buffer::Flags::New)
oss << " [new file]"; oss << " [new file]";
oss << " [" << m_input_handler.mode().description() << "]" << " - " << name() oss << " [" << m_input_handler.mode().description() << "]" << " - "
<< "@[" << Server::instance().session() << "]"; << context().name() << "@[" << Server::instance().session() << "]";
return { oss.str(), get_color("StatusLine") }; return { oss.str(), get_color("StatusLine") };
} }

View File

@ -38,7 +38,7 @@ enum class InsertMode : unsigned;
class InputHandler : public SafeCountable class InputHandler : public SafeCountable
{ {
public: public:
InputHandler(Editor& editor); InputHandler(Editor& editor, String name = "");
~InputHandler(); ~InputHandler();
// switch to insert mode // switch to insert mode
@ -105,9 +105,6 @@ public:
// handle all the keys currently available in the user interface // handle all the keys currently available in the user interface
void handle_available_input(); 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 print_status(DisplayLine status_line);
void redraw_ifn(); void redraw_ifn();
@ -126,7 +123,6 @@ private:
std::unique_ptr<UserInterface> m_ui; std::unique_ptr<UserInterface> m_ui;
String m_name;
DisplayLine m_status_line; DisplayLine m_status_line;
}; };

View File

@ -110,7 +110,7 @@ void ClientManager::ensure_no_client_uses_buffer(Buffer& buffer)
continue; continue;
if (client->context().editor().is_editing()) 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() + '\''); buffer.display_name() + '\'');
// change client context to edit the first buffer which is not the // 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 bool ClientManager::validate_client_name(const String& name) const
{ {
auto it = find_if(m_clients, [&](const std::unique_ptr<Client>& client) auto it = find_if(m_clients, [&](const std::unique_ptr<Client>& client)
{ return client->name() == name; }); { return client->context().name() == name; });
return it == m_clients.end(); return it == m_clients.end();
} }
@ -143,7 +143,7 @@ Client& ClientManager::get_client(const String& name)
{ {
for (auto& client : m_clients) for (auto& client : m_clients)
{ {
if (client->name() == name) if (client->context().name() == name)
return *client; return *client;
} }
throw runtime_error("no client named: " + name); throw runtime_error("no client named: " + name);

View File

@ -531,24 +531,6 @@ void map_key(CommandParameters params, Context& context)
keymaps.map_key(key[0], keymap_mode, std::move(mapping)); keymaps.map_key(key[0], keymap_mode, std::move(mapping));
} }
class DraftUI : public UserInterface
{
public:
void menu_show(memoryview<String>, 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<typename Func> template<typename Func>
void context_wrap(CommandParameters params, Context& context, Func func) 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")) if (parser.has_option("draft"))
{ {
Editor& editor = real_context.editor(); Editor& editor = real_context.editor();
Client client(std::unique_ptr<UserInterface>(new DraftUI()), editor, InputHandler input_handler(editor, real_context.name());
real_context.has_client() ? real_context.client().name() : "");
DynamicSelectionList sels{editor.buffer(), editor.selections()}; DynamicSelectionList sels{editor.buffer(), editor.selections()};
auto restore_sels = on_scope_end([&]{ editor.select(sels); }); 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) for (auto& sel : sels)
{ {
editor.select(sel); editor.select(sel);
func(parser, client.context()); func(parser, input_handler.context());
} }
} }
else else
func(parser, client.context()); func(parser, input_handler.context());
} }
else else
{ {
@ -715,8 +696,8 @@ void set_client_name(CommandParameters params, Context& context)
ParametersParser parser(params, OptionMap{}, ParametersParser parser(params, OptionMap{},
ParametersParser::Flags::None, 1, 1); ParametersParser::Flags::None, 1, 1);
if (ClientManager::instance().validate_client_name(params[0])) if (ClientManager::instance().validate_client_name(params[0]))
context.client().set_name(params[0]); context.set_name(params[0]);
else if (context.client().name() != params[0]) else if (context.name() != params[0])
throw runtime_error("client name '" + params[0] + "' is not unique"); throw runtime_error("client name '" + params[0] + "' is not unique");
} }

View File

@ -9,8 +9,9 @@ namespace Kakoune
Context::Context() = default; Context::Context() = default;
Context::Context(InputHandler& input_handler, Editor& editor) Context::Context(InputHandler& input_handler, Editor& editor, String name)
: m_input_handler(&input_handler), m_editor(&editor) {} : m_input_handler(&input_handler), m_editor(&editor),
m_name(std::move(name)) {}
Context::~Context() = default; Context::~Context() = default;

View File

@ -25,7 +25,7 @@ class Context
{ {
public: public:
Context(); Context();
Context(InputHandler& input_handler, Editor& editor); Context(InputHandler& input_handler, Editor& editor, String name = "");
~Context(); ~Context();
Context(const Context&) = delete; Context(const Context&) = delete;
@ -64,11 +64,16 @@ public:
const DynamicSelectionList& jump_backward(); const DynamicSelectionList& jump_backward();
void forget_jumps_to_buffer(Buffer& buffer); 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: private:
safe_ptr<Editor> m_editor; safe_ptr<Editor> m_editor;
safe_ptr<InputHandler> m_input_handler; safe_ptr<InputHandler> m_input_handler;
safe_ptr<Client> m_client; safe_ptr<Client> m_client;
String m_name;
using JumpList = std::vector<DynamicSelectionList>; using JumpList = std::vector<DynamicSelectionList>;
JumpList m_jump_list; JumpList m_jump_list;
JumpList::iterator m_current_jump = m_jump_list.begin(); JumpList::iterator m_current_jump = m_jump_list.begin();

View File

@ -102,7 +102,7 @@ void register_env_vars()
}, { }, {
"client", "client",
[](const String& name, const Context& context) [](const String& name, const Context& context)
{ return context.client().name(); } { return context.name(); }
}, { }, {
"cursor_line", "cursor_line",
[](const String& name, const Context& context) [](const String& name, const Context& context)