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)
|
Buffer::Buffer(const std::string& name, const BufferString& initial_content)
|
||||||
: m_name(name), m_history(1), m_history_cursor(m_history.begin()),
|
: 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);
|
BufferManager::instance().register_buffer(this);
|
||||||
|
|
||||||
|
@ -350,4 +350,15 @@ void Buffer::delete_window(Window* window)
|
||||||
m_windows.erase(window_it);
|
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();
|
Window* get_or_create_window();
|
||||||
void delete_window(Window* window);
|
void delete_window(Window* window);
|
||||||
|
|
||||||
|
bool is_modified() const;
|
||||||
|
void notify_saved();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BufferChar at(BufferPos position) const;
|
BufferChar at(BufferPos position) const;
|
||||||
|
|
||||||
|
@ -144,7 +147,7 @@ private:
|
||||||
|
|
||||||
std::vector<UndoGroup> m_history;
|
std::vector<UndoGroup> m_history;
|
||||||
std::vector<UndoGroup>::iterator m_history_cursor;
|
std::vector<UndoGroup>::iterator m_history_cursor;
|
||||||
UndoGroup m_current_undo_group;
|
UndoGroup m_current_undo_group;
|
||||||
|
|
||||||
void replay_modification(const Modification& modification);
|
void replay_modification(const Modification& modification);
|
||||||
void revert_modification(const Modification& modification);
|
void revert_modification(const Modification& modification);
|
||||||
|
@ -152,6 +155,8 @@ private:
|
||||||
void append_modification(Modification&& modification);
|
void append_modification(Modification&& modification);
|
||||||
|
|
||||||
std::list<std::unique_ptr<Window>> m_windows;
|
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];
|
std::string filename = params.empty() ? buffer.name() : params[0];
|
||||||
|
|
||||||
write_buffer_to_file(buffer, filename);
|
write_buffer_to_file(buffer, filename);
|
||||||
|
buffer.notify_saved();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool quit_requested = false;
|
bool quit_requested = false;
|
||||||
|
|
|
@ -332,18 +332,26 @@ std::string Window::status_line() const
|
||||||
{
|
{
|
||||||
BufferCoord cursor = window_to_buffer(cursor_position());
|
BufferCoord cursor = window_to_buffer(cursor_position());
|
||||||
std::ostringstream oss;
|
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 -- ";
|
<< " -- " << m_selections.size() << " sel -- ";
|
||||||
switch (m_select_mode)
|
if (m_current_inserter)
|
||||||
|
oss << "[Insert]";
|
||||||
|
else
|
||||||
{
|
{
|
||||||
case SelectMode::Normal:
|
switch (m_select_mode)
|
||||||
oss << "[Normal]";
|
{
|
||||||
break;
|
case SelectMode::Normal:
|
||||||
case SelectMode::Append:
|
oss << "[Normal]";
|
||||||
oss << "[Append]";
|
break;
|
||||||
break;
|
case SelectMode::Append:
|
||||||
default:
|
oss << "[Append]";
|
||||||
assert(false);
|
break;
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user