This is a migrated thread and some comments may be shown as answers.

SerializableGraphSourceBase and undo

1 Answer 82 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Rajkumar
Top achievements
Rank 1
Rajkumar asked on 05 Sep 2014, 09:25 AM
I derived out my class based on SerializableGraphSourceBase.

When I add shape to diagram using AddNode, and I try to undo, the shape still exists on the diagram.

How do i specify so as to consider the AddNode action for undo redo ?

1 Answer, 1 is accepted

Sort by
0
Milena
Telerik team
answered on 08 Sep 2014, 04:35 PM
Hi Rajkumar,

When using GraphSourceBase and add a shape through AddNode(), before performing the undo method 
you should notify the diagram for that action and update the Undo/RedoStack of the RadDiagram. You can achieve this by using UndoRedoService and UndoableDelegateCommand like so: 

private void AddShape (...)
{
     ....
   graphSource.AddNode(newShape);
 
   UndoableDelegateCommand addShape = new UndoableDelegateCommand(CommandNames.AddShape,
    c =>
    {
        graphSource.AddNode(newShape);
    },
    c =>
    {
        graphSource.RemoveItem(newShape);
    });

   this.diagram.UndoRedoService.AddCommand(addShape);           
}

You can notice that I've used:
- static class CommandNames for the name of the UndoableDelegateCommand and 
- AddNode() and RemoveItem() which comes from SerializableGraphSourceBase. 
This will allow you to take advantage of the built-in Undo/Redo functionality of the diagram and just register the new action.

For your convenience I implemented this approach in the attached project. Please take a look at it and let us know if it works for you.

Regards,
Milena
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
Diagram
Asked by
Rajkumar
Top achievements
Rank 1
Answers by
Milena
Telerik team
Share this question
or