Windows Develop Bookmark and Share   
 index > Windows Forms Designer > IMenuCommandService - Undo delete doesn't work...
 

IMenuCommandService - Undo delete doesn't work...

Hi,

I have implemented an UndoEngine in my custom designer, and it works fine for operations such as moving, resizing etc.

The problem is with undoing a delete command which was done using GlobalInvoke(StandardCommands.Delete).  I can see that the ComponentAdded event gets triggered by the IComponentChangeService but the control never reappears on the designersurface.

I have all the required services (I think):

ComponentSerializationService
IDesignerSerializationService
INameCreationService
UndoEngine

The undo is performed by calling the DoUndo() method from the hosting forms menu click event.

Any help would be greatly appreciated.

Here is my UndoEngine implementation:

    internal class MyDesignerUndoEngine : UndoEngine
    {
        Stack<MyDesignerUndoUnit> undoUnits = null;
        Stack<MyDesignerUndoUnit> redoUnits = null;

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            undoUnits.Clear();
            redoUnits.Clear();
        }

        public MyDesignerUndoEngine(IServiceProvider provider)
            : base(provider)
        {
            undoUnits = new Stack<MyDesignerUndoUnit>();
            redoUnits = new Stack<MyDesignerUndoUnit>();

        }

        public bool CanUndo { get { return undoUnits.Count != 0; } }
        public bool CanRedo { get { return redoUnits.Count != 0; } }

        public string UndoText { get { return CanUndo ? undoUnits.Peek().Name : String.Empty; } }
        public string RedoText { get { return CanRedo ? redoUnits.Peek().Name : String.Empty; } }

        public void DoUndo()
        {
            if (CanUndo)
            {
                MyDesignerUndoUnit undoUnit = undoUnits.Pop();
                undoUnit.Undo();
                redoUnits.Push(undoUnit);
            }
        }

        public void DoRedo()
        {
            if (CanRedo)
            {
                MyDesignerUndoUnit undoUnit = redoUnits.Pop();
                undoUnit.Undo();
                undoUnits.Push(undoUnit);
            }
        }

        protected override void AddUndoUnit(UndoEngine.UndoUnit unit)
        {
            redoUnits.Clear();
            undoUnits.Push(unit as MyDesignerUndoUnit);
        }

        protected override UndoEngine.UndoUnit CreateUndoUnit(string name, bool primary)
        {
            return new MyDesignerUndoUnit(this, name) as UndoUnit;
        }

        protected override void DiscardUndoUnit(UndoEngine.UndoUnit unit)
        {
            base.DiscardUndoUnit(unit);
        }

        protected override void OnUndoing(EventArgs e)
        {           
            base.OnUndoing(e);
        }

        protected override void OnUndone(EventArgs e)
        {
            base.OnUndone(e);
        }

        protected class MyDesignerUndoUnit : UndoEngine.UndoUnit
        {
            public MyDesignerUndoUnit(UndoEngine parent, string desc)
                : base(parent, desc)
            {
            }

            public override void ComponentRemoved(ComponentEventArgs e)
            {
                _removalUnit = true;
                _component = e.Component;
                base.ComponentRemoved(e);
            }

            private bool _removalUnit = false;
            private System.ComponentModel.IComponent _component = null;

            public System.ComponentModel.IComponent Component
            {
                get { return _component; }
            }

            public bool RemovalUnit
            {
                get { return _removalUnit; }
            }
        }
    }

 

 

Philip.

Philip W  Monday, February 05, 2007 3:52 PM
No ideas?
Philip W  Friday, February 09, 2007 7:25 PM

Hi, Philip.

I encountered the same problem (my custom UndoEngine is almost the same).

Have you managed to resolve it?

Or maybe someone else can help?

Any help will be most appreciated.

Thanks.

AndriiK  Wednesday, November 19, 2008 1:43 PM
Hi AndreyK,

I have the same problem.
Did you find a solution to solve it?

Any input would be appreciated.

Thanks
badin  Tuesday, December 30, 2008 5:49 PM
I alos came to the same problem
c# new learner
Fei.  Thursday, August 20, 2009 7:29 AM

You can use google to search for other answers

Custom Search

More Threads

• UserControl, ParentControlDesigner and dragging in designer mode
• Making advanced forums
• The designer could not be shown for this file because none of the classes within it can be designed.
• Workaround for Windows NT Service Control OCX problems with Multithreading from Visual Basic 4-6
• How to Implement font picker, color picker , in windows application
• ExpandableObjectConverter with multiple objects.
• MDI Child not loading correct
• IExtenderProvider using a collection property...
• C++/CLI Windows Form Designer bug in causing an event handler to disappear
• Dates between...