Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Framework / System / Windows / Documents / TextTreeUndoUnit.cs / 1 / TextTreeUndoUnit.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: Base class for all TextContainer undo units. // // History: // 03/03/2004 : benwest - Created // //--------------------------------------------------------------------------- using System; using MS.Internal; using MS.Internal.Documents; namespace System.Windows.Documents { // Base class for all TextContainer undo units. internal abstract class TextTreeUndoUnit : IUndoUnit { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors // Create a new undo unit instance. internal TextTreeUndoUnit(TextContainer tree, int symbolOffset) { _tree = tree; _symbolOffset = symbolOffset; _treeContentHashCode = _tree.GetContentHashCode(); } #endregion Constructors //------------------------------------------------------ // // Public Methods // //----------------------------------------------------- #region Public Methods // Called by the undo manager. Restores tree state to its condition // when the unit was created. Assumes the tree state matches conditions // just after the unit was created. public void Do() { _tree.BeginChange(); try { DoCore(); } finally { _tree.EndChange(); } } // Worker for Do method, implemented by derived class. public abstract void DoCore(); // Called by the undo manager. TextContainer undo units never merge. public bool Merge(IUndoUnit unit) { Invariant.Assert(unit != null); return false; } #endregion Public Methods //------------------------------------------------------ // // Protected Properties // //------------------------------------------------------ #region Protected Properties // TextContainer associated with this undo unit. protected TextContainer TextContainer { get { return _tree; } } // Offset in symbols of this undo unit within the TextContainer content. protected int SymbolOffset { get { return _symbolOffset; } } #endregion Protected Properties //----------------------------------------------------- // // Internal Methods // //------------------------------------------------------ #region Internal Methods // Explicitly sets this undo unit's content hash code to match the // current tree state. This happens automatically in the ctor, but // some undo units (for delte operations) need to be initialized before // the content is modified, in which case they call this method // afterwards. internal void SetTreeHashCode() { _treeContentHashCode = _tree.GetContentHashCode(); } // Verifies the TextContainer state matches the original state when this undo // unit was created. Because we use symbol offsets to track the // position of the content to modify, errors in the undo code or reentrant // document edits by random code could potentially // corrupt data rather than raise an immediate exception. // // This method uses Invariant.Assert to trigger a FailFast in the case an error // is detected, before we get a chance to corrupt data. internal void VerifyTreeContentHashCode() { if (_tree.GetContentHashCode() != _treeContentHashCode) { // Data is irrecoverably corrupted, shut down! Invariant.Assert(false, "Undo unit is out of [....] with TextContainer!"); } } // Converts a LocalValueEnumerator into an array of PropertyRecords. // The array is safe to cache, LocalValueEnumerators are not. internal static PropertyRecord[] LocalValueEnumeratorToArray(LocalValueEnumerator valuesEnumerator) { PropertyRecord[] records = new PropertyRecord[valuesEnumerator.Count]; int count = 0; valuesEnumerator.Reset(); while (valuesEnumerator.MoveNext()) { DependencyProperty dp = valuesEnumerator.Current.Property; if (!dp.ReadOnly) { records[count].Property = dp; records[count].Value = valuesEnumerator.Current.Value; count++; } } PropertyRecord[] trimmedResult; if(valuesEnumerator.Count != count) { trimmedResult = new PropertyRecord[count]; for(int i=0; i// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: Base class for all TextContainer undo units. // // History: // 03/03/2004 : benwest - Created // //--------------------------------------------------------------------------- using System; using MS.Internal; using MS.Internal.Documents; namespace System.Windows.Documents { // Base class for all TextContainer undo units. internal abstract class TextTreeUndoUnit : IUndoUnit { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors // Create a new undo unit instance. internal TextTreeUndoUnit(TextContainer tree, int symbolOffset) { _tree = tree; _symbolOffset = symbolOffset; _treeContentHashCode = _tree.GetContentHashCode(); } #endregion Constructors //------------------------------------------------------ // // Public Methods // //----------------------------------------------------- #region Public Methods // Called by the undo manager. Restores tree state to its condition // when the unit was created. Assumes the tree state matches conditions // just after the unit was created. public void Do() { _tree.BeginChange(); try { DoCore(); } finally { _tree.EndChange(); } } // Worker for Do method, implemented by derived class. public abstract void DoCore(); // Called by the undo manager. TextContainer undo units never merge. public bool Merge(IUndoUnit unit) { Invariant.Assert(unit != null); return false; } #endregion Public Methods //------------------------------------------------------ // // Protected Properties // //------------------------------------------------------ #region Protected Properties // TextContainer associated with this undo unit. protected TextContainer TextContainer { get { return _tree; } } // Offset in symbols of this undo unit within the TextContainer content. protected int SymbolOffset { get { return _symbolOffset; } } #endregion Protected Properties //----------------------------------------------------- // // Internal Methods // //------------------------------------------------------ #region Internal Methods // Explicitly sets this undo unit's content hash code to match the // current tree state. This happens automatically in the ctor, but // some undo units (for delte operations) need to be initialized before // the content is modified, in which case they call this method // afterwards. internal void SetTreeHashCode() { _treeContentHashCode = _tree.GetContentHashCode(); } // Verifies the TextContainer state matches the original state when this undo // unit was created. Because we use symbol offsets to track the // position of the content to modify, errors in the undo code or reentrant // document edits by random code could potentially // corrupt data rather than raise an immediate exception. // // This method uses Invariant.Assert to trigger a FailFast in the case an error // is detected, before we get a chance to corrupt data. internal void VerifyTreeContentHashCode() { if (_tree.GetContentHashCode() != _treeContentHashCode) { // Data is irrecoverably corrupted, shut down! Invariant.Assert(false, "Undo unit is out of [....] with TextContainer!"); } } // Converts a LocalValueEnumerator into an array of PropertyRecords. // The array is safe to cache, LocalValueEnumerators are not. internal static PropertyRecord[] LocalValueEnumeratorToArray(LocalValueEnumerator valuesEnumerator) { PropertyRecord[] records = new PropertyRecord[valuesEnumerator.Count]; int count = 0; valuesEnumerator.Reset(); while (valuesEnumerator.MoveNext()) { DependencyProperty dp = valuesEnumerator.Current.Property; if (!dp.ReadOnly) { records[count].Property = dp; records[count].Value = valuesEnumerator.Current.Value; count++; } } PropertyRecord[] trimmedResult; if(valuesEnumerator.Count != count) { trimmedResult = new PropertyRecord[count]; for(int i=0; i
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CanonicalXml.cs
- TextTreeRootTextBlock.cs
- SerializationInfoEnumerator.cs
- SmiRequestExecutor.cs
- UnorderedHashRepartitionStream.cs
- DataListComponentEditor.cs
- TrackingMemoryStreamFactory.cs
- ObjectIDGenerator.cs
- HtmlToClrEventProxy.cs
- TreeViewEvent.cs
- DebugView.cs
- WorkflowServiceHost.cs
- SmtpNetworkElement.cs
- ApplicationHost.cs
- BitmapEditor.cs
- ReadOnlyDictionary.cs
- FixedPageAutomationPeer.cs
- ViewGenResults.cs
- ProcessHost.cs
- RijndaelManagedTransform.cs
- SelectionProcessor.cs
- IncrementalReadDecoders.cs
- RoutingChannelExtension.cs
- RuleElement.cs
- ProcessModelInfo.cs
- basecomparevalidator.cs
- TemplateAction.cs
- MachineKey.cs
- DocumentSchemaValidator.cs
- PropertyGeneratedEventArgs.cs
- DescendantOverDescendantQuery.cs
- FrameworkElementFactory.cs
- IsolatedStorageFileStream.cs
- SimpleModelProvider.cs
- JsonServiceDocumentSerializer.cs
- ValueSerializerAttribute.cs
- ConfigXmlDocument.cs
- ListViewDeleteEventArgs.cs
- DesignerHelpers.cs
- Error.cs
- ITextView.cs
- ObjectQueryState.cs
- PopupControlService.cs
- State.cs
- RangeValueProviderWrapper.cs
- ImageBrush.cs
- SelectionItemPatternIdentifiers.cs
- ISO2022Encoding.cs
- HwndTarget.cs
- AssemblyName.cs
- IsolatedStorage.cs
- ModelTreeEnumerator.cs
- TransactionChannel.cs
- XmlSchemaInferenceException.cs
- TextTreeTextNode.cs
- TypeLoadException.cs
- CFStream.cs
- IpcClientManager.cs
- ListControlConvertEventArgs.cs
- BaseTemplateBuildProvider.cs
- XmlWrappingReader.cs
- WbemException.cs
- DoWorkEventArgs.cs
- XsltArgumentList.cs
- GridViewPageEventArgs.cs
- BackgroundFormatInfo.cs
- EdmItemError.cs
- DataSourceHelper.cs
- PropertyToken.cs
- BooleanFunctions.cs
- BitmapEffectCollection.cs
- ProcessThreadCollection.cs
- ObjectViewListener.cs
- EntityDataSourceDataSelection.cs
- KnowledgeBase.cs
- WSHttpBinding.cs
- IgnorePropertiesAttribute.cs
- ImageListUtils.cs
- XmlDocumentType.cs
- Oid.cs
- CFStream.cs
- DataBindEngine.cs
- DataFormats.cs
- ReadOnlyHierarchicalDataSource.cs
- RegexRunner.cs
- Pkcs9Attribute.cs
- ContainerUIElement3D.cs
- SessionState.cs
- _CacheStreams.cs
- ReadWriteSpinLock.cs
- RadioButtonBaseAdapter.cs
- FocusWithinProperty.cs
- PropertyIDSet.cs
- AdvancedBindingEditor.cs
- _CookieModule.cs
- Transform3DGroup.cs
- LicenseException.cs
- diagnosticsswitches.cs
- BitmapEffectInput.cs
- ParallelTimeline.cs