From 1ab486b0d8ed714535e8428ab6ffbbd567a40f74 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 16 Oct 2012 17:15:09 +0200 Subject: [PATCH] verious refactoring --- src/commands.cc | 4 +--- src/context.hh | 5 +++-- src/main.cc | 38 ++++++++++++++++++-------------------- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index 81fb5fb1..2f4d30d6 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -678,9 +678,7 @@ void exec_keys(const KeyList& keys, Context& context) scoped_edition edition(context.editor()); - Context new_context(batch_client); - new_context.change_editor(context.editor()); - new_context.change_ui(batch_ui); + Context new_context(batch_client, context.editor(), batch_ui); while (batch_ui.has_key_left()) batch_client.handle_next_input(new_context); context.change_editor(new_context.editor()); diff --git a/src/context.hh b/src/context.hh index 7b03708e..ed921580 100644 --- a/src/context.hh +++ b/src/context.hh @@ -20,8 +20,8 @@ struct Context explicit Context(Editor& editor) : m_editor(&editor) {} - explicit Context(Client& client) - : m_client(&client) {} + Context(Client& client, Editor& editor, UserInterface& ui) + : m_client(&client), m_editor(&editor), m_ui(&ui) {} // to allow func(Context(Editor(...))) // make sure the context will not survive the next ';' @@ -29,6 +29,7 @@ struct Context : m_editor(&editor) {} Context(const Context&) = delete; + Context(Context&&) = default; Context& operator=(const Context&) = delete; Buffer& buffer() const diff --git a/src/main.cc b/src/main.cc index 4761d6ff..aabea0d8 100644 --- a/src/main.cc +++ b/src/main.cc @@ -18,6 +18,7 @@ #include "context.hh" #include "ncurses.hh" #include "string.hh" +#include "file.hh" #include "color_registry.hh" #if defined(__APPLE__) @@ -502,9 +503,6 @@ int main(int argc, char* argv[]) Client client; NCursesUI ui; - Context context(client); - context.change_ui(ui); - try { Context initialisation_context; @@ -513,40 +511,40 @@ int main(int argc, char* argv[]) } catch (Kakoune::runtime_error& error) { - context.print_status(error.description()); + ui.print_status(error.description(), -1); } - write_debug("*** This is the debug buffer, where debug info will be written ***\n"); write_debug("utf-8 test: é á ï"); + Buffer* buffer = nullptr; if (argc > 1) { - String cmd = "edit "; - for (int i = 1; i < argc; ++i) - cmd += String(" ") + argv[i]; - command_manager.execute(cmd, context); + buffer = create_buffer_from_file(argv[1]); + if (not buffer) + { + ui.print_status("new file "_str + argv[1], -1); + buffer = new Buffer(argv[1], Buffer::Type::NewFile); + } } else - { - auto buffer = new Buffer("*scratch*", Buffer::Type::Scratch); - context.change_editor(*buffer->get_or_create_window()); - } + buffer = new Buffer("*scratch*", Buffer::Type::Scratch); - event_manager.watch(0, [&](int) { client.handle_next_input(context); }); - - context.draw_ifn(); - while(not quit_requested) - { + Context context(client, *buffer->get_or_create_window(), ui); + event_manager.watch(0, [&](int) { try { - event_manager.handle_next_events(); + client.handle_next_input(context); } catch (Kakoune::runtime_error& error) { context.print_status(error.description()); } - } + }); + + context.draw_ifn(); + while(not quit_requested) + event_manager.handle_next_events(); } catch (Kakoune::exception& error) {