rename (hook|option)_manager to (hook|option)s.

And Global(Hook|Option)Manager to Global(Hook|Option)s
This commit is contained in:
Maxime Coste 2012-11-22 13:50:29 +01:00
parent e981fb7957
commit 3b5530ac09
14 changed files with 63 additions and 63 deletions

View File

@ -18,8 +18,8 @@ Buffer::Buffer(String name, Flags flags,
m_history(), m_history_cursor(m_history.begin()),
m_last_save_undo_index(0),
m_timestamp(0),
m_hook_manager(GlobalHookManager::instance()),
m_option_manager(GlobalOptionManager::instance())
m_hooks(GlobalHooks::instance()),
m_options(GlobalOptions::instance())
{
BufferManager::instance().register_buffer(*this);
if (initial_content.empty() or initial_content.back() != '\n')
@ -29,11 +29,11 @@ Buffer::Buffer(String name, Flags flags,
Editor editor_for_hooks(*this);
Context context(editor_for_hooks);
if (flags & Flags::File and flags & Flags::New)
m_hook_manager.run_hook("BufNew", m_name, context);
m_hooks.run_hook("BufNew", m_name, context);
else
m_hook_manager.run_hook("BufOpen", m_name, context);
m_hooks.run_hook("BufOpen", m_name, context);
m_hook_manager.run_hook("BufCreate", m_name, context);
m_hooks.run_hook("BufCreate", m_name, context);
// now we may begin to record undo data
m_flags = flags;
@ -41,7 +41,7 @@ Buffer::Buffer(String name, Flags flags,
Buffer::~Buffer()
{
m_hook_manager.run_hook("BufClose", m_name, Context(Editor(*this)));
m_hooks.run_hook("BufClose", m_name, Context(Editor(*this)));
m_windows.clear();
BufferManager::instance().unregister_buffer(*this);

View File

@ -177,10 +177,10 @@ public:
const String& line_content(LineCount line) const
{ return m_lines[line].content; }
OptionManager& option_manager() { return m_option_manager; }
const OptionManager& option_manager() const { return m_option_manager; }
HookManager& hook_manager() { return m_hook_manager; }
const HookManager& hook_manager() const { return m_hook_manager; }
OptionManager& options() { return m_options; }
const OptionManager& options() const { return m_options; }
HookManager& hooks() { return m_hooks; }
const HookManager& hooks() const { return m_hooks; }
private:
friend class BufferIterator;
@ -230,8 +230,8 @@ private:
// observable state.
mutable std::vector<BufferChangeListener*> m_change_listeners;
OptionManager m_option_manager;
HookManager m_hook_manager;
OptionManager m_options;
HookManager m_hooks;
};
constexpr Buffer::Flags operator|(Buffer::Flags lhs, Buffer::Flags rhs)

View File

@ -265,7 +265,7 @@ void CommandManager::execute(const String& command_line,
}
if (it->type() == Token::Type::OptionExpand)
{
const Option& option = context.option_manager()[it->content()];
const Option& option = context.options()[it->content()];
params.push_back(option.as_string());
}
if (it->type() == Token::Type::CommandSeparator)

View File

@ -238,7 +238,7 @@ Buffer* open_fifo(const String& name , const String& filename, Context& context)
throw runtime_error("unable to open " + filename);
Buffer* buffer = new Buffer(name, Buffer::Flags::Fifo | Buffer::Flags::NoUndo);
buffer->hook_manager().add_hook("BufClose",
buffer->hooks().add_hook("BufClose",
[fd, buffer](const String&, const Context&) {
// Check if fifo is still alive, else fd may
// refer to another file/socket
@ -526,11 +526,11 @@ void add_hook(const CommandParameters& params, Context& context)
const String& scope = params[0];
const String& name = params[1];
if (scope == "global")
GlobalHookManager::instance().add_hook(name, hook_func);
GlobalHooks::instance().add_hook(name, hook_func);
else if (scope == "buffer")
context.buffer().hook_manager().add_hook(name, hook_func);
context.buffer().hooks().add_hook(name, hook_func);
else if (scope == "window")
context.window().hook_manager().add_hook(name , hook_func);
context.window().hooks().add_hook(name , hook_func);
else
throw runtime_error("error: no such hook container " + scope);
}
@ -636,13 +636,13 @@ void exec_commands_in_file(const CommandParameters& params,
CommandManager::instance().execute(file_content, context);
}
void set_option(OptionManager& option_manager, const CommandParameters& params,
void set_option(OptionManager& options, const CommandParameters& params,
Context& context)
{
if (params.size() != 2)
throw wrong_argument_count();
option_manager.set_option(params[0], Option(params[1]));
options.set_option(params[0], Option(params[1]));
}
class RegisterRestorer
@ -869,24 +869,24 @@ void register_commands()
cm.register_commands({ "setg", "setglobal" },
[](const CommandParameters& params, Context& context)
{ set_option(GlobalOptionManager::instance(), params, context); },
{ set_option(GlobalOptions::instance(), params, context); },
PerArgumentCommandCompleter({
[](const Context& context, const String& prefix, ByteCount cursor_pos)
{ return GlobalOptionManager::instance().complete_option_name(prefix, cursor_pos); }
{ return GlobalOptions::instance().complete_option_name(prefix, cursor_pos); }
}));
cm.register_commands({ "setb", "setbuffer" },
[](const CommandParameters& params, Context& context)
{ set_option(context.buffer().option_manager(), params, context); },
{ set_option(context.buffer().options(), params, context); },
PerArgumentCommandCompleter({
[](const Context& context, const String& prefix, ByteCount cursor_pos)
{ return context.buffer().option_manager().complete_option_name(prefix, cursor_pos); }
{ return context.buffer().options().complete_option_name(prefix, cursor_pos); }
}));
cm.register_commands({ "setw", "setwindow" },
[](const CommandParameters& params, Context& context)
{ set_option(context.window().option_manager(), params, context); },
{ set_option(context.window().options(), params, context); },
PerArgumentCommandCompleter({
[](const Context& context, const String& prefix, ByteCount cursor_pos)
{ return context.window().option_manager().complete_option_name(prefix, cursor_pos); }
{ return context.window().options().complete_option_name(prefix, cursor_pos); }
}));
cm.register_commands({"ca", "colalias"}, define_color_alias);

View File

@ -84,13 +84,13 @@ struct Context
m_ui.reset(&ui);
}
OptionManager& option_manager() const
OptionManager& options() const
{
if (has_window())
return window().option_manager();
return window().options();
if (has_buffer())
return buffer().option_manager();
return GlobalOptionManager::instance();
return buffer().options();
return GlobalOptions::instance();
}
void print_status(const String& status) const

View File

@ -123,9 +123,9 @@ Buffer* create_buffer_from_file(const String& filename)
at_file_begin = false;
}
OptionManager& option_manager = buffer->option_manager();
option_manager.set_option("eolformat", Option(crlf ? "crlf" : "lf"));
option_manager.set_option("BOM", Option(bom ? "utf-8" : "no"));
OptionManager& options = buffer->options();
options.set_option("eolformat", Option(crlf ? "crlf" : "lf"));
options.set_option("BOM", Option(bom ? "utf-8" : "no"));
// if the file ended with a \n, remove the \n added by the buffer
if (*(buffer->end() - 2) == '\n')
@ -155,7 +155,7 @@ static void write(int fd, const memoryview<char>& data, const String& filename)
void write_buffer_to_file(const Buffer& buffer, const String& filename)
{
String eolformat = buffer.option_manager()["eolformat"].as_string();
String eolformat = buffer.options()["eolformat"].as_string();
if (eolformat == "crlf")
eolformat = "\r\n";
else
@ -168,7 +168,7 @@ void write_buffer_to_file(const Buffer& buffer, const String& filename)
throw file_access_error(filename, strerror(errno));
auto close_fd = on_scope_end([fd]{ close(fd); });
if (buffer.option_manager()["BOM"].as_string() == "utf-8")
if (buffer.options()["BOM"].as_string() == "utf-8")
::write(fd, "\xEF\xBB\xBF", 3);
for (LineCount i = 0; i < buffer.line_count(); ++i)

View File

@ -37,7 +37,7 @@ void cleanup_whitespaces(Buffer& buffer, Selection& selection, String& content)
void expand_tabulations(Buffer& buffer, Selection& selection, String& content)
{
const int tabstop = buffer.option_manager()["tabstop"].as_int();
const int tabstop = buffer.options()["tabstop"].as_int();
if (content == "\t")
{
int column = 0;

View File

@ -153,7 +153,7 @@ HighlighterAndId colorize_regex_factory(Window& window,
void expand_tabulations(Window& window, DisplayBuffer& display_buffer)
{
const int tabstop = window.option_manager()["tabstop"].as_int();
const int tabstop = window.options()["tabstop"].as_int();
for (auto& line : display_buffer.lines())
{
for (auto atom_it = line.begin(); atom_it != line.end(); ++atom_it)

View File

@ -24,14 +24,14 @@ private:
HookManager()
: m_parent(nullptr) {}
// the only one allowed to construct a root hook manager
friend class GlobalHookManager;
friend class GlobalHooks;
HookManager* m_parent;
std::unordered_map<String, std::vector<HookFunc>> m_hook;
};
class GlobalHookManager : public HookManager,
public Singleton<GlobalHookManager>
class GlobalHooks : public HookManager,
public Singleton<GlobalHooks>
{
};

View File

@ -239,7 +239,7 @@ void do_join(Context& context)
void do_indent(Context& context)
{
const char* spaces = " ";
int width = std::min(context.option_manager()["indentwidth"].as_int(), 16);
int width = std::min(context.options()["indentwidth"].as_int(), 16);
String indent(spaces, spaces + width);
Editor& editor = context.editor();
@ -252,7 +252,7 @@ void do_indent(Context& context)
void do_deindent(Context& context)
{
int width = context.option_manager()["indentwidth"].as_int();
int width = context.options()["indentwidth"].as_int();
Editor& editor = context.editor();
SelectionAndCapturesList sels = editor.selections();
auto restore_sels = on_scope_end([&]{ editor.select(std::move(sels)); });
@ -571,7 +571,7 @@ void register_env_vars()
{ return runtime_directory(); });
shell_manager.register_env_var("opt_.+",
[](const String& name, const Context& context)
{ return context.option_manager()[name.substr(4_byte)].as_string(); });
{ return context.options()[name.substr(4_byte)].as_string(); });
shell_manager.register_env_var("reg_.+",
[](const String& name, const Context& context)
{ return RegisterManager::instance()[name[4]].values(context)[0]; });
@ -678,8 +678,8 @@ int main(int argc, char* argv[])
return 0;
}
GlobalOptionManager option_manager;
GlobalHookManager hook_manager;
GlobalOptions global_options;
GlobalHooks global_hooks;
ShellManager shell_manager;
CommandManager command_manager;
BufferManager buffer_manager;

View File

@ -90,7 +90,7 @@ void OptionManager::on_option_changed(const String& name, const Option& value)
watcher->on_option_changed(name, value);
}
GlobalOptionManager::GlobalOptionManager()
GlobalOptions::GlobalOptions()
: OptionManager()
{
set_option("tabstop", Option(8));

View File

@ -69,7 +69,7 @@ private:
OptionManager()
: m_parent(nullptr) {}
// the only one allowed to construct a root option manager
friend class GlobalOptionManager;
friend class GlobalOptions;
OptionMap m_options;
OptionManager* m_parent;
@ -80,11 +80,11 @@ private:
std::vector<OptionManagerWatcher*> m_watchers;
};
class GlobalOptionManager : public OptionManager,
public Singleton<GlobalOptionManager>
class GlobalOptions : public OptionManager,
public Singleton<GlobalOptions>
{
public:
GlobalOptionManager();
GlobalOptions();
};

View File

@ -13,24 +13,24 @@ namespace Kakoune
Window::Window(Buffer& buffer)
: Editor(buffer),
m_hook_manager(buffer.hook_manager()),
m_option_manager(buffer.option_manager())
m_hooks(buffer.hooks()),
m_options(buffer.options())
{
HighlighterRegistry& registry = HighlighterRegistry::instance();
m_hook_manager.run_hook("WinCreate", buffer.name(), Context(*this));
m_option_manager.register_watcher(*this);
m_hooks.run_hook("WinCreate", buffer.name(), Context(*this));
m_options.register_watcher(*this);
registry.add_highlighter_to_group(*this, m_highlighters, "expand_tabs", HighlighterParameters());
registry.add_highlighter_to_group(*this, m_highlighters, "highlight_selections", HighlighterParameters());
for (auto& option : m_option_manager.flatten_options())
for (auto& option : m_options.flatten_options())
on_option_changed(option.first, option.second);
}
Window::~Window()
{
m_option_manager.unregister_watcher(*this);
m_options.unregister_watcher(*this);
}
void Window::center_selection()
@ -176,14 +176,14 @@ String Window::status_line() const
void Window::on_incremental_insertion_end()
{
SelectionAndCapturesList backup(selections());
hook_manager().run_hook("InsertEnd", "", Context(*this));
hooks().run_hook("InsertEnd", "", Context(*this));
select(backup);
}
void Window::on_option_changed(const String& name, const Option& option)
{
String desc = name + "=" + option.as_string();
m_hook_manager.run_hook("WinSetOption", desc, Context(*this));
m_hooks.run_hook("WinSetOption", desc, Context(*this));
}
}

View File

@ -41,10 +41,10 @@ public:
HighlighterGroup& highlighters() { return m_highlighters; }
OptionManager& option_manager() { return m_option_manager; }
const OptionManager& option_manager() const { return m_option_manager; }
HookManager& hook_manager() { return m_hook_manager; }
const HookManager& hook_manager() const { return m_hook_manager; }
OptionManager& options() { return m_options; }
const OptionManager& options() const { return m_options; }
HookManager& hooks() { return m_hooks; }
const HookManager& hooks() const { return m_hooks; }
size_t timestamp() const { return m_timestamp; }
void forget_timestamp() { m_timestamp = -1; }
@ -66,8 +66,8 @@ private:
HighlighterGroup m_highlighters;
HookManager m_hook_manager;
OptionManager m_option_manager;
HookManager m_hooks;
OptionManager m_options;
size_t m_timestamp = -1;
};