aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-11-27 19:10:18 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-11-27 19:10:18 +0200
commit3f22291740c0ac631a655495f6198dbf18be2de2 (patch)
tree3a5106dfc6258b5a30dce8e26f78a65b0b7a87d3 /Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation
parentca29510e1e336c4d68aaa926cfea6eb72ce42779 (diff)
downloadTango-3f22291740c0ac631a655495f6198dbf18be2de2.tar.gz
Tango-3f22291740c0ac631a655495f6198dbf18be2de2.zip
A lot of work !!!
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs190
1 files changed, 107 insertions, 83 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 8914d55a5..4c36c3cbe 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs
@@ -24,8 +24,16 @@ namespace Tango.PPC.UI.Navigation
/// <seealso cref="Tango.PPC.Common.Navigation.INavigationManager" />
public class DefaultNavigationManager : ExtendedObject, INavigationManager
{
- private event Action<Object, Object> NavigationCycleCompleted;
+ //private event Action<Object, Object> NavigationCycleCompleted;
+ //private event Action<Object, Object> BeforeNavigationCycleCompleted;
+ private class AwaitingVMResult
+ {
+ public PPCViewModel FromVM { get; set; }
+ public PPCViewModel ToVM { get; set; }
+ public Action Action { get; set; }
+ }
+ private List<AwaitingVMResult> _awaitingVMResults;
private IDispatcherProvider _dispatcherProvider;
private IPPCModuleLoader _moduleLoader;
private Object _currentVM;
@@ -69,6 +77,8 @@ namespace Tango.PPC.UI.Navigation
/// <param name="moduleLoader">The module loader.</param>
public DefaultNavigationManager(IPPCModuleLoader moduleLoader, IDispatcherProvider dispatcherProvider)
{
+ IsBackEnabled = true;
+ _awaitingVMResults = new List<AwaitingVMResult>();
_navigationHistory = new Stack<String>();
_moduleLoader = moduleLoader;
@@ -118,21 +128,12 @@ namespace Tango.PPC.UI.Navigation
FrameworkElement toView = null;
toView = MainView.Instance.NavigationControl.NavigateTo(view.ToString(), () =>
- {
- var fromVM = toView.DataContext as PPCViewModel;
-
- if (fromVM != null)
- {
- fromVM.OnNavigatedFrom();
- }
+ {
+ NotifyOnNavigated(fromView.DataContext, toView.DataContext);
- var toVM = toView.DataContext as PPCViewModel;
+ });
- if (toVM != null)
- {
- toVM.OnNavigatedTo();
- }
- });
+ NotifyOnBeforeNavigated(fromView.DataContext, toView.DataContext);
return Task.FromResult(true);
}
@@ -193,7 +194,7 @@ namespace Tango.PPC.UI.Navigation
/// Navigates to the specified module and view by full path (e.g Jobs.JobsView).
/// </summary>
/// <param name="fullPath">The full path.</param>
- public async Task<bool> NavigateTo(String fullPath, bool pushToHistory = true)
+ public async Task<bool> NavigateTo(String fullPath, bool pushToHistory = true, Action<PPCViewModel, PPCViewModel> onNavigating = null, Action<PPCViewModel, PPCViewModel> onNavigated = null)
{
String[] path = fullPath.Split('.');
var module = _moduleLoader.UserModules.SingleOrDefault(x => x.GetType().Name == path[0] || x.Name == path[0]);
@@ -247,6 +248,13 @@ namespace Tango.PPC.UI.Navigation
{
moduleNavigation.RegisterForLoadedOrNow(async (x, e) =>
{
+ var lastView = moduleNavigation.GetElement(path.Last());
+
+ if (lastView != null)
+ {
+ onNavigating?.Invoke(fromVM as PPCViewModel, lastView.DataContext as PPCViewModel);
+ }
+
foreach (var view in path.Skip(1))
{
await Task.Delay(100);
@@ -257,16 +265,14 @@ namespace Tango.PPC.UI.Navigation
{
if (v != null)
{
- var toVM = v.DataContext as PPCViewModel;
-
- if (toVM != null)
- {
- (fromVM as PPCViewModel)?.OnNavigatedFrom();
- (toVM as PPCViewModel)?.OnNavigatedTo();
- }
+ NotifyOnNavigated(fromVM, v.DataContext);
+ onNavigated?.Invoke(fromVM as PPCViewModel, v.DataContext as PPCViewModel);
+ NotifyAwaitingVMResults(fromVM as PPCViewModel, v.DataContext as PPCViewModel);
}
});
+ NotifyOnBeforeNavigated(fromVM, v.DataContext);
+
if (v != null)
{
_currentVM = v.DataContext;
@@ -281,40 +287,34 @@ namespace Tango.PPC.UI.Navigation
throw LogManager.Log(new ArgumentNullException("Could not navigate to " + fullPath));
}
}
-
- NavigationCycleCompleted?.Invoke(fromVM, _currentVM);
});
}
else
{
- await Task.Delay(navigationControl.TransitionDuration.TimeSpan);
+ onNavigating?.Invoke(fromVM as PPCViewModel, _currentVM as PPCViewModel);
- if (fromVM is PPCViewModel)
- {
- (fromVM as PPCViewModel)?.OnNavigatedFrom();
- }
+ NotifyOnBeforeNavigated(fromVM, _currentVM);
- if (_currentVM is PPCViewModel)
- {
- (_currentVM as PPCViewModel)?.OnNavigatedTo();
- }
+ await Task.Delay(navigationControl.TransitionDuration.TimeSpan);
- NavigationCycleCompleted?.Invoke(fromVM, _currentVM);
+ NotifyOnNavigated(fromVM, _currentVM);
+
+ onNavigated?.Invoke(fromVM as PPCViewModel, _currentVM as PPCViewModel);
+ NotifyAwaitingVMResults(fromVM as PPCViewModel, _currentVM as PPCViewModel);
}
}
else
{
+ NotifyOnBeforeNavigated(fromVM, _currentVM);
+
+ onNavigating?.Invoke(fromVM as PPCViewModel, _currentVM as PPCViewModel);
+
await Task.Delay(navigationControl.TransitionDuration.TimeSpan);
- if (fromVM is PPCViewModel)
- {
- (fromVM as PPCViewModel)?.OnNavigatedFrom();
- }
+ NotifyOnNavigated(fromVM, _currentVM);
- if (_currentVM is PPCViewModel)
- {
- (_currentVM as PPCViewModel)?.OnNavigatedTo();
- }
+ onNavigated?.Invoke(fromVM as PPCViewModel, _currentVM as PPCViewModel);
+ NotifyAwaitingVMResults(fromVM as PPCViewModel, _currentVM as PPCViewModel);
}
return true;
@@ -330,46 +330,35 @@ namespace Tango.PPC.UI.Navigation
/// <param name="obj">The object.</param>
/// <param name="pushToHistory">if set to <c>true</c> [push to history].</param>
/// <returns></returns>
- public Task<TResult> NavigateForResult<TModule, TView, TResult, TObject>(TObject obj, bool pushToHistory = true)
+ public async Task<TResult> NavigateForResult<TModule, TView, TResult, TObject>(TObject obj, bool pushToHistory = true)
where TModule : IPPCModule
{
TaskCompletionSource<TResult> source = new TaskCompletionSource<TResult>();
var fromVM = _currentVM;
- Object toVM = null;
-
- Action<Object, Object> handler = null;
-
- handler = (from, to) =>
+ await NavigateTo(typeof(TModule).Name + "." + typeof(TView).Name, pushToHistory, (from, to) =>
{
- if (toVM == null)
- {
- toVM = to;
- if (toVM is INavigationResultProvider<TResult, TObject>)
- {
- (toVM as INavigationResultProvider<TResult, TObject>).OnNavigationObjectReceived(obj);
- }
- }
- else
+ _awaitingVMResults.Add(new AwaitingVMResult()
{
- if (to == fromVM && from == toVM)
+ FromVM = fromVM as PPCViewModel,
+ ToVM = to as PPCViewModel,
+ Action = () =>
{
- if (from is INavigationResultProvider<TResult, TObject>)
+ if (to is INavigationResultProvider<TResult, TObject>)
{
- source.SetResult((from as INavigationResultProvider<TResult, TObject>).GetNavigationResult());
+ source.SetResult((to as INavigationResultProvider<TResult, TObject>).GetNavigationResult());
}
}
+ });
- NavigationCycleCompleted -= handler;
+ if (to is INavigationResultProvider<TResult, TObject>)
+ {
+ (to as INavigationResultProvider<TResult, TObject>).OnNavigationObjectReceived(obj);
}
- };
-
- NavigationCycleCompleted += handler;
+ });
- NavigateTo<TModule>(typeof(TView).Name, pushToHistory);
-
- return source.Task;
+ return await source.Task;
}
/// <summary>
@@ -383,25 +372,13 @@ namespace Tango.PPC.UI.Navigation
/// <returns></returns>
public Task<bool> NavigateWithObject<TModule, TView, TPass>(TPass obj, bool pushToHistory = true) where TModule : IPPCModule
{
- TaskCompletionSource<bool> source = new TaskCompletionSource<bool>();
-
- Action<Object, Object> handler = null;
-
- handler = (from, to) =>
+ return NavigateTo(typeof(TModule).Name + "." + typeof(TView).Name, pushToHistory, (fromVM, toVM) =>
{
- if (to is INavigationObjectReceiver<TPass>)
+ if (toVM is INavigationObjectReceiver<TPass>)
{
- (to as INavigationObjectReceiver<TPass>).OnNavigatedToWithObject(obj);
+ (toVM as INavigationObjectReceiver<TPass>).OnNavigatedToWithObject(obj);
}
-
- NavigationCycleCompleted -= handler;
- };
-
- NavigationCycleCompleted += handler;
-
- NavigateTo<TModule>(typeof(TView).Name, pushToHistory);
-
- return source.Task;
+ });
}
private Task<bool> NavigateTo(Type moduleType, bool pushToHistory = true, params String[] viewPath)
@@ -424,6 +401,16 @@ namespace Tango.PPC.UI.Navigation
get { return _navigationHistory.Count > 0; }
}
+ private bool _isBackEnabled;
+ /// <summary>
+ /// Gets a value indicating whether the back should be enabled.
+ /// </summary>
+ public bool IsBackEnabled
+ {
+ get { return _isBackEnabled; }
+ set { _isBackEnabled = value; RaisePropertyChangedAuto(); }
+ }
+
/// <summary>
/// Navigates to the previous view if <see cref="P:Tango.PPC.Common.Navigation.INavigationManager.CanNavigateBack" /> is true.
/// </summary>
@@ -493,5 +480,42 @@ namespace Tango.PPC.UI.Navigation
RaisePropertyChanged(nameof(CanNavigateBack));
}
+
+ private void NotifyOnBeforeNavigated(object fromVM, object toVM)
+ {
+ if (fromVM is PPCViewModel)
+ {
+ (fromVM as PPCViewModel)?.OnBeforeNavigatedFrom();
+ }
+
+ if (toVM is PPCViewModel)
+ {
+ (toVM as PPCViewModel)?.OnBeforeNavigatedTo();
+ }
+ }
+
+ private void NotifyOnNavigated(object fromVM, object toVM)
+ {
+ if (fromVM is PPCViewModel)
+ {
+ (fromVM as PPCViewModel)?.OnNavigatedFrom();
+ }
+
+ if (toVM is PPCViewModel)
+ {
+ (toVM as PPCViewModel)?.OnNavigatedTo();
+ (toVM as PPCViewModel)?.OnNavigatedTo(fromVM as PPCViewModel);
+ }
+ }
+
+ private void NotifyAwaitingVMResults(PPCViewModel fromVM, PPCViewModel toVM)
+ {
+ var awaiter = _awaitingVMResults.SingleOrDefault(x => x.FromVM == toVM && x.ToVM == fromVM);
+ if (awaiter != null)
+ {
+ _awaitingVMResults.Remove(awaiter);
+ awaiter.Action();
+ }
+ }
}
}