mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-26 21:22:00 +03:00
move Client::m_name to context, no more need for DraftUI
This commit is contained in:
parent
ad275d1d1c
commit
f8cadc0c57
@ -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<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);
|
||||
}
|
||||
@ -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") };
|
||||
}
|
||||
|
||||
|
@ -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<UserInterface> m_ui;
|
||||
|
||||
String m_name;
|
||||
DisplayLine m_status_line;
|
||||
};
|
||||
|
||||
|
@ -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>& 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);
|
||||
|
@ -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<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>
|
||||
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<UserInterface>(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");
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<Editor> m_editor;
|
||||
safe_ptr<InputHandler> m_input_handler;
|
||||
safe_ptr<Client> m_client;
|
||||
|
||||
String m_name;
|
||||
|
||||
using JumpList = std::vector<DynamicSelectionList>;
|
||||
JumpList m_jump_list;
|
||||
JumpList::iterator m_current_jump = m_jump_list.begin();
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user