Working on backing files.
Also started a sketches project to illustrate quick ideas.
This commit is contained in:
74
Buffer.h
74
Buffer.h
@@ -17,7 +17,7 @@
|
||||
#include "Cursor.h"
|
||||
|
||||
|
||||
typedef std::vector<std::vector<uint8_t>> BufferContents;
|
||||
typedef std::vector<std::vector<uint8_t>> BufferContents;
|
||||
|
||||
|
||||
/// A Buffer is the atom of text editing. It represents a single document,
|
||||
@@ -32,6 +32,38 @@ typedef std::vector<std::vector<uint8_t>> BufferContents;
|
||||
/// cannot be demoted to a virtual buffer.
|
||||
class Buffer {
|
||||
public:
|
||||
enum class FileStatus : uint8_t {
|
||||
/// The file operation succeeded correctly.
|
||||
FileStatusOK = 0,
|
||||
|
||||
/// The file can't be written to because it is marked
|
||||
/// read-only. This refers to a buffer being marked as
|
||||
/// read-only, not to whether the underlying file is
|
||||
/// actually read-only.
|
||||
FileStatusReadOnly = 1,
|
||||
|
||||
/// There was an I/O error trying to write to the file.
|
||||
FileStatusIOFailed = 2,
|
||||
|
||||
/// The Buffer couldn't be flushed because it is a virtual
|
||||
/// buffer. If the user explicitly tried to save the buffer,
|
||||
/// they should be prompted for a path.
|
||||
FileStatusVirtual = 3,
|
||||
|
||||
/// The underlying file doesn't have the right permissions;
|
||||
/// for example, it's not writeable if the user is trying to
|
||||
/// write the file.
|
||||
FileStatusInvalidPermissions = 4,
|
||||
|
||||
/// The underlying file doesn't exist.
|
||||
FileStatusNonExistent = 5,
|
||||
};
|
||||
|
||||
|
||||
static bool StatusOK(FileStatus status)
|
||||
{ return status == FileStatus::FileStatusOK; }
|
||||
|
||||
|
||||
/// The constructor with no arguments generates a new anonymous
|
||||
/// buffer.
|
||||
Buffer();
|
||||
@@ -42,18 +74,42 @@ public:
|
||||
/// Instantiate a Buffer pointing to fPath.
|
||||
Buffer(std::string fName, std::string fPath);
|
||||
|
||||
std::string Name() const { return this->name; }
|
||||
std::string Name() const
|
||||
{ return this->name; }
|
||||
|
||||
int Flush(OptString altPath);
|
||||
void ChangePath(std::string newPath);
|
||||
bool IsVirtual()
|
||||
{ return this->file.has_value(); }
|
||||
|
||||
Buffer::FileStatus Flush(OptString altPath);
|
||||
|
||||
/// Refresh reads the contents of the file back into the
|
||||
/// buffer.
|
||||
///
|
||||
/// \warning This does not care if the file is dirty or not -
|
||||
/// it WILL overwrite the contents of the buffer.
|
||||
///
|
||||
/// \return A FileStatus indicating whether the read was successful.
|
||||
Buffer::FileStatus Refresh();
|
||||
|
||||
void ChangePath(std::string newPath);
|
||||
|
||||
Cursor Cursor()
|
||||
{ return this->cursor; }
|
||||
|
||||
void MarkDirty();
|
||||
bool IsDirty()
|
||||
{ return this->dirty; }
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
OptString path;
|
||||
OptFile file;
|
||||
Cursor cursor;
|
||||
BufferContents contents;
|
||||
void clearContents();
|
||||
|
||||
class Cursor cursor;
|
||||
|
||||
bool dirty;
|
||||
std::string name;
|
||||
OptString path;
|
||||
OptFile file;
|
||||
BufferContents contents;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user