This project is read-only.

Situation when using Navigate(string name) to current controller

Apr 1, 2009 at 11:30 AM
Edited Apr 2, 2009 at 8:30 AM
If we try to navigate to the current controller using NavigationService.Navigate(string name), the method throws an InvalidOperationException, thrown by history.Add(controller).
What is happening is that during this code:

if (controllerList.Contains(controller))
{
this.controllerList.Remove(controller);
}
 if (current == null)
{
this.controllerList.AddFirst(controller);
this.current = controllerList.First;
}
else
{
this.current = controllerList.AddAfter(current, controller);
}

The node is removed from the LinkedList in the first condition, and then trying to add the controller after the same controller that no longer belongs to the linked list.

This can be easily fixed just by applying a condition if we are navigating to the current controller.
On NavigationService.Add(string name):
(...)
                Controller controller = controllerCache[name];

                Controller currentController = history.GetCurrent();

                if (currentController != controller)
                {
                    controller.View.Show();
                    if (currentController != null)
                    {
                        currentController.View.Hide();
                    }

                    history.Add(controller);
                }                
(...)

Gonçalo Ferreira