blob: ae1d29bc22cc843572fec3851c63e64a392f6a22 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using Tango.PPC.Common;
using Tango.PPC.Common.Modules;
using Tango.PPC.Common.Navigation;
using Tango.PPC.UI.Views;
using Tango.SharedUI.Controls;
namespace Tango.PPC.UI.Navigation
{
/// <summary>
/// Represents the default PPC navigation manager.
/// </summary>
/// <seealso cref="Tango.PPC.Common.Navigation.INavigationManager" />
public class DefaultNavigationManager : INavigationManager
{
private IPPCModuleLoader _moduleLoader;
/// <summary>
/// Initializes a new instance of the <see cref="DefaultNavigationManager"/> class.
/// </summary>
/// <param name="moduleLoader">The module loader.</param>
public DefaultNavigationManager(IPPCModuleLoader moduleLoader)
{
_moduleLoader = moduleLoader;
}
/// <summary>
/// Navigates to the specified PPC view.
/// </summary>
/// <param name="view">The view.</param>
public void NavigateTo(NavigationView view)
{
if (view == NavigationView.HomeModule)
{
MainView.Instance.NavigationControl.NavigateTo(NavigationView.LayoutView.ToString());
var firstModule = _moduleLoader.UserModules.FirstOrDefault();
LayoutView.Instance.NavigationControl.NavigateTo(firstModule.Name);
var moduleAtt = firstModule.GetType().GetCustomAttribute<PPCModuleAttribute>();
if (moduleAtt != null)
{
NavigateTo(firstModule.GetType(), moduleAtt.HomeViewName);
}
}
else
{
MainView.Instance.NavigationControl.NavigateTo(view.ToString());
}
}
/// <summary>
/// Navigates to the specified module.
/// </summary>
/// <typeparam name="T"></typeparam>
public void NavigateTo<T>() where T : IPPCModule
{
MainView.Instance.NavigationControl.NavigateTo(NavigationView.LayoutView.ToString());
var navigationControl = LayoutView.Instance.NavigationControl;
var module = _moduleLoader.UserModules.SingleOrDefault(x => x.GetType() == typeof(T));
navigationControl.NavigateTo(module.Name);
}
/// <summary>
/// Navigates to the specified module name.
/// </summary>
/// <param name="moduleName">Name of the module.</param>
public void NavigateTo(string moduleName)
{
var navigationControl = LayoutView.Instance.NavigationControl;
navigationControl.NavigateTo(moduleName);
}
/// <summary>
/// Navigates to the specified module using the view path (e.g MainView.JobsView).
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="viewPath">The view path.</param>
public void NavigateTo<T>(string viewPath) where T : IPPCModule
{
NavigateTo<T>(viewPath.Split(','));
}
/// <summary>
/// Navigates to the specified module using the view path (e.g MainView,JobsView).
/// This method makes it easy to do stuff like NavigateTo(nameof(MainView),nameof(JobsView));
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="viewPath">The view path.</param>
public void NavigateTo<T>(params String[] viewPath) where T : IPPCModule
{
NavigateTo(typeof(T), viewPath);
}
/// <summary>
/// Navigates to the specified module using the view path (e.g MainView,JobsView).
/// This method makes it easy to do stuff like NavigateTo(nameof(MainView),nameof(JobsView));
/// </summary>
/// <param name="viewPath">The view path.</param>
private void NavigateTo(Type moduleType, params String[] viewPath)
{
MainView.Instance.NavigationControl.NavigateTo(NavigationView.LayoutView.ToString());
var navigationControl = LayoutView.Instance.NavigationControl;
var module = _moduleLoader.UserModules.SingleOrDefault(x => x.GetType() == moduleType);
var moduleView = navigationControl.NavigateTo(module.Name);
var moduleNavigation = moduleView.FindChildOffline<NavigationControl>();
moduleNavigation.RegisterForLoadedOrNow(async (x, e) =>
{
foreach (var view in viewPath)
{
await Task.Delay(100);
var v = moduleNavigation.NavigateTo(view);
if (view != viewPath.Last())
{
moduleNavigation = v.FindChildOffline<NavigationControl>();
}
}
});
}
}
}
|