Context: only buffer context are not allowed, an editor is always needed

This commit is contained in:
Maxime Coste 2012-08-05 20:12:43 +02:00
parent 1ce2d3e302
commit 18ca422306
2 changed files with 11 additions and 7 deletions

View File

@ -33,21 +33,23 @@ Buffer::Buffer(String name, Type type,
if (not initial_content.empty())
apply_modification(Modification::make_insert(begin(), std::move(initial_content)));
Editor editor_for_hooks(*this);
Context context(editor_for_hooks);
if (type == Type::NewFile)
m_hook_manager.run_hook("BufNew", m_name, Context(*this));
m_hook_manager.run_hook("BufNew", m_name, context);
else if (type == Type::File)
m_hook_manager.run_hook("BufOpen", m_name, Context(*this));
m_hook_manager.run_hook("BufOpen", m_name, context);
m_hook_manager.run_hook("BufCreate", m_name, Context(*this));
m_hook_manager.run_hook("BufCreate", m_name, context);
}
Buffer::~Buffer()
{
m_hook_manager.run_hook("BufClose", m_name, Context(Editor(*this)));
m_windows.clear();
BufferManager::instance().unregister_buffer(this);
assert(m_change_listeners.empty());
m_hook_manager.run_hook("BufClose", m_name, Context(*this));
}
BufferIterator Buffer::iterator_at(const BufferCoord& line_and_column) const

View File

@ -13,8 +13,10 @@ struct Context
Context() {}
Context(Editor& editor)
: m_editor(&editor), m_buffer(&editor.buffer()) {}
Context(Buffer& buffer)
: m_buffer(&buffer) {}
// to allow func(Context(Editor(...)))
Context(Editor&& editor)
: m_editor(&editor), m_buffer(&editor.buffer()) {}
Buffer& buffer() const
{