|
|
|
|
@ -2,9 +2,9 @@
@@ -2,9 +2,9 @@
|
|
|
|
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.ComponentModel; |
|
|
|
|
using System.Diagnostics; |
|
|
|
|
|
|
|
|
|
using ICSharpCode.AvalonEdit.Utils; |
|
|
|
|
|
|
|
|
|
namespace ICSharpCode.AvalonEdit.Document |
|
|
|
|
@ -213,6 +213,7 @@ namespace ICSharpCode.AvalonEdit.Document
@@ -213,6 +213,7 @@ namespace ICSharpCode.AvalonEdit.Document
|
|
|
|
|
undoGroupDepth--; |
|
|
|
|
//Util.LoggingService.Debug("Close undo group (new depth=" + undoGroupDepth + ")");
|
|
|
|
|
if (undoGroupDepth == 0) { |
|
|
|
|
Debug.Assert(state == StateListen || actionCountInUndoGroup == 0); |
|
|
|
|
if (actionCountInUndoGroup == optionalActionCount) { |
|
|
|
|
// only optional actions: don't store them
|
|
|
|
|
for (int i = 0; i < optionalActionCount; i++) { |
|
|
|
|
@ -223,9 +224,11 @@ namespace ICSharpCode.AvalonEdit.Document
@@ -223,9 +224,11 @@ namespace ICSharpCode.AvalonEdit.Document
|
|
|
|
|
undostack.PushBack(new UndoOperationGroup(undostack, actionCountInUndoGroup)); |
|
|
|
|
FileModified(-actionCountInUndoGroup + 1 + optionalActionCount); |
|
|
|
|
} |
|
|
|
|
//if (state == StateListen) {
|
|
|
|
|
EnforceSizeLimit(); |
|
|
|
|
allowContinue = true; |
|
|
|
|
RecalcIsOriginalFile(); // can raise event
|
|
|
|
|
//}
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -243,6 +246,28 @@ namespace ICSharpCode.AvalonEdit.Document
@@ -243,6 +246,28 @@ namespace ICSharpCode.AvalonEdit.Document
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<TextDocument> affectedDocuments; |
|
|
|
|
|
|
|
|
|
internal void RegisterAffectedDocument(TextDocument document) |
|
|
|
|
{ |
|
|
|
|
if (affectedDocuments == null) |
|
|
|
|
affectedDocuments = new List<TextDocument>(); |
|
|
|
|
if (!affectedDocuments.Contains(document)) { |
|
|
|
|
affectedDocuments.Add(document); |
|
|
|
|
document.BeginUpdate(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CallEndUpdateOnAffectedDocuments() |
|
|
|
|
{ |
|
|
|
|
if (affectedDocuments != null) { |
|
|
|
|
foreach (TextDocument doc in affectedDocuments) { |
|
|
|
|
doc.EndUpdate(); |
|
|
|
|
} |
|
|
|
|
affectedDocuments = null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Call this method to undo the last operation on the stack
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -260,8 +285,9 @@ namespace ICSharpCode.AvalonEdit.Document
@@ -260,8 +285,9 @@ namespace ICSharpCode.AvalonEdit.Document
|
|
|
|
|
RunUndo(uedit); |
|
|
|
|
} finally { |
|
|
|
|
state = StateListen; |
|
|
|
|
FileModified(-1); |
|
|
|
|
CallEndUpdateOnAffectedDocuments(); |
|
|
|
|
} |
|
|
|
|
FileModified(-1); |
|
|
|
|
RecalcIsOriginalFile(); |
|
|
|
|
if (undostack.Count == 0) |
|
|
|
|
NotifyPropertyChanged("CanUndo"); |
|
|
|
|
@ -294,8 +320,9 @@ namespace ICSharpCode.AvalonEdit.Document
@@ -294,8 +320,9 @@ namespace ICSharpCode.AvalonEdit.Document
|
|
|
|
|
RunRedo(uedit); |
|
|
|
|
} finally { |
|
|
|
|
state = StateListen; |
|
|
|
|
FileModified(1); |
|
|
|
|
CallEndUpdateOnAffectedDocuments(); |
|
|
|
|
} |
|
|
|
|
FileModified(1); |
|
|
|
|
RecalcIsOriginalFile(); |
|
|
|
|
if (redostack.Count == 0) |
|
|
|
|
NotifyPropertyChanged("CanRedo"); |
|
|
|
|
@ -345,14 +372,15 @@ namespace ICSharpCode.AvalonEdit.Document
@@ -345,14 +372,15 @@ namespace ICSharpCode.AvalonEdit.Document
|
|
|
|
|
if (state == StateListen && sizeLimit > 0) { |
|
|
|
|
bool wasEmpty = undostack.Count == 0; |
|
|
|
|
|
|
|
|
|
StartUndoGroup(); |
|
|
|
|
bool needsUndoGroup = undoGroupDepth == 0; |
|
|
|
|
if (needsUndoGroup) StartUndoGroup(); |
|
|
|
|
undostack.PushBack(operation); |
|
|
|
|
actionCountInUndoGroup++; |
|
|
|
|
if (isOptional) |
|
|
|
|
optionalActionCount++; |
|
|
|
|
else |
|
|
|
|
FileModified(1); |
|
|
|
|
EndUndoGroup(); |
|
|
|
|
if (needsUndoGroup) EndUndoGroup(); |
|
|
|
|
if (wasEmpty) |
|
|
|
|
NotifyPropertyChanged("CanUndo"); |
|
|
|
|
ClearRedoStack(); |
|
|
|
|
@ -390,29 +418,14 @@ namespace ICSharpCode.AvalonEdit.Document
@@ -390,29 +418,14 @@ namespace ICSharpCode.AvalonEdit.Document
|
|
|
|
|
ClearRedoStack(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal void AttachToDocument(TextDocument document) |
|
|
|
|
{ |
|
|
|
|
document.UpdateStarted += document_UpdateStarted; |
|
|
|
|
document.UpdateFinished += document_UpdateFinished; |
|
|
|
|
document.Changing += document_Changing; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void document_UpdateStarted(object sender, EventArgs e) |
|
|
|
|
{ |
|
|
|
|
StartUndoGroup(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void document_UpdateFinished(object sender, EventArgs e) |
|
|
|
|
{ |
|
|
|
|
EndUndoGroup(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void document_Changing(object sender, DocumentChangeEventArgs e) |
|
|
|
|
internal void Push(TextDocument document, DocumentChangeEventArgs e) |
|
|
|
|
{ |
|
|
|
|
if (state == StatePlayback) |
|
|
|
|
throw new InvalidOperationException("Document changes during undo/redo operations are not allowed."); |
|
|
|
|
TextDocument document = (TextDocument)sender; |
|
|
|
|
Push(new DocumentChangeOperation(document, e)); |
|
|
|
|
if (state == StatePlaybackModifyDocument) |
|
|
|
|
state = StatePlayback; // allow only 1 change per expected modification
|
|
|
|
|
else |
|
|
|
|
Push(new DocumentChangeOperation(document, e)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|