Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Framework / System / Windows / Documents / TextTreeUndo.cs / 1 / TextTreeUndo.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: Helper class for TextContainer, handles all undo operations.
//
// History:
// 03/03/2004 : benwest - Created
//
//---------------------------------------------------------------------------
using MS.Internal.Documents;
namespace System.Windows.Documents
{
// This static class is logically an extension of TextContainer. It contains
// TextContainer undo related helpers.
internal static class TextTreeUndo
{
//-----------------------------------------------------
//
// Internal Methods
//
//-----------------------------------------------------
#region Internal Methods
// Adds a TextTreeInsertUndoUnit to the open parent undo unit, if any.
// Called from TextContainer.InsertText and TextContainer.InsertEmbeddedObject.
internal static void CreateInsertUndoUnit(TextContainer tree, int symbolOffset, int symbolCount)
{
UndoManager undoManager;
undoManager = GetOrClearUndoManager(tree);
if (undoManager == null)
return;
undoManager.Add(new TextTreeInsertUndoUnit(tree, symbolOffset, symbolCount));
}
// Adds a TextTreeInsertElementUndoUnit to the open parent undo unit, if any.
// Called from TextContainer.InsertElement.
internal static void CreateInsertElementUndoUnit(TextContainer tree, int symbolOffset, bool deep)
{
UndoManager undoManager;
undoManager = GetOrClearUndoManager(tree);
if (undoManager == null)
return;
undoManager.Add(new TextTreeInsertElementUndoUnit(tree, symbolOffset, deep));
}
// Adds a TextTreePropertyUndoUnit to the open parent undo unit, if any.
// Called by TextElement's property change listener.
internal static void CreatePropertyUndoUnit(TextElement element, DependencyPropertyChangedEventArgs e)
{
UndoManager undoManager;
PropertyRecord record;
TextContainer textContainer = element.TextContainer;
undoManager = GetOrClearUndoManager(textContainer);
if (undoManager == null)
return;
record = new PropertyRecord();
record.Property = e.Property;
record.Value = e.OldValueSource == BaseValueSourceInternal.Local ? e.OldValue : DependencyProperty.UnsetValue;
undoManager.Add(new TextTreePropertyUndoUnit(textContainer, element.TextElementNode.GetSymbolOffset(textContainer.Generation) + 1, record));
}
// Adds a DeleteContentUndoUnit to the open parent undo unit, if any.
// Called by TextContainer.DeleteContent.
internal static TextTreeDeleteContentUndoUnit CreateDeleteContentUndoUnit(TextContainer tree, TextPointer start, TextPointer end)
{
UndoManager undoManager;
TextTreeDeleteContentUndoUnit undoUnit;
if (start.CompareTo(end) == 0)
return null;
undoManager = GetOrClearUndoManager(tree);
if (undoManager == null)
return null;
undoUnit = new TextTreeDeleteContentUndoUnit(tree, start, end);
undoManager.Add(undoUnit);
return undoUnit;
}
// Adds a TextTreeExtractElementUndoUnit to the open parent undo unit, if any.
// Called by TextContainer.ExtractElement.
internal static TextTreeExtractElementUndoUnit CreateExtractElementUndoUnit(TextContainer tree, TextTreeTextElementNode elementNode)
{
UndoManager undoManager;
TextTreeExtractElementUndoUnit undoUnit;
undoManager = GetOrClearUndoManager(tree);
if (undoManager == null)
return null;
undoUnit = new TextTreeExtractElementUndoUnit(tree, elementNode);
undoManager.Add(undoUnit);
return undoUnit;
}
// Returns the local UndoManager.
// Returns null if there is no undo service or if the service exists
// but is disabled or if there is no open parent undo unit.
internal static UndoManager GetOrClearUndoManager(ITextContainer textContainer)
{
UndoManager undoManager;
undoManager = textContainer.UndoManager;
if (undoManager == null)
return null;
if (!undoManager.IsEnabled)
return null;
if (undoManager.OpenedUnit == null)
{
// There's no parent undo unit, so we can't open a child.
//
// Clear the undo stack -- since we depend on symbol offsets
// matching the original document state when an undo unit is
// executed, any of our units currently in the stack will be
// corrupted after we finished the operation in progress.
undoManager.Clear();
return null;
}
return undoManager;
}
#endregion Internal methods
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: Helper class for TextContainer, handles all undo operations.
//
// History:
// 03/03/2004 : benwest - Created
//
//---------------------------------------------------------------------------
using MS.Internal.Documents;
namespace System.Windows.Documents
{
// This static class is logically an extension of TextContainer. It contains
// TextContainer undo related helpers.
internal static class TextTreeUndo
{
//-----------------------------------------------------
//
// Internal Methods
//
//-----------------------------------------------------
#region Internal Methods
// Adds a TextTreeInsertUndoUnit to the open parent undo unit, if any.
// Called from TextContainer.InsertText and TextContainer.InsertEmbeddedObject.
internal static void CreateInsertUndoUnit(TextContainer tree, int symbolOffset, int symbolCount)
{
UndoManager undoManager;
undoManager = GetOrClearUndoManager(tree);
if (undoManager == null)
return;
undoManager.Add(new TextTreeInsertUndoUnit(tree, symbolOffset, symbolCount));
}
// Adds a TextTreeInsertElementUndoUnit to the open parent undo unit, if any.
// Called from TextContainer.InsertElement.
internal static void CreateInsertElementUndoUnit(TextContainer tree, int symbolOffset, bool deep)
{
UndoManager undoManager;
undoManager = GetOrClearUndoManager(tree);
if (undoManager == null)
return;
undoManager.Add(new TextTreeInsertElementUndoUnit(tree, symbolOffset, deep));
}
// Adds a TextTreePropertyUndoUnit to the open parent undo unit, if any.
// Called by TextElement's property change listener.
internal static void CreatePropertyUndoUnit(TextElement element, DependencyPropertyChangedEventArgs e)
{
UndoManager undoManager;
PropertyRecord record;
TextContainer textContainer = element.TextContainer;
undoManager = GetOrClearUndoManager(textContainer);
if (undoManager == null)
return;
record = new PropertyRecord();
record.Property = e.Property;
record.Value = e.OldValueSource == BaseValueSourceInternal.Local ? e.OldValue : DependencyProperty.UnsetValue;
undoManager.Add(new TextTreePropertyUndoUnit(textContainer, element.TextElementNode.GetSymbolOffset(textContainer.Generation) + 1, record));
}
// Adds a DeleteContentUndoUnit to the open parent undo unit, if any.
// Called by TextContainer.DeleteContent.
internal static TextTreeDeleteContentUndoUnit CreateDeleteContentUndoUnit(TextContainer tree, TextPointer start, TextPointer end)
{
UndoManager undoManager;
TextTreeDeleteContentUndoUnit undoUnit;
if (start.CompareTo(end) == 0)
return null;
undoManager = GetOrClearUndoManager(tree);
if (undoManager == null)
return null;
undoUnit = new TextTreeDeleteContentUndoUnit(tree, start, end);
undoManager.Add(undoUnit);
return undoUnit;
}
// Adds a TextTreeExtractElementUndoUnit to the open parent undo unit, if any.
// Called by TextContainer.ExtractElement.
internal static TextTreeExtractElementUndoUnit CreateExtractElementUndoUnit(TextContainer tree, TextTreeTextElementNode elementNode)
{
UndoManager undoManager;
TextTreeExtractElementUndoUnit undoUnit;
undoManager = GetOrClearUndoManager(tree);
if (undoManager == null)
return null;
undoUnit = new TextTreeExtractElementUndoUnit(tree, elementNode);
undoManager.Add(undoUnit);
return undoUnit;
}
// Returns the local UndoManager.
// Returns null if there is no undo service or if the service exists
// but is disabled or if there is no open parent undo unit.
internal static UndoManager GetOrClearUndoManager(ITextContainer textContainer)
{
UndoManager undoManager;
undoManager = textContainer.UndoManager;
if (undoManager == null)
return null;
if (!undoManager.IsEnabled)
return null;
if (undoManager.OpenedUnit == null)
{
// There's no parent undo unit, so we can't open a child.
//
// Clear the undo stack -- since we depend on symbol offsets
// matching the original document state when an undo unit is
// executed, any of our units currently in the stack will be
// corrupted after we finished the operation in progress.
undoManager.Clear();
return null;
}
return undoManager;
}
#endregion Internal methods
}
}
// 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
- ShutDownListener.cs
- Int32AnimationBase.cs
- HtmlInputControl.cs
- EventDrivenDesigner.cs
- DocumentScope.cs
- SessionStateSection.cs
- Vector3D.cs
- WebPartDescriptionCollection.cs
- SimpleTypeResolver.cs
- ReadOnlyDataSource.cs
- TimeoutTimer.cs
- securitycriticaldataformultiplegetandset.cs
- InheritanceContextChangedEventManager.cs
- ServiceAuthorizationBehavior.cs
- Attributes.cs
- EmptyReadOnlyDictionaryInternal.cs
- WebPartVerbsEventArgs.cs
- SectionVisual.cs
- TrustLevel.cs
- RedirectionProxy.cs
- ScrollItemPattern.cs
- IconBitmapDecoder.cs
- PropertyTab.cs
- ScriptResourceAttribute.cs
- Duration.cs
- StructuralObject.cs
- ValidationPropertyAttribute.cs
- ScrollChangedEventArgs.cs
- FlowDocumentPageViewerAutomationPeer.cs
- MatrixCamera.cs
- StrokeSerializer.cs
- ValueConversionAttribute.cs
- LocatorGroup.cs
- ProviderConnectionPointCollection.cs
- EncryptedKey.cs
- InstanceData.cs
- TypeProvider.cs
- RuleProcessor.cs
- DiffuseMaterial.cs
- HostProtectionException.cs
- OperatingSystem.cs
- Condition.cs
- TimeSpanMinutesConverter.cs
- SymbolTable.cs
- WebZoneDesigner.cs
- HorizontalAlignConverter.cs
- FileRecordSequenceCompletedAsyncResult.cs
- CheckBoxPopupAdapter.cs
- CheckBoxList.cs
- BamlRecords.cs
- SerialPinChanges.cs
- RichTextBox.cs
- ContentDisposition.cs
- TransformationRules.cs
- PointCollection.cs
- ContainerFilterService.cs
- XmlExpressionDumper.cs
- HelpProvider.cs
- XXXInfos.cs
- AssociationTypeEmitter.cs
- ToolBarTray.cs
- BinaryUtilClasses.cs
- BehaviorEditorPart.cs
- SchemaMapping.cs
- ScalarConstant.cs
- FontFaceLayoutInfo.cs
- ImageListUtils.cs
- Rotation3D.cs
- DbDataAdapter.cs
- EntityModelBuildProvider.cs
- Canonicalizers.cs
- RegexBoyerMoore.cs
- MethodRental.cs
- SafeRegistryKey.cs
- PeerName.cs
- BindingParameterCollection.cs
- PipelineModuleStepContainer.cs
- XsltSettings.cs
- AxHost.cs
- Propagator.ExtentPlaceholderCreator.cs
- ConfigurationManagerInternalFactory.cs
- Site.cs
- EventRouteFactory.cs
- XmlSchemaObjectCollection.cs
- WindowsListView.cs
- WindowsFormsSectionHandler.cs
- FloatUtil.cs
- DirectoryObjectSecurity.cs
- IteratorFilter.cs
- ProcessModelSection.cs
- RegexCompilationInfo.cs
- DataGridBoolColumn.cs
- WebPartExportVerb.cs
- Operator.cs
- CurrentChangedEventManager.cs
- ImageFormatConverter.cs
- KeyValueConfigurationElement.cs
- UIElementParagraph.cs
- CommunicationException.cs
- CodeTypeConstructor.cs