示例#1
0
        /// <summary>
        /// Handles a change to the undo manager for a given dependency object.
        /// </summary>
        /// <param name="dependencyObject">The target object for this attached property.</param>
        /// <param name="dependencyPropertyChangedEventArgs">The event parameters.</param>
        static void OnUndoManagerChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            // This will remove the previous UndoManager from the object.  Note that an old UndoManager must be removed from the class before a new one can be
            // added, otherwise the events will still be connected to the old manager after the new one is set.
            if (dependencyPropertyChangedEventArgs.OldValue is UndoManager)
            {
                // This is the 'UnDo' manager for the old scope.
                UndoManager undoManager = dependencyPropertyChangedEventArgs.OldValue as UndoManager;

                // There is also a specific handler for the particulars of a given class (TextBox, CheckBox, etc.).  To save time, a mapping is used to find an
                // interface to the methods that handle the particulars of each class.  An entry must be made in this map for any new user interface elements
                // not covered by default by this class.
                IUndo iUndo;
                if (undoManager.typeUndoMapField.TryGetValue(dependencyObject.GetType(), out iUndo))
                {
                    iUndo.Unregister(dependencyObject);
                }
            }

            // This will connect a User Interface Element to an UndoManager.  The UndoManager will be hooked into the elements events and when the control's
            // content is changed, entries will be made in a stack that keeps track of the operations.  This stack is integrated with all the other elements in
            // the scope of this UndoManager so that actions are 'Undone' in the order they were added to the UndoManager in this scope.
            if (dependencyPropertyChangedEventArgs.NewValue is UndoManager)
            {
                // This is the 'UnDo' manager for the new scope.
                UndoManager undoManager = dependencyPropertyChangedEventArgs.NewValue as UndoManager;

                // There is also a specific handler for the particulars of a given class (TextBox, CheckBox, etc.).  To save time, a mapping is used to find an
                // interface to the methods that handle the particulars of each class.  An entry must be made in this map for any new user interface elements
                // not covered by default by this class.
                IUndo iUndo;
                if (undoManager.typeUndoMapField.TryGetValue(dependencyObject.GetType(), out iUndo))
                {
                    iUndo.Register(dependencyObject);
                }
            }
        }
示例#2
0
 /// <summary>
 /// Creates an object that manages the Undo/Redo logic that is particular to this control.
 /// </summary>
 /// <param name="undoManager">An object that coordinates all the undo/redo actions in a scope.</param>
 public RichTextBoxUndo(UndoManager undoManager) : base(undoManager)
 {
 }
示例#3
0
        /// <summary>
        /// Handles a change to the undo manager for a given dependency object.
        /// </summary>
        /// <param name="dependencyObject">The target object for this attached property.</param>
        /// <param name="dependencyPropertyChangedEventArgs">The event parameters.</param>
        static void OnUndoScopeChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            // Validate the parameters.
            if (dependencyObject == null)
            {
                throw new ArgumentNullException("dependencyObject");
            }
            if (dependencyPropertyChangedEventArgs == null)
            {
                throw new ArgumentNullException("dependencyPropertyChangedEventArgs");
            }

            // Extract the specific arguments from the generic ones.
            UndoManager             oldUndoManager          = dependencyPropertyChangedEventArgs.OldValue as UndoManager;
            UndoManager             newUndoManager          = dependencyPropertyChangedEventArgs.NewValue as UndoManager;
            FrameworkElement        frameworkElement        = dependencyObject as FrameworkElement;
            FrameworkContentElement frameworkContentElement = dependencyObject as FrameworkContentElement;

            // This is the manager that was previously associated with the root of the Undo Scope.
            if (oldUndoManager != null)
            {
                // This will remove a handler for the mouse focus events.
                oldUndoManager.focusUndo.Unregister(dependencyObject);

                // This will remove the UndoManager from all the child controls.
                dependencyObject.ClearValue(UndoManager.UndoManagerProperty);

                // This will remove the handlers for the undo/redo operations for the given undo manager.
                if (frameworkElement != null)
                {
                    frameworkElement.RemoveHandler(CommandManager.PreviewExecutedEvent, new ExecutedRoutedEventHandler(oldUndoManager.OnCommand));
                }

                // This will remove the handlers for the undo/redo operations for the given undo manager.
                if (frameworkContentElement != null)
                {
                    frameworkContentElement.RemoveHandler(CommandManager.PreviewExecutedEvent, new ExecutedRoutedEventHandler(oldUndoManager.OnCommand));
                }
            }

            // This will add the high level handlers for the root node in the UndoManager scope.
            if (newUndoManager != null)
            {
                // This will add a handler for the mouse focus events.
                newUndoManager.focusUndo.Register(dependencyObject);

                // This adds the Undo Manager to all the child windows in the scope of this user interface element which forms
                // the root of the scope.
                dependencyObject.SetValue(UndoManager.UndoManagerProperty, newUndoManager);

                // This will add the handlers for the undo/redo operations for the given undo manager.
                if (frameworkElement != null)
                {
                    frameworkElement.AddHandler(CommandManager.PreviewExecutedEvent, new ExecutedRoutedEventHandler(newUndoManager.OnCommand), true);
                }

                //// This will add the handlers for the undo/redo operations for the given undo manager.
                if (frameworkContentElement != null)
                {
                    frameworkContentElement.AddHandler(CommandManager.PreviewExecutedEvent, new ExecutedRoutedEventHandler(newUndoManager.OnCommand), true);
                }
            }
        }
示例#4
0
 /// <summary>
 /// Creates an object that manages the Undo/Redo logic that is particular to this control.
 /// </summary>
 /// <param name="undoManager">An object that coordinates all the undo/redo actions in a scope.</param>
 protected TextBoxBaseUndo(UndoManager undoManager) : base(undoManager)
 {
 }
示例#5
0
 /// <summary>
 /// Creates an object that manages the Undo/Redo logic that is particular to this control.
 /// </summary>
 /// <param name="undoManager">An object that coordinates all the undo/redo actions in a scope.</param>
 public SelectorUndo(UndoManager undoManager) : base(undoManager)
 {
     // Initialzie the object
     this.isUndoing = false;
 }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the UndoManager class.
 /// </summary>
 /// <param name="undoManager"></param>
 protected UndoBase(UndoManager undoManager)
 {
     // Initialize the object.
     this.undoManager = undoManager;
 }
 /// <summary>
 /// Creates an object that manages the Undo/Redo logic that is particular to this control.
 /// </summary>
 /// <param name="undoManager">An object that coordinates all the undo/redo actions in a scope.</param>
 public ToggleButtonUndo(UndoManager undoManager)
     : base(undoManager)
 {
     // Initialzie the object
     this.isUndoing = false;
 }