@ -49,11 +49,22 @@ namespace ICSharpCode.AvalonEdit.Document
/// </summary>
/// </summary>
int elementsOnUndoUntilOriginalFile ;
int elementsOnUndoUntilOriginalFile ;
bool isOriginalFile = true ;
/// <summary>
/// <summary>
/// Gets whether the document is currently in its original state (no modifications).
/// Gets whether the document is currently in its original state (no modifications).
/// </summary>
/// </summary>
public bool IsOriginalFile {
public bool IsOriginalFile {
get { return elementsOnUndoUntilOriginalFile = = 0 ; }
get { return isOriginalFile ; }
}
void RecalcIsOriginalFile ( )
{
bool newIsOriginalFile = ( elementsOnUndoUntilOriginalFile = = 0 ) ;
if ( newIsOriginalFile ! = isOriginalFile ) {
isOriginalFile = newIsOriginalFile ;
NotifyPropertyChanged ( "IsOriginalFile" ) ;
}
}
}
/// <summary>
/// <summary>
@ -61,10 +72,8 @@ namespace ICSharpCode.AvalonEdit.Document
/// </summary>
/// </summary>
public void MarkAsOriginalFile ( )
public void MarkAsOriginalFile ( )
{
{
bool oldIsOriginalFile = IsOriginalFile ;
elementsOnUndoUntilOriginalFile = 0 ;
elementsOnUndoUntilOriginalFile = 0 ;
if ( ! oldIsOriginalFile )
RecalcIsOriginalFile ( ) ;
NotifyPropertyChanged ( "IsOriginalFile" ) ;
}
}
/// <summary>
/// <summary>
@ -72,24 +81,20 @@ namespace ICSharpCode.AvalonEdit.Document
/// </summary>
/// </summary>
public void DiscardOriginalFileMarker ( )
public void DiscardOriginalFileMarker ( )
{
{
bool oldIsOriginalFile = IsOriginalFile ;
elementsOnUndoUntilOriginalFile = int . MinValue ;
elementsOnUndoUntilOriginalFile = int . MinValue ;
if ( oldIsOriginalFile )
RecalcIsOriginalFile ( ) ;
NotifyPropertyChanged ( "IsOriginalFile" ) ;
}
}
void FileModified ( int newElementsOnUndoStack )
void FileModified ( int newElementsOnUndoStack )
{
{
if ( newElementsOnUndoStack = = 0 | | elementsOnUndoUntilOriginalFile = = int . MinValue )
if ( elementsOnUndoUntilOriginalFile = = int . MinValue )
return ;
return ;
bool oldIsOriginalFile = IsOriginalFile ;
elementsOnUndoUntilOriginalFile + = newElementsOnUndoStack ;
elementsOnUndoUntilOriginalFile + = newElementsOnUndoStack ;
if ( elementsOnUndoUntilOriginalFile > undostack . Count )
if ( elementsOnUndoUntilOriginalFile > undostack . Count )
elementsOnUndoUntilOriginalFile = int . MinValue ;
elementsOnUndoUntilOriginalFile = int . MinValue ;
if ( oldIsOriginalFile ! = IsOriginalFile )
// don't call RecalcIsOriginalFile(): wait until end of undo group
NotifyPropertyChanged ( "IsOriginalFile" ) ;
}
}
#endregion
#endregion
@ -220,11 +225,11 @@ namespace ICSharpCode.AvalonEdit.Document
} else if ( actionCountInUndoGroup > 1 ) {
} else if ( actionCountInUndoGroup > 1 ) {
// combine all actions within the group into a single grouped action
// combine all actions within the group into a single grouped action
undostack . PushBack ( new UndoOperationGroup ( undostack , actionCountInUndoGroup ) ) ;
undostack . PushBack ( new UndoOperationGroup ( undostack , actionCountInUndoGroup ) ) ;
actionCountInUndoGroup = 1 ; // actions were combined
FileModified ( - actionCountInUndoGroup + 1 + optionalActionCount ) ;
}
}
EnforceSizeLimit ( ) ;
EnforceSizeLimit ( ) ;
allowContinue = true ;
allowContinue = true ;
FileModified ( actionCountInUndoGroup ) ;
RecalcIsOriginalFile ( ) ; // can raise event
}
}
}
}
@ -261,6 +266,7 @@ namespace ICSharpCode.AvalonEdit.Document
state = StateListen ;
state = StateListen ;
}
}
FileModified ( - 1 ) ;
FileModified ( - 1 ) ;
RecalcIsOriginalFile ( ) ;
if ( undostack . Count = = 0 )
if ( undostack . Count = = 0 )
NotifyPropertyChanged ( "CanUndo" ) ;
NotifyPropertyChanged ( "CanUndo" ) ;
if ( redostack . Count = = 1 )
if ( redostack . Count = = 1 )
@ -294,6 +300,7 @@ namespace ICSharpCode.AvalonEdit.Document
state = StateListen ;
state = StateListen ;
}
}
FileModified ( 1 ) ;
FileModified ( 1 ) ;
RecalcIsOriginalFile ( ) ;
if ( redostack . Count = = 0 )
if ( redostack . Count = = 0 )
NotifyPropertyChanged ( "CanRedo" ) ;
NotifyPropertyChanged ( "CanRedo" ) ;
if ( undostack . Count = = 1 )
if ( undostack . Count = = 1 )
@ -347,6 +354,8 @@ namespace ICSharpCode.AvalonEdit.Document
actionCountInUndoGroup + + ;
actionCountInUndoGroup + + ;
if ( isOptional )
if ( isOptional )
optionalActionCount + + ;
optionalActionCount + + ;
else
FileModified ( 1 ) ;
EndUndoGroup ( ) ;
EndUndoGroup ( ) ;
if ( wasEmpty )
if ( wasEmpty )
NotifyPropertyChanged ( "CanUndo" ) ;
NotifyPropertyChanged ( "CanUndo" ) ;