none
Undo Engine will not work with CodeDomDesignerLoader? RRS feed

  • Question

  • I have used this sample

    http://msdn.microsoft.com/en-us/magazine/cc163634.aspx

    and merged BasicHostLoader into CodeDomHostLoader to save desgined surface into XML file. And I am adding services in the following order:

    hostSurface.RemoveService(

    typeof(ComponentSerializationService), false);

    hostSurface.AddService(

    typeof(ComponentSerializationService), new CodeDomComponentSerializationService(hostSurface));

    hostSurface.RemoveService(

    typeof(IDesignerSerializationService), false);

    hostSurface.AddService(

    typeof(IDesignerSerializationService), new DesignerSerializationService(hostSurface));

    hostSurface.AddService(

    typeof(UndoEngine), new MyUndoEngine(hostSurface.GetService(typeof(IDesignerHost)) as IDesignerHost));

    Here DesignerSerializationService is the following:

     

    class DesignerSerializationService : IDesignerSerializationService

    {

     

    IServiceProvider serviceProvider;

     

    public DesignerSerializationService(IServiceProvider serviceProvider)

    {

     

    this.serviceProvider = serviceProvider;

    }

    #region

     

    IDesignerSerializationService Members

     

    public ICollection Deserialize(object serializationData)

    {

     

    SerializationStore serializationStore = serializationData as SerializationStore;

     

    if (serializationStore != null)

    {

     

    ComponentSerializationService componentSerializationService = serviceProvider.GetService(typeof(ComponentSerializationService)) as ComponentSerializationService;

     

    ICollection collection = (ICollection)componentSerializationService.Deserialize(serializationStore);

     

    return collection;

    }

     

    return new object[0];

    }

     

    public object Serialize(System.Collections.ICollection objects)

    {

     

    ComponentSerializationService componentSerializationService = serviceProvider.GetService(typeof(ComponentSerializationService)) as ComponentSerializationService;

     

    SerializationStore returnObject = null;

     

    using (SerializationStore serializationStore = componentSerializationService.CreateStore())

    {

     

    foreach (object obj in objects)

    {

     

    if (obj is Control)

    {

    componentSerializationService.Serialize(serializationStore, obj);

    }

    }

    returnObject = serializationStore;

    }

     

    return returnObject;

    }

    #endregion

    }


    And

    Undo Engine class is the following

     

    public class MyUndoEngine : UndoEngine

    {

     

    private Stack<UndoEngine.UndoUnit> undoStack = new Stack<UndoEngine.UndoUnit>();

     

    private Stack<UndoEngine.UndoUnit> redoStack = new Stack<UndoEngine.UndoUnit>();

     

    public MyUndoEngine(IServiceProvider provider) : base(provider)

    {

     

    // When created, UndoEngine is enabled

     

    this.Enabled = true;

    }

     

     

    public bool EnableUndo

    {

     

    get

    {

     

    return undoStack.Count > 0;

    }

    }

     

    public bool EnableRedo

    {

     

    get

    {

     

    return redoStack.Count > 0;

    }

    }

     

    public void Undo()

    {

     

    if ( undoStack.Count > 0 )

    {

     

    try

    {

     

    UndoEngine.UndoUnit unit = undoStack.Pop();

    unit.Undo();

    redoStack.Push ( unit );

    }

     

    catch ( Exception ex )

    {

    }

    }

     

    else

    {

    }

    }

     

    public void Redo()

    {

     

    if ( redoStack.Count > 0 )

    {

     

    try

    {

     

    UndoEngine.UndoUnit unit = redoStack.Pop();

    unit.Undo();

    undoStack.Push ( unit );

    }

     

    catch ( Exception ex )

    {

    }

    }

     

    else

    {

    }

    }

     

     

    protected override void AddUndoUnit ( UndoEngine.UndoUnit unit )

    {

    undoStack.Push ( unit );

    }

    }


    When I place a component, move it, size, and move it.

    UndoStack has all of the four actions (Create, Move, Size, Move) as undo units but will will only do Selecting component and deleting it when perform Undo action recursively until the Undo Stack gets EMPTY.

    Any suggestions???


    Thank you


    P. s. UndoEnginer works normally when No Loader or BasicHostLoader is selected.

    Tuesday, January 26, 2010 2:42 AM

All replies

  • Hi jcarter121212

    Did you come right with the issue? I am having a similar issue.

    Also could you update the MSDN link as its broken, would love to read the original article.

    Thank you

    Thursday, August 22, 2019 11:14 AM