Remove BufferChangeListener

This commit is contained in:
Maxime Coste 2014-05-14 01:01:46 +01:00
parent bf98b38afd
commit c3f4ef9ba2
2 changed files with 0 additions and 52 deletions

View File

@ -68,16 +68,10 @@ Buffer::~Buffer()
m_options.unregister_watcher(*this); m_options.unregister_watcher(*this);
BufferManager::instance().unregister_buffer(*this); BufferManager::instance().unregister_buffer(*this);
m_values.clear(); m_values.clear();
kak_assert(m_change_listeners.empty());
} }
void Buffer::reload(std::vector<String> lines, time_t fs_timestamp) void Buffer::reload(std::vector<String> lines, time_t fs_timestamp)
{ {
// use back coord to simulate the persistance of the last end of line
// as buffers are expected to never be empty.
for (auto listener : m_change_listeners)
listener->on_erase(*this, {0,0}, back_coord(), true);
m_changes.push_back({ Change::Erase, {0,0}, back_coord(), true }); m_changes.push_back({ Change::Erase, {0,0}, back_coord(), true });
m_history.clear(); m_history.clear();
@ -100,9 +94,6 @@ void Buffer::reload(std::vector<String> lines, time_t fs_timestamp)
m_fs_timestamp = fs_timestamp; m_fs_timestamp = fs_timestamp;
m_changes.push_back({ Change::Insert, {0,0}, back_coord(), true }); m_changes.push_back({ Change::Insert, {0,0}, back_coord(), true });
for (auto listener : m_change_listeners)
listener->on_insert(*this, {0,0}, back_coord(), true);
} }
String Buffer::display_name() const String Buffer::display_name() const
@ -522,8 +513,6 @@ ByteCoord Buffer::do_insert(ByteCoord pos, const String& content)
} }
m_changes.push_back({ Change::Insert, begin, end, at_end }); m_changes.push_back({ Change::Insert, begin, end, at_end });
for (auto listener : m_change_listeners)
listener->on_insert(*this, begin, end, at_end);
return begin; return begin;
} }
@ -553,8 +542,6 @@ ByteCoord Buffer::do_erase(ByteCoord begin, ByteCoord end)
m_lines[i].start -= length; m_lines[i].start -= length;
m_changes.push_back({ Change::Erase, begin, end, is_end(begin) }); m_changes.push_back({ Change::Erase, begin, end, is_end(begin) });
for (auto listener : m_change_listeners)
listener->on_erase(*this, begin, end, is_end(begin));
return next; return next;
} }

View File

@ -63,15 +63,6 @@ private:
ByteCoord m_coord; ByteCoord m_coord;
}; };
class BufferChangeListener
{
public:
virtual void on_insert(const Buffer& buffer,
ByteCoord begin, ByteCoord end, bool at_end) = 0;
virtual void on_erase(const Buffer& buffer,
ByteCoord begin, ByteCoord end, bool at_end) = 0;
};
// A Buffer is a in-memory representation of a file // A Buffer is a in-memory representation of a file
// //
// The Buffer class permits to read and mutate this file // The Buffer class permits to read and mutate this file
@ -170,8 +161,6 @@ public:
void run_hook_in_own_context(const String& hook_name, const String& param); void run_hook_in_own_context(const String& hook_name, const String& param);
std::unordered_set<BufferChangeListener*>& change_listeners() const { return m_change_listeners; }
void reload(std::vector<String> lines, time_t fs_timestamp = InvalidTime); void reload(std::vector<String> lines, time_t fs_timestamp = InvalidTime);
void check_invariant() const; void check_invariant() const;
@ -230,10 +219,6 @@ private:
time_t m_fs_timestamp; time_t m_fs_timestamp;
// this is mutable as adding or removing listeners is not muting the
// buffer observable state.
mutable std::unordered_set<BufferChangeListener*> m_change_listeners;
OptionManager m_options; OptionManager m_options;
HookManager m_hooks; HookManager m_hooks;
KeymapManager m_keymaps; KeymapManager m_keymaps;
@ -270,30 +255,6 @@ private:
} }
}; };
struct BufferListenerRegisterFuncs
{
static void insert(const Buffer& buffer, BufferChangeListener& listener)
{
buffer.change_listeners().insert(&listener);
}
static void remove(const Buffer& buffer, BufferChangeListener& listener)
{
buffer.change_listeners().erase(&listener);
}
};
class BufferChangeListener_AutoRegister
: public BufferChangeListener,
public AutoRegister<BufferChangeListener_AutoRegister,
BufferListenerRegisterFuncs, Buffer>
{
public:
BufferChangeListener_AutoRegister(Buffer& buffer)
: AutoRegister(buffer) {}
Buffer& buffer() const { return registry(); }
};
} }
#include "buffer.inl.hh" #include "buffer.inl.hh"