Buffer: modification tracking
This commit is contained in:
parent
f4743e08bd
commit
4ce349fa02
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -332,8 +332,15 @@ 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 -- ";
|
||||
if (m_current_inserter)
|
||||
oss << "[Insert]";
|
||||
else
|
||||
{
|
||||
switch (m_select_mode)
|
||||
{
|
||||
case SelectMode::Normal:
|
||||
|
@ -345,6 +352,7 @@ std::string Window::status_line() const
|
|||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user