Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Documents / ChangeBlockUndoRecord.cs / 1305600 / ChangeBlockUndoRecord.cs
//---------------------------------------------------------------------------- // // File: ChangeBlockUndoRecord.cs // // Description: Undo wrapper for any edit on or through a TextRange or // TextContainer. // //--------------------------------------------------------------------------- using System; using System.Windows; using MS.Internal; using MS.Internal.Documents; namespace System.Windows.Documents { // Undo wrapper for any edit on or through a TextRange or TextContainer. internal class ChangeBlockUndoRecord { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors // Constructor, called when a change block is opening. internal ChangeBlockUndoRecord(ITextContainer textContainer, string actionDescription) { if (textContainer.UndoManager != null) { _undoManager = textContainer.UndoManager; if (_undoManager.IsEnabled) { // Don't bother opening an undo unit if the owning control is // still being initialized (ie, programmatic load by parser). if (textContainer.TextView != null) { // Don't bother opening a new undo unit if we're already nested // inside another. if (_undoManager.OpenedUnit == null) { if (textContainer.TextSelection != null) { _parentUndoUnit = new TextParentUndoUnit(textContainer.TextSelection); } else { _parentUndoUnit = new ParentUndoUnit(actionDescription); } _undoManager.Open(_parentUndoUnit); } } else { // If the owning control isn't initialized (parser is still running), // don't add anything to the undo record. Instead, clear it. _undoManager.Clear(); } } } } #endregion Constructors //------------------------------------------------------ // // Internal Methods // //----------------------------------------------------- #region Internal Methods // Called when a change block is closing. internal void OnEndChange() { // Commit our undo unit. if (_parentUndoUnit != null) { IParentUndoUnit openedUnit; if (_parentUndoUnit.Container is UndoManager) { openedUnit = ((UndoManager)_parentUndoUnit.Container).OpenedUnit; } else { openedUnit = ((IParentUndoUnit)_parentUndoUnit.Container).OpenedUnit; } // UIElementPropertyUndoUnit can clear the undo stack if a change is made to a databound property if (openedUnit == _parentUndoUnit) { if (_parentUndoUnit is TextParentUndoUnit) { ((TextParentUndoUnit)_parentUndoUnit).RecordRedoSelectionState(); } Invariant.Assert(_undoManager != null); _undoManager.Close(_parentUndoUnit, (_parentUndoUnit.LastUnit != null) ? UndoCloseAction.Commit : UndoCloseAction.Discard); } } } #endregion Internal Methods //------------------------------------------------------ // // Private Fields // //------------------------------------------------------ #region Private Fields private readonly UndoManager _undoManager; private readonly IParentUndoUnit _parentUndoUnit; #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // // File: ChangeBlockUndoRecord.cs // // Description: Undo wrapper for any edit on or through a TextRange or // TextContainer. // //--------------------------------------------------------------------------- using System; using System.Windows; using MS.Internal; using MS.Internal.Documents; namespace System.Windows.Documents { // Undo wrapper for any edit on or through a TextRange or TextContainer. internal class ChangeBlockUndoRecord { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors // Constructor, called when a change block is opening. internal ChangeBlockUndoRecord(ITextContainer textContainer, string actionDescription) { if (textContainer.UndoManager != null) { _undoManager = textContainer.UndoManager; if (_undoManager.IsEnabled) { // Don't bother opening an undo unit if the owning control is // still being initialized (ie, programmatic load by parser). if (textContainer.TextView != null) { // Don't bother opening a new undo unit if we're already nested // inside another. if (_undoManager.OpenedUnit == null) { if (textContainer.TextSelection != null) { _parentUndoUnit = new TextParentUndoUnit(textContainer.TextSelection); } else { _parentUndoUnit = new ParentUndoUnit(actionDescription); } _undoManager.Open(_parentUndoUnit); } } else { // If the owning control isn't initialized (parser is still running), // don't add anything to the undo record. Instead, clear it. _undoManager.Clear(); } } } } #endregion Constructors //------------------------------------------------------ // // Internal Methods // //----------------------------------------------------- #region Internal Methods // Called when a change block is closing. internal void OnEndChange() { // Commit our undo unit. if (_parentUndoUnit != null) { IParentUndoUnit openedUnit; if (_parentUndoUnit.Container is UndoManager) { openedUnit = ((UndoManager)_parentUndoUnit.Container).OpenedUnit; } else { openedUnit = ((IParentUndoUnit)_parentUndoUnit.Container).OpenedUnit; } // UIElementPropertyUndoUnit can clear the undo stack if a change is made to a databound property if (openedUnit == _parentUndoUnit) { if (_parentUndoUnit is TextParentUndoUnit) { ((TextParentUndoUnit)_parentUndoUnit).RecordRedoSelectionState(); } Invariant.Assert(_undoManager != null); _undoManager.Close(_parentUndoUnit, (_parentUndoUnit.LastUnit != null) ? UndoCloseAction.Commit : UndoCloseAction.Discard); } } } #endregion Internal Methods //------------------------------------------------------ // // Private Fields // //------------------------------------------------------ #region Private Fields private readonly UndoManager _undoManager; private readonly IParentUndoUnit _parentUndoUnit; #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ImageConverter.cs
- TileModeValidation.cs
- Rule.cs
- SchemaImporterExtensionElementCollection.cs
- WebAdminConfigurationHelper.cs
- QualificationDataAttribute.cs
- SystemException.cs
- Error.cs
- GridViewRowCollection.cs
- SortedDictionary.cs
- WindowVisualStateTracker.cs
- ParallelRangeManager.cs
- XmlAutoDetectWriter.cs
- LicenseManager.cs
- TreeNodeEventArgs.cs
- NamespaceQuery.cs
- SchemaElement.cs
- HttpResponseHeader.cs
- ComboBoxAutomationPeer.cs
- ContainerUIElement3D.cs
- Brushes.cs
- ParseChildrenAsPropertiesAttribute.cs
- VectorAnimation.cs
- ToolStrip.cs
- Helper.cs
- HttpFileCollection.cs
- Win32MouseDevice.cs
- ConnectionStringsExpressionBuilder.cs
- safesecurityhelperavalon.cs
- AssemblyCollection.cs
- TypeElementCollection.cs
- InfoCard.cs
- DeviceFilterDictionary.cs
- HostingEnvironment.cs
- DataServiceException.cs
- MetadataHelper.cs
- RequestQueue.cs
- XmlDocumentFragment.cs
- InkCanvasInnerCanvas.cs
- Type.cs
- FileDialogCustomPlace.cs
- NamespaceList.cs
- DecoderFallbackWithFailureFlag.cs
- InternalCache.cs
- OleDbErrorCollection.cs
- PointLight.cs
- RequestCacheValidator.cs
- ToolStripComboBox.cs
- XPathConvert.cs
- Int64.cs
- Resources.Designer.cs
- Command.cs
- Parser.cs
- ErrorFormatter.cs
- DateTime.cs
- UrlPath.cs
- WindowsEditBox.cs
- PipelineModuleStepContainer.cs
- SymbolMethod.cs
- XhtmlTextWriter.cs
- SystemIPInterfaceStatistics.cs
- DataError.cs
- _MultipleConnectAsync.cs
- InheritanceRules.cs
- EntityDataSourceDesigner.cs
- DynamicResourceExtension.cs
- SqlStream.cs
- XmlSortKeyAccumulator.cs
- VectorCollection.cs
- TcpServerChannel.cs
- CustomAttribute.cs
- ColumnCollection.cs
- FormatSettings.cs
- ToolStripDropDownItem.cs
- BitStream.cs
- _NetworkingPerfCounters.cs
- ReverseComparer.cs
- SocketElement.cs
- ComPlusTypeLoader.cs
- EntitySqlQueryBuilder.cs
- WebEvents.cs
- XhtmlTextWriter.cs
- DoubleCollectionValueSerializer.cs
- ByteAnimationBase.cs
- Environment.cs
- FormViewDeletedEventArgs.cs
- SqlBulkCopyColumnMapping.cs
- GridViewColumnCollection.cs
- ViewCellSlot.cs
- ZipIOExtraFieldPaddingElement.cs
- SqlHelper.cs
- _BufferOffsetSize.cs
- StaticExtensionConverter.cs
- DocumentSequenceHighlightLayer.cs
- CompensatableSequenceActivity.cs
- HuffCodec.cs
- ContextMarshalException.cs
- FlowDocumentFormatter.cs
- ObjectViewFactory.cs
- IsolatedStorage.cs