From 4ce349fa023998c83292eef4cc2f56a385e95721 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 5 Oct 2011 14:21:24 +0000 Subject: [PATCH] Buffer: modification tracking --- src/buffer.cc | 13 ++++++++++++- src/buffer.hh | 7 ++++++- src/main.cc | 1 + src/window.cc | 28 ++++++++++++++++++---------- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index d59977fe..2ee56106 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -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; +} + } diff --git a/src/buffer.hh b/src/buffer.hh index 565dfea5..b3ed56fc 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -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 m_history; std::vector::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> m_windows; + + std::vector::iterator m_last_save_undo_group; }; } diff --git a/src/main.cc b/src/main.cc index 19ff9e0f..99965f7e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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; diff --git a/src/window.cc b/src/window.cc index f75c08b1..34baaee6 100644 --- a/src/window.cc +++ b/src/window.cc @@ -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(); }