diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2014-11-24 05:50:25 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2014-11-24 05:58:27 +0100 |
commit | e030c4e574de9350024fba415450a0017fe48b56 (patch) | |
tree | d2eb0d69b69ad84b173c496b9c28792fdf80e381 /src | |
parent | 70776212a69ce374b16baa108a21accd0921589d (diff) | |
download | sciteco-e030c4e574de9350024fba415450a0017fe48b56.tar.gz |
turn off Scintilla undo collection by default and fixed memleak
* in batch mode, Scintilla undo actions are simply leaked memory
* Since we have more than one Scintilla view now, we must empty
the undo buffer of all scintilla views when a command line is committed ($$)
Diffstat (limited to 'src')
-rw-r--r-- | src/cmdline.cpp | 4 | ||||
-rw-r--r-- | src/interface.cpp | 6 | ||||
-rw-r--r-- | src/interface.h | 7 | ||||
-rw-r--r-- | src/main.cpp | 7 | ||||
-rw-r--r-- | src/ring.cpp | 9 | ||||
-rw-r--r-- | src/ring.h | 22 |
6 files changed, 45 insertions, 10 deletions
diff --git a/src/cmdline.cpp b/src/cmdline.cpp index 8b2d412..78c0bdb 100644 --- a/src/cmdline.cpp +++ b/src/cmdline.cpp @@ -258,7 +258,9 @@ process_edit_cmd(gchar key) throw Quit(); undo.clear(); - interface.ssm(SCI_EMPTYUNDOBUFFER); + /* also empties all Scintilla undo buffers */ + ring.set_scintilla_undo(true); + QRegisters::view.set_scintilla_undo(true); Goto::table->clear(); expressions.clear(); diff --git a/src/interface.cpp b/src/interface.cpp index a726e01..fc46f53 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -55,6 +55,12 @@ template <class ViewImpl> void View<ViewImpl>::setup(void) { + /* + * Start with or without undo collection, + * depending on undo.enabled. + */ + ssm(SCI_SETUNDOCOLLECTION, undo.enabled); + ssm(SCI_SETFOCUS, TRUE); ssm(SCI_SETCARETSTYLE, CARETSTYLE_BLOCK); diff --git a/src/interface.h b/src/interface.h index a883a5f..4b5de7f 100644 --- a/src/interface.h +++ b/src/interface.h @@ -131,6 +131,13 @@ public: undo.push(new UndoTokenSetRepresentations(impl())); } + inline void + set_scintilla_undo(bool state) + { + ssm(SCI_EMPTYUNDOBUFFER); + ssm(SCI_SETUNDOCOLLECTION, state); + } + protected: void setup(void); }; diff --git a/src/main.cpp b/src/main.cpp index 463cdfd..9123224 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -357,8 +357,9 @@ main(int argc, char **argv) QRegisters::globals.insert("\x1B"); Goto::table = &cmdline_goto_table; - interface.ssm(SCI_EMPTYUNDOBUFFER); undo.enabled = true; + ring.set_scintilla_undo(true); + QRegisters::view.set_scintilla_undo(true); interface.event_loop(); @@ -368,8 +369,10 @@ main(int argc, char **argv) * in non-interactive mode again. */ undo.enabled = false; - interface.ssm(SCI_EMPTYUNDOBUFFER); undo.clear(); + /* also empties all Scintilla undo buffers */ + ring.set_scintilla_undo(false); + QRegisters::view.set_scintilla_undo(false); try { QRegisters::hook(QRegisters::HOOK_QUIT); diff --git a/src/ring.cpp b/src/ring.cpp index df80246..0d617c0 100644 --- a/src/ring.cpp +++ b/src/ring.cpp @@ -251,6 +251,15 @@ Ring::close(void) } } +void +Ring::set_scintilla_undo(bool state) +{ + Buffer *cur; + + TAILQ_FOREACH(cur, &head, buffers) + cur->set_scintilla_undo(state); +} + Ring::~Ring() { Buffer *buffer, *next; @@ -38,6 +38,8 @@ namespace SciTECO { */ class Buffer : private IOView { + TAILQ_ENTRY(Buffer) buffers; + class UndoTokenClose : public UndoToken { Buffer *buffer; @@ -48,9 +50,13 @@ class Buffer : private IOView { void run(void); }; -public: - TAILQ_ENTRY(Buffer) buffers; + inline void + undo_close(void) + { + undo.push(new UndoTokenClose(this)); + } +public: gchar *filename; bool dirty; @@ -115,11 +121,11 @@ public: } void save(const gchar *filename = NULL); - inline void - undo_close(void) - { - undo.push(new UndoTokenClose(this)); - } + /* + * Ring manages the buffer list and has privileged + * access. + */ + friend class Ring; }; /* object declared in main.cpp */ @@ -195,6 +201,8 @@ public: { current->undo_close(); } + + void set_scintilla_undo(bool state); } ring; /* |