Buffer: add a type property
This commit is contained in:
parent
12535e1099
commit
9db4aa9691
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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("<scratch>");
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user