diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2009-10-22 21:36:24 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2009-10-22 21:36:24 (GMT) |
commit | 1c3b7359656edd8a158c3056d26d732e01c34994 (patch) | |
tree | 96ad00b3aa3cde150762ffef6a0c8c8897350b33 /generic/tkText.c | |
parent | 73bb161d56a49cf21d50dc11576fb42c2da880f8 (diff) | |
download | tk-1c3b7359656edd8a158c3056d26d732e01c34994.zip tk-1c3b7359656edd8a158c3056d26d732e01c34994.tar.gz tk-1c3b7359656edd8a158c3056d26d732e01c34994.tar.bz2 |
Apply (slight cleaner, tested) version of [Patch 1469210].
Diffstat (limited to 'generic/tkText.c')
-rw-r--r-- | generic/tkText.c | 69 |
1 files changed, 53 insertions, 16 deletions
diff --git a/generic/tkText.c b/generic/tkText.c index 46c2e19..c1cc433 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -13,7 +13,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkText.c,v 1.91 2009/09/07 07:29:04 das Exp $ + * RCS: @(#) $Id: tkText.c,v 1.92 2009/10/22 21:36:24 dkf Exp $ */ #include "default.h" @@ -543,7 +543,8 @@ CreateWidget( Tcl_InitHashTable(&sharedPtr->imageTable, TCL_STRING_KEYS); sharedPtr->undoStack = TkUndoInitStack(interp,0); sharedPtr->undo = 1; - sharedPtr->isDirtyIncrement = 1; + sharedPtr->isDirty = 0; + sharedPtr->dirtyMode = TK_TEXT_DIRTY_NORMAL; sharedPtr->autoSeparators = 1; sharedPtr->lastEditMode = TK_TEXT_EDIT_OTHER; sharedPtr->stateEpoch = 0; @@ -4899,16 +4900,21 @@ TextEditUndo( } /* - * Turn off the undo feature while we revert a compound action. Note that - * the dirty counter counts backwards while we are undoing... + * Turn off the undo feature while we revert a compound action, setting + * the dirty handling mode to undo for the duration (unless it is + * 'fixed'). */ textPtr->sharedTextPtr->undo = 0; - textPtr->sharedTextPtr->isDirtyIncrement = -1; + if (textPtr->sharedTextPtr->dirtyMode != TK_TEXT_DIRTY_FIXED) { + textPtr->sharedTextPtr->dirtyMode = TK_TEXT_DIRTY_UNDO; + } status = TkUndoRevert(textPtr->sharedTextPtr->undoStack); - textPtr->sharedTextPtr->isDirtyIncrement = 1; + if (textPtr->sharedTextPtr->dirtyMode != TK_TEXT_DIRTY_FIXED) { + textPtr->sharedTextPtr->dirtyMode = TK_TEXT_DIRTY_NORMAL; + } textPtr->sharedTextPtr->undo = 1; return status; @@ -4943,13 +4949,20 @@ TextEditRedo( /* * Turn off the undo feature temporarily while we revert a previously - * undone compound action. + * undone compound action, setting the dirty handling mode to redo for the + * duration (unless it is 'fixed'). */ textPtr->sharedTextPtr->undo = 0; + if (textPtr->sharedTextPtr->dirtyMode != TK_TEXT_DIRTY_FIXED) { + textPtr->sharedTextPtr->dirtyMode = TK_TEXT_DIRTY_REDO; + } status = TkUndoApply(textPtr->sharedTextPtr->undoStack); + if (textPtr->sharedTextPtr->dirtyMode != TK_TEXT_DIRTY_FIXED) { + textPtr->sharedTextPtr->dirtyMode = TK_TEXT_DIRTY_NORMAL; + } textPtr->sharedTextPtr->undo = 1; return status; } @@ -5014,17 +5027,18 @@ TextEditCmd( } /* - * Set or reset the dirty info, but trigger a Modified event only - * if it has changed. Ensure a rationalized value for the bit. + * Set or reset the dirty info, and trigger a Modified event. */ setModified = setModified ? 1 : 0; textPtr->sharedTextPtr->isDirty = setModified; - if (textPtr->sharedTextPtr->modifiedSet != setModified) { - textPtr->sharedTextPtr->modifiedSet = setModified; - GenerateModifiedEvent(textPtr); + if (setModified) { + textPtr->sharedTextPtr->dirtyMode = TK_TEXT_DIRTY_FIXED; + } else { + textPtr->sharedTextPtr->dirtyMode = TK_TEXT_DIRTY_NORMAL; } + GenerateModifiedEvent(textPtr); } break; case EDIT_REDO: @@ -5192,7 +5206,7 @@ GenerateModifiedEvent( * * UpdateDirtyFlag -- * - * Increases the dirtyness of the text widget + * Updates the dirtyness of the text widget * * Results: * None @@ -5208,14 +5222,37 @@ UpdateDirtyFlag( TkSharedText *sharedTextPtr)/* Information about text widget. */ { int oldDirtyFlag; + TkText *textPtr; + + /* + * If we've been forced to be dirty, we stay dirty (until explicitly + * reset, of course). + */ - if (sharedTextPtr->modifiedSet) { + if (sharedTextPtr->dirtyMode == TK_TEXT_DIRTY_FIXED) { return; } + + if (sharedTextPtr->isDirty < 0 + && sharedTextPtr->dirtyMode == TK_TEXT_DIRTY_NORMAL) { + /* + * If dirty flag is negative, only redo operations can make it zero + * again. If we do a normal operation, it can never become zero any + * more (other than by explicit reset). + */ + + sharedTextPtr->dirtyMode = TK_TEXT_DIRTY_FIXED; + return; + } + oldDirtyFlag = sharedTextPtr->isDirty; - sharedTextPtr->isDirty += sharedTextPtr->isDirtyIncrement; + if (sharedTextPtr->dirtyMode == TK_TEXT_DIRTY_UNDO) { + sharedTextPtr->isDirty--; + } else { + sharedTextPtr->isDirty++; + } + if (sharedTextPtr->isDirty == 0 || oldDirtyFlag == 0) { - TkText *textPtr; for (textPtr = sharedTextPtr->peers; textPtr != NULL; textPtr = textPtr->next) { GenerateModifiedEvent(textPtr); |