2 using System.Collections.Generic;
3 using System.ComponentModel;
6 namespace Tizen.NUI.Binding
8 [EditorBrowsable(EditorBrowsableState.Never)]
9 internal class NavigationModel
11 readonly List<Page> _modalStack = new List<Page>();
12 readonly List<List<Page>> _navTree = new List<List<Page>>();
14 public Page CurrentPage
19 return _navTree.Last().Last();
24 public IEnumerable<Page> Modals
26 get { return _modalStack; }
29 public IEnumerable<Page> Roots
33 foreach (List<Page> list in _navTree)
40 public IReadOnlyList<IReadOnlyList<Page>> Tree
42 get { return _navTree; }
51 public void InsertPageBefore(Page page, Page before)
53 List<Page> currentStack = _navTree.Last();
54 int index = currentStack.IndexOf(before);
57 throw new ArgumentException("before must be in the current navigation context");
59 currentStack.Insert(index, page);
62 public Page Pop(Page ancestralNav)
64 ancestralNav = AncestorToRoot(ancestralNav);
65 foreach (List<Page> stack in _navTree)
67 if (stack.Contains(ancestralNav))
70 throw new InvalidNavigationException("Can not pop final item in stack");
71 Page result = stack.Last();
77 throw new InvalidNavigationException("Popped from unpushed item?");
80 public Page PopModal()
82 if (_navTree.Count <= 1)
83 throw new InvalidNavigationException("Can't pop modal without any modals pushed");
84 Page modal = _navTree.Last().First();
85 _modalStack.Remove(modal);
86 _navTree.Remove(_navTree.Last());
90 public Page PopTopPage()
93 if (_navTree.Count == 1)
95 if (_navTree[0].Count > 1)
97 itemToRemove = _navTree[0].Last();
98 _navTree[0].Remove(itemToRemove);
103 itemToRemove = _navTree.Last().Last();
104 _navTree.Last().Remove(itemToRemove);
105 if (!_navTree.Last().Any())
107 _navTree.RemoveAt(_navTree.Count - 1);
112 public void PopToRoot(Page ancestralNav)
114 ancestralNav = AncestorToRoot(ancestralNav);
115 foreach (List<Page> stack in _navTree)
117 if (stack.Contains(ancestralNav))
119 if (stack.Count <= 1)
120 throw new InvalidNavigationException("Can not pop final item in stack");
121 stack.RemoveRange(1, stack.Count - 1);
126 throw new InvalidNavigationException("Popped from unpushed item?");
129 public void Push(Page page, Page ancestralNav)
131 if (ancestralNav == null)
134 throw new InvalidNavigationException("Ancestor must be provided for all pushes except first");
135 _navTree.Add(new List<Page> { page });
139 ancestralNav = AncestorToRoot(ancestralNav);
141 foreach (List<Page> stack in _navTree)
143 if (stack.Contains(ancestralNav))
150 throw new InvalidNavigationException("Invalid ancestor passed");
153 public void PushModal(Page page)
155 _navTree.Add(new List<Page> { page });
156 _modalStack.Add(page);
159 public bool RemovePage(Page page)
162 List<Page> currentStack = _navTree.Last();
164 while (!(found = currentStack.Remove(page)) && i < _navTree.Count - 1)
166 currentStack = _navTree[i++];
172 Page AncestorToRoot(Page ancestor)
174 Page result = ancestor;
175 // while (!Application.IsApplicationOrNull(result.RealParent))
176 result = (Page)result.RealParent;