diff --git a/src/buffer.cc b/src/buffer.cc index 2ee561065..4e3bb5c3b 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -136,8 +136,10 @@ bool BufferIterator::is_end() const return m_position == m_buffer->length(); } -Buffer::Buffer(const std::string& name, const BufferString& initial_content) - : m_name(name), m_history(1), m_history_cursor(m_history.begin()), +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()) { BufferManager::instance().register_buffer(this); diff --git a/src/buffer.hh b/src/buffer.hh index b3ed56fc1..a2a1933ef 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -71,7 +71,13 @@ private: class Buffer { public: - Buffer(const std::string& name, + enum class Type + { + File, + Scratch + }; + + Buffer(const std::string& name, Type type, const BufferString& initial_content = ""); void begin_undo_group(); @@ -107,6 +113,7 @@ public: void delete_window(Window* window); bool is_modified() const; + Type type() const { return m_type; } void notify_saved(); private: @@ -129,6 +136,7 @@ private: BufferString m_content; std::string m_name; + const Type m_type; struct Modification { diff --git a/src/file.cc b/src/file.cc index af9caad9e..4da683d7f 100644 --- a/src/file.cc +++ b/src/file.cc @@ -39,7 +39,7 @@ Buffer* create_buffer_from_file(const std::string& filename) if (Buffer* buffer = BufferManager::instance().get_buffer(filename)) BufferManager::instance().delete_buffer(buffer); - return new Buffer(filename, content); + return new Buffer(filename, Buffer::Type::File, content); } void write_buffer_to_file(const Buffer& buffer, const std::string& filename) diff --git a/src/main.cc b/src/main.cc index 2aaa4f3fc..55d1a2915 100644 --- a/src/main.cc +++ b/src/main.cc @@ -371,7 +371,7 @@ void edit(const CommandParameters& params) catch (file_not_found& what) { print_status("new file " + filename); - buffer = new Buffer(filename); + buffer = new Buffer(filename, Buffer::Type::File); } current_window = buffer->get_or_create_window(); } @@ -400,7 +400,7 @@ void quit(const CommandParameters& params) { for (auto& buffer : BufferManager::instance()) { - if (buffer.is_modified()) + if (buffer.type() == Buffer::Type::File and buffer.is_modified()) { print_status("modified buffer remaining"); return; @@ -558,7 +558,7 @@ int main(int argc, char* argv[]) try { - auto buffer = (argc > 1) ? create_buffer_from_file(argv[1]) : new Buffer(""); + auto buffer = (argc > 1) ? create_buffer_from_file(argv[1]) : new Buffer("*scratch*", Buffer::Type::Scratch); current_window = buffer->get_or_create_window(); draw_window(*current_window);