aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-06-14 19:23:02 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-06-14 19:23:02 +0300
commit5224c29724a65ba10901053b23840d299826a6a8 (patch)
treedcdc2ff1a6384c7d816b1ab9055bf7c7d948e039 /Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation
parent61a68af94273563e1179b49062ac96b8a627a72a (diff)
downloadTango-5224c29724a65ba10901053b23840d299826a6a8.tar.gz
Tango-5224c29724a65ba10901053b23840d299826a6a8.zip
Working on PPC navigation history!
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs155
1 files changed, 116 insertions, 39 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs
index ae1d29bc2..2213011bf 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs
@@ -6,6 +6,8 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
+using Tango.Core;
+using Tango.Core.Commands;
using Tango.PPC.Common;
using Tango.PPC.Common.Modules;
using Tango.PPC.Common.Navigation;
@@ -18,9 +20,23 @@ namespace Tango.PPC.UI.Navigation
/// Represents the default PPC navigation manager.
/// </summary>
/// <seealso cref="Tango.PPC.Common.Navigation.INavigationManager" />
- public class DefaultNavigationManager : INavigationManager
+ public class DefaultNavigationManager : ExtendedObject, INavigationManager
{
private IPPCModuleLoader _moduleLoader;
+ private Object _currentVM;
+ private IPPCModule _currentModule;
+
+ private Stack<String> _navigationHistory;
+
+ /// <summary>
+ /// Navigates to the previous view.
+ /// </summary>
+ public RelayCommand NavigateBackCommand { get; private set; }
+
+ /// <summary>
+ /// Navigates to the specified full path in command parameter.
+ /// </summary>
+ public RelayCommand<String> NavigateToCommand { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="DefaultNavigationManager"/> class.
@@ -28,30 +44,39 @@ namespace Tango.PPC.UI.Navigation
/// <param name="moduleLoader">The module loader.</param>
public DefaultNavigationManager(IPPCModuleLoader moduleLoader)
{
+ _navigationHistory = new Stack<String>();
_moduleLoader = moduleLoader;
+
+ NavigateToCommand = new RelayCommand<string>(async (x) => await NavigateTo(x));
+ NavigateBackCommand = new RelayCommand(async () => await NavigateBack());
}
/// <summary>
/// Navigates to the specified PPC view.
/// </summary>
/// <param name="view">The view.</param>
- public void NavigateTo(NavigationView view)
+ public Task<bool> NavigateTo(NavigationView view)
{
if (view == NavigationView.HomeModule)
{
- MainView.Instance.NavigationControl.NavigateTo(NavigationView.LayoutView.ToString());
+ _navigationHistory.Clear();
+
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);
+ return NavigateTo(firstModule.GetType(), moduleAtt.HomeViewName);
+ }
+ else
+ {
+ return NavigateTo(firstModule.GetType());
}
}
else
{
MainView.Instance.NavigationControl.NavigateTo(view.ToString());
+ return Task.FromResult(true);
}
}
@@ -59,22 +84,9 @@ namespace Tango.PPC.UI.Navigation
/// Navigates to the specified module.
/// </summary>
/// <typeparam name="T"></typeparam>
- public void NavigateTo<T>() where T : IPPCModule
+ public Task<bool> 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);
+ return NavigateTo(typeof(T));
}
/// <summary>
@@ -82,9 +94,9 @@ namespace Tango.PPC.UI.Navigation
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="viewPath">The view path.</param>
- public void NavigateTo<T>(string viewPath) where T : IPPCModule
+ public Task<bool> NavigateTo<T>(string viewPath) where T : IPPCModule
{
- NavigateTo<T>(viewPath.Split(','));
+ return NavigateTo<T>(viewPath.Split('.'));
}
/// <summary>
@@ -93,38 +105,103 @@ namespace Tango.PPC.UI.Navigation
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="viewPath">The view path.</param>
- public void NavigateTo<T>(params String[] viewPath) where T : IPPCModule
+ public Task<bool> NavigateTo<T>(params String[] viewPath) where T : IPPCModule
{
- NavigateTo(typeof(T), viewPath);
+ return 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));
+ /// Navigates to the specified module and view by full path (e.g Jobs.JobsView).
/// </summary>
- /// <param name="viewPath">The view path.</param>
- private void NavigateTo(Type moduleType, params String[] viewPath)
+ /// <param name="fullPath">The full path.</param>
+ public async Task<bool> NavigateTo(String fullPath)
{
+ String[] path = fullPath.Split('.');
+ var module = _moduleLoader.UserModules.SingleOrDefault(x => x.GetType().Name == path[0] || x.Name == path[0]);
+
+ if (path.Length == 1 && path[0] == _currentModule.Name) return true;
+
+ if (_currentVM != null && _currentVM is INavigationBlocker)
+ {
+ if (!await (_currentVM as INavigationBlocker).OnNavigateOutRequest())
+ {
+ return false;
+ }
+ }
+
+ _navigationHistory.Push(fullPath);
+ RaisePropertyChanged(nameof(CanNavigateBack));
+
MainView.Instance.NavigationControl.NavigateTo(NavigationView.LayoutView.ToString());
var navigationControl = LayoutView.Instance.NavigationControl;
- var module = _moduleLoader.UserModules.SingleOrDefault(x => x.GetType() == moduleType);
+ _currentModule = module;
var moduleView = navigationControl.NavigateTo(module.Name);
- var moduleNavigation = moduleView.FindChildOffline<NavigationControl>();
+ _currentVM = moduleView.DataContext;
- moduleNavigation.RegisterForLoadedOrNow(async (x, e) =>
+ if (path.Length > 1)
{
- foreach (var view in viewPath)
- {
- await Task.Delay(100);
- var v = moduleNavigation.NavigateTo(view);
+ var moduleNavigation = moduleView.FindChildOffline<NavigationControl>();
- if (view != viewPath.Last())
+ moduleNavigation.RegisterForLoadedOrNow(async (x, e) =>
+ {
+ foreach (var view in path.Skip(1))
{
- moduleNavigation = v.FindChildOffline<NavigationControl>();
+ await Task.Delay(100);
+ var v = moduleNavigation.NavigateTo(view);
+
+ _currentVM = v.DataContext;
+
+ if (view != path.Last())
+ {
+ moduleNavigation = v.FindChildOffline<NavigationControl>();
+ }
}
- }
- });
+ });
+ }
+
+ return true;
+ }
+
+ private Task<bool> NavigateTo(Type moduleType, params String[] viewPath)
+ {
+ if (viewPath != null && viewPath.Length > 0)
+ {
+ return NavigateTo(moduleType.Name + "." + String.Join(".", viewPath));
+ }
+ else
+ {
+ return NavigateTo(moduleType.Name);
+ }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether the navigation system is able to navigate to the previous view.
+ /// </summary>
+ public bool CanNavigateBack
+ {
+ get { return _navigationHistory.Count > 1; }
+ }
+
+ /// <summary>
+ /// Navigates to the previous view if <see cref="P:Tango.PPC.Common.Navigation.INavigationManager.CanNavigateBack" /> is true.
+ /// </summary>
+ /// <exception cref="NotImplementedException"></exception>
+ public async Task<bool> NavigateBack()
+ {
+ String first = _navigationHistory.Pop();
+ String second = _navigationHistory.Pop();
+
+ if (await NavigateTo(second))
+ {
+ return true;
+ }
+ else
+ {
+ _navigationHistory.Push(second);
+ _navigationHistory.Push(first);
+ return false;
+ }
}
}
}