From 8f7019287562d29644e3b952ee091cb8c800432d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 23 Sep 2011 14:29:42 +0000 Subject: [PATCH] CommandManager: now a singleton --- src/command_manager.hh | 4 ++-- src/main.cc | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/command_manager.hh b/src/command_manager.hh index 037ec2c9..c3d5fca4 100644 --- a/src/command_manager.hh +++ b/src/command_manager.hh @@ -7,7 +7,7 @@ #include #include -#include "exception.hh" +#include "utils.hh" #include "completion.hh" namespace Kakoune @@ -47,7 +47,7 @@ private: ArgumentCompleterList m_completers; }; -class CommandManager +class CommandManager : public Singleton { public: void execute(const std::string& command_line); diff --git a/src/main.cc b/src/main.cc index 16bd6d5e..047c6aa4 100644 --- a/src/main.cc +++ b/src/main.cc @@ -329,17 +329,15 @@ void show_buffer(const CommandParameters& params) current_window = buffer->get_or_create_window(); } -CommandManager command_manager; -BufferManager buffer_manager; - void do_command() { try { - command_manager.execute(prompt(":", std::bind(&CommandManager::complete, - &command_manager, - std::placeholders::_1, - std::placeholders::_2))); + auto cmdline = prompt(":", std::bind(&CommandManager::complete, + &CommandManager::instance(), + _1, _2)); + + CommandManager::instance().execute(cmdline); } catch (prompt_aborted&) {} } @@ -400,6 +398,10 @@ std::unordered_map> keymap int main(int argc, char* argv[]) { init_ncurses(); + + CommandManager command_manager; + BufferManager buffer_manager; + command_manager.register_command(std::vector{ "e", "edit" }, edit, PerArgumentCommandCompleter{ complete_filename }); command_manager.register_command(std::vector{ "q", "quit" }, quit);