Undo,Redo functionalities for Designer host not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anupam roy
    New Member
    • Oct 2007
    • 19

    Undo,Redo functionalities for Designer host not working

    Hi All,

    I want to perform basic Edit menu functionalities on my custom design surface.
    While all the Cut/Copy/Paste/Deelete/Select functionalities working fine with code below,Undo/Redo standard commands are not working for me.

    Code:
    IMenuCommandService menusrv= HostControl.HostSurface.GetService(typeof(IMenuCommandService)) as IMenuCommandService;
                 if (menusrv != null)
                 {
                     switch (editstring)
                     {
    ////////////////////////////////////////////
    //Undo/Redo not working    ////
    //////////////////////////////////////////
                         case "Undo/Redo":
                           menusrv.GlobalInvoke(StandardCommands.undo/StandardCommands.Redo)
    break;
    
                          case "Cut":
                             menusrv.GlobalInvoke(StandardCommands.Cut);
                             break;
                         case "Copy":
                             menusrv.GlobalInvoke(StandardCommands.Copy);
                             break;
                         case "Paste":
                             menusrv.GlobalInvoke(StandardCommands.Paste);
                             break;
                         case "Delete":
                             menusrv.GlobalInvoke(StandardCommands.Delete);
                             break;
                         case "SelectAll":
                             menusrv.GlobalInvoke(StandardCommands.SelectAll);
                             break;
    }
    }
    It will be of great help if sumbody can share a piece of code to implement Undo/Redo functionalitis.

    I am using .NET 2003,C#
    Help will be much appreciated!

    Thanks and Regards,
    -Anupam Roy
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    This example may help:

    Undo and redo commands in the constructor

    Code:
    AddCommand(new MenuCommand(new EventHandler(this.ExecuteUndo), StandardCommands.Undo));
    
    AddCommand(new MenuCommand(new EventHandler(this.ExecuteRedo), StandardCommands.Redo));
    
    void ExecuteUndo(object sender, EventArgs e)
    
    {
    
    UndoEngineImpl undoEngine = _host.GetService(typeof(UndoEngine)) as UndoEngineImpl;
    
    if (undoEngine != null)
    
    undoEngine.DoUndo();
    
    }
    
    void ExecuteRedo(object sender, EventArgs e)
    
    {
    
    UndoEngineImpl undoEngine = _host.GetService(typeof(UndoEngine)) as UndoEngineImpl;
    
    if (undoEngine != null)
    
    undoEngine.DoRedo();
    
    }

    Comment

    Working...