From 790a796de93c6f9868ce78f4aea9262461e2b8c9 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 12 Jan 2017 21:13:44 +0100 Subject: Buffer dirty marking --- buffer.cpp | 10 ++++++++++ buffer.h | 2 ++ manager.cpp | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/buffer.cpp b/buffer.cpp index 1366862..b185b99 100644 --- a/buffer.cpp +++ b/buffer.cpp @@ -34,6 +34,7 @@ void Buffer::handleCommand(const Command &cmd){ cursor.line=0; cursor.x=0; screen.clear(); + dirty=false; manager->receive({"info","Opened, read "+to_string(nread)+" characters"}); } else if(cmd[0]=="save_file"){ if(filename.size()==0){ @@ -46,11 +47,13 @@ void Buffer::handleCommand(const Command &cmd){ return; } i64 nwritten=tb.write(file); + dirty=false; manager->receive({"info","Saved, written "+to_string(nwritten)+" characters"}); } else if(cmd[0]=="insert_char"){ char c=cmd[1][0]; assert(c!='\n'); tb.insert(cursor.line,cursor.x,cmd[1][0]); + dirty=true; cursor.x++; relayoutScreen(); if(findCursorInScreen().x==-1){ @@ -59,6 +62,7 @@ void Buffer::handleCommand(const Command &cmd){ } } else if(cmd[0]=="insert_newline"){ tb.insert(cursor.line,cursor.x,'\n'); + dirty=true; cursor.x=0; cursor.line++; relayoutScreen(); @@ -79,6 +83,7 @@ void Buffer::handleCommand(const Command &cmd){ cursor.x=tb.lineLen(cursor.line); tb.erase(cursor.line,cursor.x); } + dirty=true; relayoutScreen(); if(findCursorInScreen().x==-1){ scrollUp(); @@ -91,6 +96,7 @@ void Buffer::handleCommand(const Command &cmd){ return; } tb.erase(cursor.line,cursor.x); + dirty=true; relayoutScreen(); } else if(cmd[0]=="move_forward"){ if(cursor.line==tb.numLines()-1&&cursor.x==tb.lineLen(cursor.line)){ @@ -476,3 +482,7 @@ string Buffer::getText() const { return tb.fullText(); } } + +bool Buffer::isDirty() const { + return dirty; +} diff --git a/buffer.h b/buffer.h index 119097e..b20c885 100644 --- a/buffer.h +++ b/buffer.h @@ -36,6 +36,7 @@ class Buffer{ const bool singleLineMode=false; TextBlob tb; + bool dirty=false; vector screen; i64 lastWidth=-1,lastHeight=-1; //excluding the gutter @@ -62,4 +63,5 @@ public: void show(i64 atx,i64 aty,i64 width,i64 height); string getText() const; + bool isDirty() const; }; diff --git a/manager.cpp b/manager.cpp index af8844c..a3e9738 100644 --- a/manager.cpp +++ b/manager.cpp @@ -59,7 +59,7 @@ void Manager::show(){ string bartext; i64 hilight_start=-1,hilight_len; for(size_t i=0;i":buffers[i].filename; + string fname=buffers[i].filename.size()==0?"":buffers[i].filename; string tabtext=" "; for(size_t j=0;j