RadiantQ WPF Gantt
Adding Undo Actions Programmatically
Previous Topic  Next Topic 

You will often have to add custom actions into the gantt's ActionManager when you have the Undo feature enabled. As mentioned in the previous topic, when Undo is enabled, you should not make any changes on the gantt model programmatically without going through the ActionManager.


Some common actions that you will have to add manually into the ActionManager are:


Adding new Tasks


Use the built-in AddAction to add a new task in the gantt.

        private void Add_Click(object sender, RoutedEventArgs e)

        {

            DateTime startTime = TimeComputingUtils.ToUtcKind(DateTime.Today);

            AddAction addAction = new AddAction(this.ganttControl, new CustomTask

                {

                    TaskName = "New Task",

                    StartTime = startTime,

                    PredecessorIndices = "",

                    RequiredEffort = TimeSpan.FromHours(8),

                    TaskID = this.ganttControl.Model.GetNewID().ToString(),

                    Description = "Description of new Task"

                });

            this.ganttControl.ActionManager.RecordAction(addAction);

        }


This Action removes the added task object from the list on undo and adds it back again on redo.


Deleting an existing Task


Use the build-in DeleteAction action to delete an existing task in the gantt:


        private void Delete_Click(object sender, RoutedEventArgs e)

        {

            IActivity activity = this.ganttControl.SelectedActivity;

            if (activity != null)

            {

                if (activity.ChildActivities.Count > 0)

                {

                    MessageBox.Show("Children have to be deleted before parent to support Undo.");

                    return;

                }

                DeleteAction delAction = new DeleteAction(this.ganttControl, activity);

                this.ganttControl.ActionManager.RecordAction(delAction);

            }

            else

                MessageBox.Show("Select an activity first, before delete.");


        }


This Action caches the deleted object and adds it back into the list on undo.


More built-in Actions


There are a whole lot of other built-in undo actions in the RadiantQ.Windows.Controls.Gantt namespace like the following:


Take a look at the sample ..\Samples\ProjectGantt\Misc\GanttControlUndoRedo where the above are illustrated.




� RadiantQ 2009 - 2019. All Rights Reserved.