diff options
Diffstat (limited to 'src/Text/Impl/StandaloneUndo/UndoHistoryImpl.cs')
-rw-r--r-- | src/Text/Impl/StandaloneUndo/UndoHistoryImpl.cs | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/Text/Impl/StandaloneUndo/UndoHistoryImpl.cs b/src/Text/Impl/StandaloneUndo/UndoHistoryImpl.cs index 9f5bac5..47fec01 100644 --- a/src/Text/Impl/StandaloneUndo/UndoHistoryImpl.cs +++ b/src/Text/Impl/StandaloneUndo/UndoHistoryImpl.cs @@ -8,13 +8,11 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.Collections.ObjectModel; -using System.ComponentModel.Composition; using Microsoft.VisualStudio.Utilities; namespace Microsoft.VisualStudio.Text.Operations.Standalone { - internal class UndoHistoryImpl : ITextUndoHistory + internal class UndoHistoryImpl : ITextUndoHistory2 { public event EventHandler<TextUndoRedoEventArgs> UndoRedoHappened; public event EventHandler<TextUndoTransactionCompletedEventArgs> UndoTransactionCompleted; @@ -25,7 +23,7 @@ namespace Microsoft.VisualStudio.Text.Operations.Standalone private Stack<ITextUndoTransaction> undoStack; private Stack<ITextUndoTransaction> redoStack; private DelegatedUndoPrimitiveImpl activeUndoOperationPrimitive; - private TextUndoHistoryState state; + internal TextUndoHistoryState state; private PropertyCollection properties; #endregion @@ -188,6 +186,13 @@ namespace Microsoft.VisualStudio.Text.Operations.Standalone get { return this.state; } } + public ITextUndoTransaction CreateInvisibleTransaction(string description) + { + // Standalone undo doesn't support invisible transactions so simply return + // a normal transaction. + return this.CreateTransaction(description); + } + /// <summary> /// Creates a new transaction, nests it in the previously current transaction, and marks it current. /// If there is a redo stack, it gets cleared. @@ -198,9 +203,9 @@ namespace Microsoft.VisualStudio.Text.Operations.Standalone /// <returns></returns> public ITextUndoTransaction CreateTransaction(string description) { - if (String.IsNullOrEmpty(description)) + if (string.IsNullOrEmpty(description)) { - throw new ArgumentNullException("description", String.Format(CultureInfo.CurrentUICulture, "Strings.ArgumentCannotBeNull", "CreateTransaction", "description")); + throw new ArgumentNullException(nameof(description)); } // If there is a pending transaction that has already been completed, we should not be permitted @@ -244,12 +249,12 @@ namespace Microsoft.VisualStudio.Text.Operations.Standalone { if (count <= 0) { - throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, "Strings.RedoAndUndoAcceptOnlyPositiveCounts", "Undo", count), "count"); + throw new ArgumentOutOfRangeException(nameof(count)); } if (!IsThereEnoughVisibleTransactions(this.undoStack, count)) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, "Strings.CannotUndoMoreTransactionsThanExist", "undo", count)); + throw new InvalidOperationException("Cannot undo more transactions than exist"); } TextUndoHistoryState originalState = this.state; @@ -321,12 +326,12 @@ namespace Microsoft.VisualStudio.Text.Operations.Standalone { if (count <= 0) { - throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, "Strings.RedoAndUndoAcceptOnlyPositiveCounts", "Redo", count), "count"); + throw new ArgumentOutOfRangeException(nameof(count)); } if (!IsThereEnoughVisibleTransactions(this.redoStack, count)) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, "Strings.CannotUndoMoreTransactionsThanExist", "redo", count)); + throw new InvalidOperationException("Cannot redo more transactions than exist"); } TextUndoHistoryState originalState = this.state; @@ -424,15 +429,19 @@ namespace Microsoft.VisualStudio.Text.Operations.Standalone throw new InvalidOperationException("Strings.EndTransactionOutOfOrder"); } + // Note that the VS undo history actually "pops" the nested undo stack on the Complete/Cancel + // (instead of in the Dispose). This shouldn't affect anything but we should consider adapting + // this code to follow the model in VS undo. + this.currentTransaction = (UndoTransactionImpl)(transaction.Parent); + // only add completed transactions to their parents (or the stack) - if (this.currentTransaction.State == UndoTransactionState.Completed) + if (transaction.State == UndoTransactionState.Completed) { - if (this.currentTransaction.Parent == null) // stack bottomed out! + if (transaction.Parent == null) // stack bottomed out! { - MergeOrPushToUndoStack(this.currentTransaction); + MergeOrPushToUndoStack((UndoTransactionImpl)transaction); } } - this.currentTransaction = this.currentTransaction.Parent as UndoTransactionImpl; } /// <summary> @@ -471,7 +480,7 @@ namespace Microsoft.VisualStudio.Text.Operations.Standalone transactionAdded = transaction; transactionResult = TextUndoTransactionCompletionResult.TransactionAdded; } - RaiseUndoTransactionCompleted(transactionAdded, transactionResult); + RaiseUndoTransactionCompleted(transactionAdded, transactionResult); } public bool ValidTransactionForMarkers(ITextUndoTransaction transaction) |