Buffer: fix modified handling

This commit is contained in:
Maxime Coste 2011-11-03 13:44:02 +00:00
parent 4982620c4c
commit 9cf7cb682c
2 changed files with 10 additions and 4 deletions

View File

@ -22,7 +22,7 @@ Buffer::Buffer(const std::string& name, Type type,
const BufferString& initial_content)
: m_name(name), m_type(type),
m_history(1), m_history_cursor(m_history.begin()),
m_content(initial_content), m_last_save_undo_group(m_history.begin())
m_content(initial_content), m_last_save_undo_index(0)
{
BufferManager::instance().register_buffer(this);
@ -154,6 +154,10 @@ void Buffer::begin_undo_group()
{
assert(m_current_undo_group.empty());
m_history.erase(m_history_cursor, m_history.end());
if (m_history.size() < m_last_save_undo_index)
m_last_save_undo_index = -1;
m_history_cursor = m_history.end();
}
@ -245,13 +249,15 @@ void Buffer::delete_window(Window* window)
bool Buffer::is_modified() const
{
return m_last_save_undo_group != m_history_cursor
size_t history_cursor_index = m_history_cursor - m_history.begin();
return m_last_save_undo_index != history_cursor_index
or not m_current_undo_group.empty();
}
void Buffer::notify_saved()
{
m_last_save_undo_group = m_history_cursor;
size_t history_cursor_index = m_history_cursor - m_history.begin();
m_last_save_undo_index = history_cursor_index;
}
void Buffer::register_modification_listener(BufferModificationListener* listener) const

View File

@ -184,7 +184,7 @@ private:
std::list<std::unique_ptr<Window>> m_windows;
std::vector<UndoGroup>::iterator m_last_save_undo_group;
size_t m_last_save_undo_index;
mutable std::vector<BufferModificationListener*> m_modification_listeners;
};