Buffer: modification tracking

This commit is contained in:
Maxime Coste 2011-10-05 14:21:24 +00:00
parent f4743e08bd
commit 4ce349fa02
4 changed files with 37 additions and 12 deletions

View File

@ -138,7 +138,7 @@ bool BufferIterator::is_end() const
Buffer::Buffer(const std::string& name, const BufferString& initial_content)
: m_name(name), m_history(1), m_history_cursor(m_history.begin()),
m_content(initial_content)
m_content(initial_content), m_last_save_undo_group(m_history.begin())
{
BufferManager::instance().register_buffer(this);
@ -350,4 +350,15 @@ void Buffer::delete_window(Window* window)
m_windows.erase(window_it);
}
bool Buffer::is_modified() const
{
return m_last_save_undo_group != m_history_cursor
or not m_current_undo_group.empty();
}
void Buffer::notify_saved()
{
m_last_save_undo_group = m_history_cursor;
}
}

View File

@ -106,6 +106,9 @@ public:
Window* get_or_create_window();
void delete_window(Window* window);
bool is_modified() const;
void notify_saved();
private:
BufferChar at(BufferPos position) const;
@ -144,7 +147,7 @@ private:
std::vector<UndoGroup> m_history;
std::vector<UndoGroup>::iterator m_history_cursor;
UndoGroup m_current_undo_group;
UndoGroup m_current_undo_group;
void replay_modification(const Modification& modification);
void revert_modification(const Modification& modification);
@ -152,6 +155,8 @@ private:
void append_modification(Modification&& modification);
std::list<std::unique_ptr<Window>> m_windows;
std::vector<UndoGroup>::iterator m_last_save_undo_group;
};
}

View File

@ -382,6 +382,7 @@ void write_buffer(const CommandParameters& params)
std::string filename = params.empty() ? buffer.name() : params[0];
write_buffer_to_file(buffer, filename);
buffer.notify_saved();
}
bool quit_requested = false;

View File

@ -332,18 +332,26 @@ std::string Window::status_line() const
{
BufferCoord cursor = window_to_buffer(cursor_position());
std::ostringstream oss;
oss << m_buffer.name() << " -- " << cursor.line << "," << cursor.column
oss << m_buffer.name();
if (m_buffer.is_modified())
oss << " [+]";
oss << " -- " << cursor.line << "," << cursor.column
<< " -- " << m_selections.size() << " sel -- ";
switch (m_select_mode)
if (m_current_inserter)
oss << "[Insert]";
else
{
case SelectMode::Normal:
oss << "[Normal]";
break;
case SelectMode::Append:
oss << "[Append]";
break;
default:
assert(false);
switch (m_select_mode)
{
case SelectMode::Normal:
oss << "[Normal]";
break;
case SelectMode::Append:
oss << "[Append]";
break;
default:
assert(false);
}
}
return oss.str();
}