Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / 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 : [....] - 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 sync 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
- RoleManagerSection.cs
- GreenMethods.cs
- ScriptRegistrationManager.cs
- HttpChannelHelper.cs
- SafeWaitHandle.cs
- EmissiveMaterial.cs
- FormsAuthenticationEventArgs.cs
- LOSFormatter.cs
- TextProperties.cs
- ColorAnimation.cs
- SoapTransportImporter.cs
- ToolStripDropDownClosedEventArgs.cs
- Token.cs
- MarginsConverter.cs
- TreeNode.cs
- CompiledIdentityConstraint.cs
- UInt64Storage.cs
- DownloadProgressEventArgs.cs
- TaskExtensions.cs
- XmlDataCollection.cs
- COM2Enum.cs
- xmlglyphRunInfo.cs
- SafeFileMappingHandle.cs
- SymLanguageType.cs
- ValueQuery.cs
- HttpProcessUtility.cs
- EncryptedPackageFilter.cs
- HotSpot.cs
- SQLInt16.cs
- CommonRemoteMemoryBlock.cs
- WindowsToolbarAsMenu.cs
- LassoSelectionBehavior.cs
- CalendarButton.cs
- MouseButtonEventArgs.cs
- __Error.cs
- FlowLayoutSettings.cs
- _DomainName.cs
- DataGridViewCheckBoxColumn.cs
- DataSourceControl.cs
- ListControl.cs
- RootCodeDomSerializer.cs
- TypeNameHelper.cs
- TransformerConfigurationWizardBase.cs
- UserCancellationException.cs
- TagPrefixCollection.cs
- TypeNameConverter.cs
- PersonalizationEntry.cs
- SelectionEditor.cs
- ConfigXmlSignificantWhitespace.cs
- DrawingServices.cs
- CodeExporter.cs
- tibetanshape.cs
- SerializationAttributes.cs
- CngKeyBlobFormat.cs
- EventRouteFactory.cs
- TranslateTransform.cs
- Input.cs
- DayRenderEvent.cs
- BinaryWriter.cs
- SpeechRecognizer.cs
- ReadOnlyDataSource.cs
- InheritanceService.cs
- PointCollection.cs
- XPathNodePointer.cs
- CompilationLock.cs
- CmsUtils.cs
- ExceptionHandlers.cs
- IgnoreDeviceFilterElement.cs
- InvalidCastException.cs
- CodeIdentifier.cs
- TreeNodeSelectionProcessor.cs
- FontDifferentiator.cs
- StreamInfo.cs
- CustomCredentialPolicy.cs
- DisplayNameAttribute.cs
- RegexStringValidatorAttribute.cs
- SettingsPropertyValue.cs
- FormClosedEvent.cs
- DocumentScope.cs
- TypeSystem.cs
- DSASignatureFormatter.cs
- JsonEnumDataContract.cs
- ResourcesBuildProvider.cs
- XmlStreamStore.cs
- ContractListAdapter.cs
- DateTimeFormat.cs
- InkCanvasFeedbackAdorner.cs
- CompileLiteralTextParser.cs
- ServiceDocumentFormatter.cs
- SQLInt16Storage.cs
- TimestampInformation.cs
- Hashtable.cs
- SafeTokenHandle.cs
- ISessionStateStore.cs
- WindowsListViewItemStartMenu.cs
- BroadcastEventHelper.cs
- TreeViewImageKeyConverter.cs
- XmlReader.cs
- DesignSurface.cs
- FieldToken.cs