diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-13 23:52:01 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-13 23:52:01 +0100 |
commit | 66bde3c43d543cbadd617f68240f4bd8c22d10d9 (patch) | |
tree | fa45084a22bb67249f43503d24fae930cb4062f7 /qbuffers.cpp | |
parent | 074c64232f8be3bc34b40a9d5e92f28e6aa922fb (diff) | |
download | sciteco-66bde3c43d543cbadd617f68240f4bd8c22d10d9.tar.gz |
EF command to close a buffer
can be rubbed out!!!
this works because when a buffer is closed, it is not deallocated but transferred to the undo
token object which then (if run) reinserts it into the ring list. if the undo token is destroyed
before it is run (eg. <ESC><ESC> pressed), the buffer will finally be deallocated.
Diffstat (limited to 'qbuffers.cpp')
-rw-r--r-- | qbuffers.cpp | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/qbuffers.cpp b/qbuffers.cpp index e72c730..f4212d7 100644 --- a/qbuffers.cpp +++ b/qbuffers.cpp @@ -190,6 +190,22 @@ Buffer::close(void) "Removed unnamed file from the ring."); } +void +Ring::UndoTokenEdit::run(void) +{ + /* + * assumes that buffer still has correct prev/next + * pointers + */ + *buffer->buffers.le_prev = buffer; + if (buffer->next()) + buffer->next()->buffers.le_prev = &buffer->next(); + + ring->current = buffer; + buffer->edit(); + buffer = NULL; +} + Buffer * Ring::find(const gchar *filename) { @@ -283,12 +299,18 @@ Ring::close(void) { Buffer *buffer = current; + buffer->dot = editor_msg(SCI_GETCURRENTPOS); buffer->close(); current = buffer->next() ? : first(); - if (!current) - edit(NULL); + /* transfer responsibility to UndoToken object */ + undo.push(new UndoTokenEdit(this, buffer)); - delete buffer; + if (current) { + current->edit(); + } else { + edit(NULL); + undo_close(); + } } Ring::~Ring() |