Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Documents / TextTreeUndoUnit.cs / 1305600 / TextTreeUndoUnit.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: Base class for all TextContainer undo units. // // History: // 03/03/2004 : [....] - Created // //--------------------------------------------------------------------------- using System; using MS.Internal; using MS.Internal.Documents; using System.Windows.Data; 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!"); } } // Gets an array of PropertyRecords from a DependencyObject's LocalValueEnumerator. // The array is safe to cache, LocalValueEnumerators are not. internal static PropertyRecord[] GetPropertyRecordArray(DependencyObject d) { LocalValueEnumerator valuesEnumerator = d.GetLocalValueEnumerator(); PropertyRecord[] records = new PropertyRecord[valuesEnumerator.Count]; int count = 0; valuesEnumerator.Reset(); while (valuesEnumerator.MoveNext()) { DependencyProperty dp = valuesEnumerator.Current.Property; if (!dp.ReadOnly) { // LocalValueEntry.Value can be an Expression, which we can't duplicate when we // undo, so we copy over the current value from DependencyObject.GetValue instead. records[count].Property = dp; records[count].Value = d.GetValue(dp); 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 : [....] - Created // //--------------------------------------------------------------------------- using System; using MS.Internal; using MS.Internal.Documents; using System.Windows.Data; 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!"); } } // Gets an array of PropertyRecords from a DependencyObject's LocalValueEnumerator. // The array is safe to cache, LocalValueEnumerators are not. internal static PropertyRecord[] GetPropertyRecordArray(DependencyObject d) { LocalValueEnumerator valuesEnumerator = d.GetLocalValueEnumerator(); PropertyRecord[] records = new PropertyRecord[valuesEnumerator.Count]; int count = 0; valuesEnumerator.Reset(); while (valuesEnumerator.MoveNext()) { DependencyProperty dp = valuesEnumerator.Current.Property; if (!dp.ReadOnly) { // LocalValueEntry.Value can be an Expression, which we can't duplicate when we // undo, so we copy over the current value from DependencyObject.GetValue instead. records[count].Property = dp; records[count].Value = d.GetValue(dp); 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
- Base64Encoding.cs
- SemanticTag.cs
- DataTableMappingCollection.cs
- ToolBarButtonClickEvent.cs
- PackagePartCollection.cs
- CustomTypeDescriptor.cs
- xmlsaver.cs
- FamilyMap.cs
- CharEntityEncoderFallback.cs
- XmlTextReaderImplHelpers.cs
- SchemaContext.cs
- Material.cs
- SystemColorTracker.cs
- ScriptingSectionGroup.cs
- WindowsTokenRoleProvider.cs
- EventPrivateKey.cs
- ReferencedAssembly.cs
- ExtentKey.cs
- ReadOnlyDataSource.cs
- LocalIdKeyIdentifierClause.cs
- ColorKeyFrameCollection.cs
- TextWriter.cs
- MarkupExtensionParser.cs
- MetadataItem_Static.cs
- DataGridViewRowCancelEventArgs.cs
- MatcherBuilder.cs
- DiscoveryClientDuplexChannel.cs
- HMACSHA512.cs
- DataGridViewCellStyleChangedEventArgs.cs
- SafeNativeMethods.cs
- IntSumAggregationOperator.cs
- WebContext.cs
- ConvertTextFrag.cs
- RequiredFieldValidator.cs
- Substitution.cs
- TreeViewHitTestInfo.cs
- ObjectSet.cs
- HtmlHistory.cs
- Action.cs
- DesignerTransaction.cs
- TextFindEngine.cs
- NameValuePermission.cs
- DataGridItem.cs
- MsdtcClusterUtils.cs
- Brushes.cs
- CommonRemoteMemoryBlock.cs
- DotExpr.cs
- WrappedIUnknown.cs
- LoginAutoFormat.cs
- WindowsScrollBar.cs
- ProxyFragment.cs
- DynamicRenderer.cs
- DBPropSet.cs
- QilTernary.cs
- uribuilder.cs
- diagnosticsswitches.cs
- SwitchElementsCollection.cs
- DesigntimeLicenseContextSerializer.cs
- Ops.cs
- AsyncOperation.cs
- MenuItem.cs
- SecurityElementBase.cs
- RenameRuleObjectDialog.Designer.cs
- Effect.cs
- DefaultShape.cs
- TextContainerChangeEventArgs.cs
- BamlCollectionHolder.cs
- Transform3DGroup.cs
- DataSourceControl.cs
- ResourceWriter.cs
- CodeMemberField.cs
- indexingfiltermarshaler.cs
- XslNumber.cs
- FacetChecker.cs
- ShellProvider.cs
- ManualResetEvent.cs
- DataGridRowDetailsEventArgs.cs
- KnownBoxes.cs
- ProviderSettingsCollection.cs
- SqlDataSourceConfigureFilterForm.cs
- CacheSection.cs
- DbDeleteCommandTree.cs
- LoginName.cs
- DeclarativeConditionsCollection.cs
- ProxyRpc.cs
- XsltContext.cs
- IPEndPointCollection.cs
- FixedTextContainer.cs
- SaveFileDialog.cs
- ManifestResourceInfo.cs
- FormattedTextSymbols.cs
- Activity.cs
- WebProxyScriptElement.cs
- DirectoryNotFoundException.cs
- DbProviderFactories.cs
- KeyTime.cs
- TabControlAutomationPeer.cs
- MimeWriter.cs
- InvalidComObjectException.cs
- SessionEndedEventArgs.cs