diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-18 01:05:37 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-18 01:05:37 +0100 |
commit | 9be9fcca0c9ab63180a2e9aeb64e25829034b7a4 (patch) | |
tree | 94cd667c59f75551921e988bdfd1edbaa4a3d946 | |
parent | ed6d0bdbf4b69061dd5db69d823c2ee39b98dcdd (diff) | |
download | sciteco-9be9fcca0c9ab63180a2e9aeb64e25829034b7a4.tar.gz |
avoid using Scintilla's SAVEPOINT mechanism altogether: fixes some destructive commands
* the only thing gained from (partially) using that mechanism is that no explicit calls to set the dirty-status of a buffer are necessary
* however it had many disadvantages:
* setting the buffer clean had to be done manually anyway (see previous commits)
* when changing Q-Registers without affecting the current document, a flag had to be used to prevent setting the current document dirty
* last but not least, it introduced a dependency on the order of the destructive operation and its UNDO token.
* the UNDO token could trigger a SAVEPOINTLEFT notification resulting in additional rubout tokens to be pushed on the stack which screws
the rubout stack. this can be avoided by clever ordering of the operations
* using an explicit ring.dirtify() is therefore much better
-rw-r--r-- | main.cpp | 23 | ||||
-rw-r--r-- | parser.cpp | 5 | ||||
-rw-r--r-- | qbuffers.cpp | 28 | ||||
-rw-r--r-- | qbuffers.h | 4 |
4 files changed, 22 insertions, 38 deletions
@@ -47,30 +47,9 @@ Interface::stdio_vmsg(MessageType type, const gchar *fmt, va_list ap) void Interface::process_notify(SCNotification *notify) { - switch (notify->nmhdr.code) { #ifdef DEBUG - case SCN_SAVEPOINTREACHED: - g_printf("SCINTILLA SAVEPOINT REACHED\n"); - break; -#endif - case SCN_SAVEPOINTLEFT: -#ifdef DEBUG - g_printf("SCINTILLA SAVEPOINT LEFT\n"); + g_printf("SCINTILLA NOTIFY: code=%d\n", notify->nmhdr.code); #endif - - if (!dirty_check_enabled || - !ring.current || ring.current->dirty) - break; - - undo.push_msg(SCI_SETSAVEPOINT); - undo_info_update(ring.current); - undo.push_var(ring.current->dirty); - ring.current->dirty = true; - info_update(ring.current); - break; - default: - break; - } } static inline void @@ -415,6 +415,8 @@ StateStart::delete_words(gint64 n) undo.push_msg(SCI_GOTOPOS, pos); undo.push_msg(SCI_UNDO); + ring.dirtify(); + return SUCCESS; } @@ -804,6 +806,7 @@ StateStart::custom(gchar chr) throw (Error) interface.ssm(SCI_BEGINUNDOACTION); interface.ssm(SCI_DELETERANGE, from, len); interface.ssm(SCI_ENDUNDOACTION); + ring.dirtify(); break; } @@ -1110,6 +1113,7 @@ StateInsert::initial(void) throw (Error) expressions.pop_num_calc(); interface.ssm(SCI_SCROLLCARET); interface.ssm(SCI_ENDUNDOACTION); + ring.dirtify(); undo.push_msg(SCI_UNDO); } @@ -1122,6 +1126,7 @@ StateInsert::process(const gchar *str, gint new_chars) throw (Error) (sptr_t)(str + strlen(str) - new_chars)); interface.ssm(SCI_SCROLLCARET); interface.ssm(SCI_ENDUNDOACTION); + ring.dirtify(); undo.push_msg(SCI_UNDO); } diff --git a/qbuffers.cpp b/qbuffers.cpp index cbeee0b..1647ef3 100644 --- a/qbuffers.cpp +++ b/qbuffers.cpp @@ -38,13 +38,6 @@ namespace States { Ring ring; QRegisterTable qregisters; -/* - * Can be used to temporarily disable SCN_SAVEPOINTLEFT processing since - * a Q-Register may be modified without changing the logical current - * document and we don't want the wrong file to get modified. - */ -bool dirty_check_enabled = true; - static QRegister *register_argument = NULL; /* FIXME: clean up current_save_dot() usage */ @@ -74,11 +67,9 @@ QRegister::set_string(const gchar *str) edit(); dot = 0; - dirty_check_enabled = false; interface.ssm(SCI_BEGINUNDOACTION); interface.ssm(SCI_SETTEXT, 0, (sptr_t)(str ? : "")); interface.ssm(SCI_ENDUNDOACTION); - dirty_check_enabled = true; current_edit(); } @@ -129,12 +120,10 @@ QRegister::load(const gchar *filename) edit(); dot = 0; - dirty_check_enabled = false; interface.ssm(SCI_BEGINUNDOACTION); interface.ssm(SCI_CLEARALL); interface.ssm(SCI_APPENDTEXT, size, (sptr_t)contents); interface.ssm(SCI_ENDUNDOACTION); - dirty_check_enabled = true; g_free(contents); @@ -187,10 +176,12 @@ Buffer::load(const gchar *filename) g_free(contents); - interface.ssm(SCI_SETSAVEPOINT); + /* NOTE: currently buffer cannot be dirty */ +#if 0 interface.undo_info_update(this); undo.push_var(dirty); dirty = false; +#endif set_filename(filename); @@ -241,6 +232,18 @@ Ring::find(const gchar *filename) return cur; } +void +Ring::dirtify(void) +{ + if (!current || current->dirty) + return; + + interface.undo_info_update(current); + undo.push_var(current->dirty); + current->dirty = true; + interface.info_update(current); +} + bool Ring::is_any_dirty(void) { @@ -423,7 +426,6 @@ Ring::save(const gchar *filename) if (!g_file_set_contents(filename, buffer, size, NULL)) return false; - interface.ssm(SCI_SETSAVEPOINT); interface.undo_info_update(current); undo.push_var(current->dirty); current->dirty = false; @@ -164,7 +164,6 @@ public: gint savepoint_id; - /* set by Interfaces using Scintilla notifications */ bool dirty; private: @@ -280,6 +279,7 @@ public: Buffer *find(const gchar *filename); + void dirtify(void); bool is_any_dirty(void); bool edit(const gchar *filename); @@ -372,6 +372,4 @@ namespace States { extern StateCopyToQReg copytoqreg; } -extern bool dirty_check_enabled; - #endif |