| ofs | hex dump | ascii |
|---|
| 0000 | 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 01 f4 00 00 01 ca 08 06 00 00 00 f5 a6 b9 | .PNG........IHDR................ |
| 0020 | 57 00 00 00 01 73 52 47 42 00 ae ce 1c e9 00 00 00 04 67 41 4d 41 00 00 b1 8f 0b fc 61 05 00 00 | W....sRGB.........gAMA......a... |
| 0040 | 00 09 70 48 59 73 00 00 0b 12 00 00 0b 12 01 d2 dd 7e fc 00 00 00 18 74 45 58 74 53 6f 66 74 77 | ..pHYs...........~.....tEXtSoftw |
| 0060 | 61 72 65 00 70 61 69 6e 74 2e 6e 65 74 20 34 2e 30 2e 39 6c 33 7e 4e 00 00 78 14 49 44 41 54 78 | are.paint.net.4.0.9l3~N..x.IDATx |
| 0080 | 5e ed 9d 07 78 54 d7 99 fe 97 b8 c5 2d 8e 63 3b c5 ce 3a 3d eb d4 4d b2 c9 3f 9b 9e 4d 36 c9 6e | ^...xT......-.c;..:=..M..?..M6.n |
| 00a0 | 7a 31 d9 6c d6 0d 02 02 44 ef cd 20 4c 35 45 06 21 69 14 15 8c 2d 8c 6d 64 0c 18 1b 17 30 c6 a6 | z1.l....D...L5E.!i...-.md....0.. |
| 00c0 | d9 c6 60 03 a6 9b 6a 90 a9 42 12 ea 75 fe ef 7b 39 97 8c af 8f ca 48 23 cd bd d2 fb 7b 9e f7 b9 | ..`...j..B..u..{9.....H#....{... |
| 00e0 | 23 69 34 73 cf 2d df 7b be 73 4f f9 27 21 5a c3 f2 e5 cb 6f 79 e4 91 47 fe 9e 91 91 b1 1d 5a 98 | #i4s.-.{.sO.'!Z....oy..G......Z. |
| 0100 | 92 92 72 83 f9 93 10 42 08 21 fc 4e 5e 5e de 45 1b 37 6e 1c 5e 5c 5c 5c 79 ea d4 a9 f0 df ff fe | ..r....B.!.N^^.E.7n.^\\\y....... |
| 0120 | 77 47 30 f5 0d 49 49 49 ef 33 6f 13 42 08 21 84 5f c9 cc cc bc 7e f7 ee dd cf d7 d5 d5 85 5d 1e | wG0..III.3o.B.!._....~........]. |
| 0140 | 7b ec b1 0b a6 9e 9e 9e 7e 9b 79 ab 10 42 08 21 fc 08 8c fb 4b c7 8e 1d 3b 64 7c fc 02 8b 16 2d | {.......~.y..B.!....K...;d|....- |
| 0160 | ba 60 e8 d0 1e 65 e9 42 08 21 84 4f 59 b9 72 e5 37 0b 0a 0a ce 18 0f bf 00 7e 17 69 e6 8e 32 32 | .`...e.B.!.OY.r.7........~.i..22 |
| 0180 | 32 fe 60 fe 4d 08 21 84 10 7e 61 ed da b5 5f 2d 2e 2e 2e 32 1e 7e 81 fa fa fa f0 f2 e5 cb 6d 86 | 2.`.M.!..~a..._-...2.~........m. |
| 01a0 | be 01 ff d6 e5 fc 7f 0b 21 84 10 22 ee c0 b0 6f 3e 7b f6 6c be f1 f0 77 b1 71 e3 c6 f7 98 79 84 | ........!.."...o>{.l...w.q....y. |
| 01c0 | be 63 3e 42 08 21 84 10 f1 64 fe fc f9 ef cf cf cf 7f cd f8 f7 bb d8 ba 75 ab cd c4 23 b5 cc 7c | .c>B.!...d..............u...#..| |
| 01e0 | 8c 10 42 08 21 e2 48 97 3d 7b f6 a4 1a ff 7e 17 af be fa aa cd c0 bd aa 49 4b 4b fb ac f9 2c 21 | ..B.!.H.={....~.........IKK...,! |
| 0200 | 84 10 42 c4 83 0d 1b 36 fc b0 aa aa ea 1f 63 d3 00 9f 99 af 5d bb d6 66 de 0d 29 cb 7c 9c 10 42 | ..B....6......c.....]..f..).|..B |
| 0220 | 08 21 da 1b 36 b5 17 14 14 ec 31 3e 7e 81 f5 eb d7 db 4c bb 41 65 64 64 94 72 dc ba f9 58 21 84 | .!..6.....1>~.....L.Aedd.r...X!. |
| 0240 | 10 42 b4 27 7b f6 ec e9 6b 3c fc 02 db b7 6f b7 9a 76 53 0a 85 42 93 cd c7 0a 21 84 10 a2 bd 58 | .B.'{...k<....o..vS..B....!....X |
| 0260 | b6 6c d9 d5 c5 c5 c5 27 8d 8f 3b 9c 3c 79 32 8c 4c db 6a d8 cd d0 c9 e4 e4 e4 cb cd c7 0b 21 84 | .l.....'..;.<y2.L.j...........!. |
| 0280 | 10 a2 3d d8 bf 7f 7f 1f e3 e3 0e 35 35 35 e1 87 1f 7e d8 66 d4 cd 16 2a 03 fd cc c7 0b 21 84 10 | ..=........555...~.f...*.....!.. |
| 02a0 | a2 ad 81 f1 5e 52 58 58 b8 cf 78 b9 c3 a6 4d 9b ac 26 1d a5 f6 71 41 17 f3 35 42 08 21 84 68 4b | ....^RXX..x...M..&...qA..5B.!.hK |
| 02c0 | 76 ee dc f9 03 f6 64 77 29 2d 2d 0d e7 e4 e4 d8 0c 3a 6a 65 64 64 fc d9 7c 8d 10 42 08 21 da 92 | v.....dw)--......:jedd..|..B.!.. |
| 02e0 | 93 27 4f e6 18 2f 77 88 72 88 5a 53 da ac 45 5b 84 10 42 88 36 66 d1 a2 45 97 97 97 97 17 18 2f | .'O../w.r.ZS..E[..B.6f..E....../ |
| 0300 | 0f e3 75 cc b2 73 57 a1 50 e8 3f cd d7 09 21 84 10 a2 2d 78 eb ad b7 be 6b bc dc 61 db b6 6d 56 | ..u..sW.P.?...!...-x....k..a..mV |
| 0320 | 53 6e 8d 32 32 32 5e c0 47 6b d1 16 21 84 10 a2 ad 38 7d fa f4 3d e7 ad fc fc 8c 70 8f 3c f2 88 | Sn.222^.Gk..!....8}..=.....p.<.. |
| 0340 | d5 94 5b a9 3a 64 e9 ff 66 be 52 08 21 84 10 b1 a6 a4 a4 64 a3 f1 f3 f0 d9 b3 67 6d 66 1c 2b 2d | ..[.:d..f.R.!......d......gmf.+- |
| 0360 | 31 5f 29 84 10 42 88 58 f2 dc 73 cf 5d 59 5d 5d 7d ce f8 79 78 cb 96 2d 36 23 8e 89 32 32 32 aa | 1_)..B.X..s.]Y]]}..yx..-6#..222. |
| 0380 | b3 b3 b3 b5 68 8b 10 42 08 11 6b b6 6f df 7e 8b f1 72 87 25 4b 96 58 cd 38 56 ca cc cc bc df 7c | ....h..B..k.o.~..r.%K.X.8V.....| |
| 03a0 | b5 10 42 08 21 62 c5 b9 73 e7 fe 64 bc 3c 8c 4c 3d 8c 0c da 6a c4 b1 12 b2 f4 b2 f9 f3 e7 7f d4 | ..B.!b..s..d.<.L=...j........... |
| 03c0 | 7c bd 10 a2 1d 48 49 49 b9 0c 95 f5 eb b6 6e dd fa a9 0d 1b 36 7c 6b ed da b5 df 7b e1 85 17 7e | |....HII......n.....6|k....{...~ |
| 03e0 | 64 5e 7f 7e e1 c2 85 d7 f3 3d e6 ed 42 88 20 72 e6 cc 99 71 c6 cf c3 27 4e 9c b0 9a 70 ac 15 0a | d^.~.....=..B..r...q...'N...p... |
| 0400 | 85 ee 33 5f 2f 84 88 31 9c 99 f1 8d 37 de f8 24 ee e7 bf 9e 3a 75 2a 0d f7 f8 a6 ca ca ca 02 a8 | ..3_/..1....7..$....:u*......... |
| 0420 | ba ae ee 5d ab 22 3b 70 8a e7 f2 f2 f2 9a c2 c2 c2 82 a3 47 8f 6e da bb 77 ef f4 e7 9f 7f fe 37 | ...].";p...........G.n..w......7 |
| 0440 | a8 78 7f d0 7c a4 10 22 08 e0 26 cf 32 f7 75 78 e7 ce 9d 56 03 6e 03 9d cd cc cc bc c6 ec 82 10 | .x..|.."..&.2.ux...V.n.......... |
| 0460 | a2 95 ec d8 b1 e3 d2 03 07 0e 7c bf a8 a8 28 b9 ac ac ec 50 6d 6d ed 7b 9d 3b 0a 38 da a5 b8 b8 | ..........|...(....Pmm.{.;.8.... |
| 0480 | b8 ec ad b7 de 5a b1 6a d5 aa df 71 59 65 f3 55 42 08 bf 52 52 52 f2 92 b9 87 a3 5e f3 bc 95 4a | .....Z.j...qYe.UB..RRR.....^...J |
| 04a0 | 32 bb 20 84 68 19 5d 60 b8 9f 85 f1 4e ad aa aa ca 37 b7 71 cc 61 56 9f 0f 10 1f 06 a7 a5 a5 5d | 2...h.]`....N....7.q.aV........] |
| 04c0 | 65 be 5b 08 e1 37 50 93 3f 64 ee db f0 b2 65 cb 6c c6 db 56 3a 99 9b 9b 7b a5 d9 0d 21 44 33 c1 | e.[..7P.?d....e.l..V:...{...!D3. |
| 04e0 | ad 7a d1 e9 d3 a7 7f 5a 59 59 f9 1c cc b6 e6 fc dd 6b 87 66 8c f7 85 cf 9d 3b e7 3c 52 3b 7a f4 | .z.....ZYY.......k.f.....;.<R;z. |
| 0500 | a8 23 fc 7f 18 99 bc d3 6f 26 1a 4e 9d 3a 75 e2 f9 e7 9f bf d5 ec 8a 10 c2 2f 74 ed da f5 22 18 | .#......o&.N.:u........../t...". |
| 0520 | fa 09 73 af 86 17 2e 5c 68 33 de 36 53 46 46 c6 30 b3 2b 42 88 26 58 b3 66 cd c5 67 cf 9e fd 1d | ..s....\h3.6SFF.0.+B.&X.f..g.... |
| 0540 | 0c 7a b3 b9 65 df 03 a7 6d 3e 70 e0 40 78 e3 c6 8d e1 c7 1f 7f 3c fc e0 83 0f 72 64 89 f5 fe a3 | .z..e...m>p.@x.......<....rd.... |
| 0560 | d8 09 96 4b 24 e3 b3 c3 fb f6 ed 0b 57 54 54 98 4f b2 c3 e7 ed 0b 16 2c a8 c5 67 fe c9 ec 96 10 | ...K$.......WTT.O......,..g..... |
| 0580 | c2 0f 2c 5f be fc 0a dc a0 45 bc 51 61 ec e1 07 1e 78 c0 7a d3 b7 95 60 e8 47 f5 6c 4e 88 c6 e1 | ..,_.....E.Qa....x.z...`.G.lN... |
| 05a0 | c2 46 85 85 85 3f c1 bd 6a 35 f2 e2 e2 e2 f0 d6 ad 5b c3 8b 17 2f 6e d4 bc 9b a3 ac ac ac f0 8a | .F...?..j5.......[.../n......... |
| 05c0 | 15 2b c2 7b f7 ee 75 3e 97 71 c1 85 66 bf 72 e5 4a f7 bd af 9a dd 13 42 f8 81 43 87 0e 7d 10 37 | .+.{..u>.q..f.r.J......B..C..}.7 |
| 05e0 | ac 53 25 67 b3 5c 6b 83 41 4b 14 0a 85 fa 98 dd 11 42 78 38 77 ee dc 17 aa ab ab 9f 75 1c 35 02 | .S%g.\k.AK.......Bx8w.......u.5. |
| 0600 | 1a 2d 4d 97 8f c9 da f2 be 65 25 ff d1 47 1f 75 e4 19 d2 ba d2 ec a2 10 c2 0f 14 15 15 7d a8 ae | .-M......e%..G.u.............}.. |
| 0620 | ae ae 8a 01 82 86 1e 71 b3 b6 9b 90 a5 ef 47 06 72 a9 d9 25 21 04 38 79 f2 e4 55 55 55 55 33 dd | .......q......G.r..%!.8y..UUUU3. |
| 0640 | fb d3 85 59 32 67 73 64 53 ba ed 7e 6a 27 d5 a3 22 fe 5b b3 ab 42 08 3f 50 5f 5f 7f 9d db a9 86 | ...Y2gsdS..~j'..".[..B.?P__..... |
| 0660 | cf de 2c 37 6e bb 08 19 c6 ed 66 97 84 e8 d4 e0 56 ec 02 d3 fe 2f 64 e0 87 79 5f ba b0 c2 bd 69 | ..,7n.....f.....V..../d..y_....i |
| 0680 | d3 a6 f0 fd f7 df 6f bd 87 da 59 8b cd ee 0a 21 fc 42 71 71 31 0d dd e9 e6 8a 6c dd 76 e3 b6 97 | ......o...Y....!.Bqq1.....l.v... |
| 06a0 | 76 22 4b bf d8 ec 96 10 9d 92 b3 67 cf 5e 53 5d 5d 3d df 71 70 03 9b d6 f9 7c 7c fe fc f9 b6 fb | v"K........g.^S]]=.qp....||..... |
| 06c0 | 26 1e 3a 86 0a f8 f5 66 97 85 10 7e 01 26 7e 2d 0c bd 92 81 23 ce 86 4e fd d1 ec 96 10 9d 8e 9a | &.:....f...~.&~-....#..N........ |
| 06e0 | 9a 9a 1f c3 bc 8f 38 2e 6e e0 f0 32 f6 40 b7 dc 2b f1 52 4d 46 46 c6 8f cd 2e 0b 21 fc c4 99 33 | ......8.n..2.@..+.RMFF.....!...3 |
| 0700 | 67 3e 80 20 52 c6 e0 11 6f 43 47 a0 d8 c2 29 2b cd ae 09 d1 29 c0 ad 77 31 cc fc de fa fa fa 0b | g>..R...oCG...)+....)..w1....... |
| 0720 | 33 bb 71 7c 78 44 6f 72 df 08 99 f9 04 b3 db 42 08 bf 71 e8 d0 a1 f7 c3 d0 cf 32 88 70 e2 09 db | 3.q|xDor.......B..q.......2.p... |
| 0740 | 4d dc 5e 82 a1 d7 63 fb 5f 66 d7 84 e8 f0 a0 42 fd 71 dc 7f 1b 1c 17 37 70 2c b8 8f 9a d7 23 b5 | M.^...c._f.....B.q.....7p,....#. |
| 0760 | 46 15 6e 21 fc 4d 17 64 06 ce 94 91 ec 3d 6b b9 89 db 5b af 70 cc ad d9 37 21 3a 2c c8 ca 7f 56 | F.n!.M.d.....=k...[.p...7!:,...V |
| 0780 | 57 57 77 c6 71 71 c0 fb ef d9 67 9f b5 dd 13 71 17 2a db a7 72 72 72 6e 34 bb 2e 84 f0 2b 30 f4 | WWw.qq....g....q.*..rrrn4....+0. |
| 07a0 | 03 0c 28 f1 1a b6 16 29 66 e9 d0 cf cc ae 09 d1 e1 c0 ad d6 a5 ba ba 7a 54 64 13 7b 7e 7e 7e 38 | ..(....)f..............zTd.{~~~8 |
| 07c0 | 37 37 d7 7a 4f f8 40 75 b8 27 7f 69 76 5f 08 e1 67 6a 6b 6b d7 33 a8 54 55 55 39 b3 44 59 6e e8 | 77.zO.@u.'.iv_..gjkk.3.TUU9.DYn. |
| 07e0 | 76 15 82 c7 46 65 e9 a2 23 f2 f6 db 6f 5f 8e ac 7c a1 e3 e2 00 a6 ee 0c 45 8b c7 84 4e 51 68 a6 | v...Fe..#...o_..|.......E...NQh. |
| 0800 | d9 7d 21 84 df 41 80 c9 61 70 c1 36 de 93 55 b8 aa 0b 85 42 3f 31 bb 27 44 87 a0 ac ac ec 46 54 | .}!..A..ap.6..U....B?1.'D.....FT |
| 0820 | 9e 5f 73 9c 1c b0 45 6c f9 f2 e5 b6 eb df 37 42 e5 fa 15 54 36 2e 31 45 10 42 f8 1d 18 f9 0c 13 | ._s...El......7B...T6.1E.B...... |
| 0840 | 63 7c 33 44 06 81 64 1d 76 a7 8b d9 45 21 02 4d 55 55 d5 57 71 9f 1d 3d 7f 97 85 9d 95 ce 1e 7a | c|3D..d.v...E!.MUU.Wq..=.......z |
| 0860 | e8 21 eb b5 ef 17 e1 1e 2c 9c 3b 77 ee a7 4c 11 84 10 41 00 59 43 4f 13 67 9c c5 1d 6c 37 77 1c | .!......,.;w..L...A.YCO.g...l7w. |
| 0880 | 54 87 cc e0 47 66 17 85 08 2c 15 15 15 3f a9 af af 3f 67 6e b1 f0 5b 6f bd e5 9d 13 dd 8f e2 d4 | T...Gf...,...?...?gusing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.Core.Commands;
using Tango.Core.DI;
using Tango.MachineStudio.Common;
using Tango.MachineStudio.Common.Modules;
using Tango.MachineStudio.Common.Navigation;
using Tango.MachineStudio.Common.Threading;
using Tango.SharedUI.Controls;
namespace Tango.MachineStudio.UI.Navigation
{
/// <summary>
/// Represents the Machine Studio default <see cref="INavigationManager">Navigation Manager</see>.
/// </summary>
/// <seealso cref="Tango.MachineStudio.Common.Navigation.INavigationManager" />
public class DefaultNavigationManager : ExtendedObject, INavigationManager
{
private event Action<Object, Object> NavigationCycleCompleted;
private IDispatcherProvider _dispatcherProvider;
private IStudioModuleLoader _moduleLoader;
private Object _currentVM;
private String _lastFullPath;
private bool _preventHistory;
private bool _navigating_back;
private Stack<String> _navigationHistory;
/// <summary>
/// Gets the current view model.
/// </summary>
public StudioViewModel CurrentVM
{
get { return _currentVM as StudioViewModel; }
}
private IStudioModule _currentModule;
/// <summary>
/// Gets or sets the current module.
/// </summary>
public IStudioModule CurrentModule
{
get { return _currentModule; }
private set { _currentModule = value; RaisePropertyChangedAuto(); }
}
/// <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.
/// </summary>
/// <param name="moduleLoader">The module loader.</param>
public DefaultNavigationManager(IStudioModuleLoader moduleLoader, IDispatcherProvider dispatcherProvider)
{
_navigationHistory = new Stack<String>();
_moduleLoader = moduleLoader;
NavigateToCommand = new RelayCommand<string>(async (x) => await NavigateTo(x));
NavigateBackCommand = new RelayCommand(async () => await NavigateBack());
_dispatcherProvider = dispatcherProvider;
}
/// <summary>
/// Navigates to the specified PPC view.
/// </summary>
/// <param name="view">The view.</param>
public Task<bool> NavigateTo(NavigationView view, bool pushToHistory = true)
{
LogManager.Log($"Navigating to: {view.ToString()}...");
_dispatcherProvider.Invoke(() =>
{
MainWindow.Instance.NavigationControl.NavigateTo(view.ToString());
});
return Task.FromResult(true);
}
/// <summary>
/// Navigates to the specified PPC view with the specified receive object.
/// </summary>
/// <param name="view">The view.</param>
/// <param name="obj"></param>
/// <param name="pushToHistory"></param>
/// <returns></returns>
public Task<bool> NavigateWithObject<TPass>(NavigationView view, TPass obj, bool pushToHistory = true)
{
LogManager.Log($"Navigating to: {view.ToString()}, with object {typeof(TPass).Name}...");
MainWindow.Instance.NavigationControl.NavigateTo(view.ToString());
INavigationObjectReceiver<TPass> receiver = MainWindow.Instance.NavigationControl.Elements.FirstOrDefault(x => (x.GetType().Name == view.ToString() || NavigationControl.GetNavigationName(x) == view.ToString()) && x.DataContext is INavigationObjectReceiver<TPass>).DataContext as INavigationObjectReceiver<TPass>;
if (receiver != null)
{
receiver.OnNavigatedToWithObject(obj);
}
return Task.FromResult(true);
}
/// <summary>
/// Navigates to the specified module.
/// </summary>
/// <typeparam name="T"></typeparam>
public Task<bool> NavigateTo<T>(bool pushToHistory = true) where T : IStudioModule
{
return NavigateTo(typeof(T));
}
/// <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 Task<bool> NavigateTo<T>(string viewPath, bool pushToHistory = true) where T : IStudioModule
{
return NavigateTo<T>(pushToHistory, 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 Task<bool> NavigateTo<T>(bool pushToHistory = true, params String[] viewPath) where T : IStudioModule
{
return NavigateTo(typeof(T), pushToHistory, viewPath);
}
/// <summary>
/// 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)
{
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;
LogManager.Log($"Navigating to: {fullPath}...");
var fromVM = _currentVM;
if (_currentVM != null && _currentVM is INavigationBlocker)
{
if (_navigating_back)
{
if (!await (_currentVM as INavigationBlocker).OnNavigateBackRequest())
{
return false;
}
}
else
{
if (!await (_currentVM as INavigationBlocker).OnNavigateOutRequest())
{
return false;
}
}
}
if (pushToHistory && _lastFullPath != null && !_preventHistory)
{
_navigationHistory.Push(_lastFullPath);
RaisePropertyChanged(nameof(CanNavigateBack));
}
_lastFullPath = fullPath;
MainWindow.Instance.NavigationControl.NavigateTo(NavigationView.MainView.ToString());
var navigationControl = MachineStudio.UI.Views.MainView.Instance.NavigationControl;
CurrentModule = module;
var moduleView = navigationControl.NavigateTo(module.Name);
_currentVM = moduleView.DataContext;
if (path.Length > 1)
{
var moduleNavigation = moduleView.FindChildOffline<NavigationControl>();
moduleNavigation.RegisterForLoadedOrNow(async (x, e) =>
{
foreach (var view in path.Skip(1))
{
await Task.Delay(100);
var v = moduleNavigation.NavigateTo(view);
if (v != null)
{
_currentVM = v.DataContext;
if (view != path.Last())
{
moduleNavigation = v.FindChildOffline<NavigationControl>();
}
}
else
{
throw LogManager.Log(new ArgumentNullException("Could not navigate to " + fullPath));
}
}
NavigationCycleCompleted?.Invoke(fromVM, _currentVM);
});
}
return true;
}
/// <summary>
/// Navigates for result.
/// </summary>
/// <typeparam name="TModule">The type of the module.</typeparam>
/// <typeparam name="TView">The type of the view.</typeparam>
/// <typeparam name="TResult">The type of the result.</typeparam>
/// <typeparam name="TObject">The type of the object.</typeparam>
/// <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)
where TModule : IStudioModule
{
TaskCompletionSource<TResult> source = new TaskCompletionSource<TResult>();
var fromVM = _currentVM;
Object toVM = null;
Action<Object, Object> handler = null;
handler = (from, to) =>
{
if (toVM == null)
{
toVM = to;
if (toVM is INavigationResultProvider<TResult, TObject>)
{
(toVM as INavigationResultProvider<TResult, TObject>).OnNavigationObjectReceived(obj);
}
}
else
{
if (to == fromVM && from == toVM)
{
if (from is INavigationResultProvider<TResult, TObject>)
{
source.SetResult((from as INavigationResultProvider<TResult, TObject>).GetNavigationResult());
}
}
NavigationCycleCompleted -= handler;
}
};
NavigationCycleCompleted += handler;
NavigateTo<TModule>(typeof(TView).Name, pushToHistory);
return source.Task;
}
/// <summary>
/// Navigates to the specified module and view with the specified object.
/// </summary>
/// <typeparam name="TModule">The type of the module.</typeparam>
/// <typeparam name="TView">The type of the view.</typeparam>
/// <typeparam name="TPass">The type of the pass.</typeparam>
/// <param name="obj">The object.</param>
/// <param name="pushToHistory">if set to <c>true</c> [push to history].</param>
/// <returns></returns>
public Task<bool> NavigateWithObject<TModule, TView, TPass>(TPass obj, bool pushToHistory = true) where TModule : IStudioModule
{
TaskCompletionSource<bool> source = new TaskCompletionSource<bool>();
Action<Object, Object> handler = null;
handler = (from, to) =>
{
if (to is INavigationObjectReceiver<TPass>)
{
(to 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)
{
if (viewPath != null && viewPath.Length > 0)
{
return NavigateTo(moduleType.Name + "." + String.Join(".", viewPath), pushToHistory);
}
else
{
return NavigateTo(moduleType.Name, pushToHistory);
}
}
/// <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 > 0; }
}
/// <summary>
/// Navigates to the previous view if <see cref="P:Tango.PPC.Common.Navigation.INavigationManager.CanNavigateBack" /> is true.
/// </summary>
public async Task<bool> NavigateBack()
{
LogManager.Log("Navigating back...");
_navigating_back = true;
String first = _navigationHistory.Pop();
_preventHistory = true;
if (await NavigateTo(first))
{
RaisePropertyChanged(nameof(CanNavigateBack));
_preventHistory = false;
_navigating_back = false;
return true;
}
else
{
_navigationHistory.Push(first);
_preventHistory = false;
_navigating_back = false;
RaisePropertyChanged(nameof(CanNavigateBack));
return false;
}
}
/// <summary>
/// Clears the navigation back history.
/// </summary>
public void ClearHistory()
{
LogManager.Log("Navigation history cleared.");
_navigationHistory.Clear();
RaisePropertyChanged(nameof(CanNavigateBack));
}
/// <summary>
/// Clears the navigation back history except the specified view type.
/// </summary>
/// <typeparam name="T"></typeparam>
public void ClearHistoryExcept<T>()
{
LogManager.Log($"Navigation history cleared except for {typeof(T).Name}.");
var history_list = _navigationHistory.ToList();
history_list = history_list.Where(x => x.Contains(typeof(T).Name)).Distinct().ToList();
_navigationHistory.Clear();
foreach (var item in history_list)
{
_navigationHistory.Push(item);
}
RaisePropertyChanged(nameof(CanNavigateBack));
}
public void NavigateToModule<T>() where T : IStudioModule
{
var loader = TangoIOC.Default.GetInstance<IStudioModuleLoader>();
var module = loader.UserModules.SingleOrDefault(x => x.GetType() == typeof(T));
if (module != null)
{
TangoIOC.Default.GetInstance<ViewModels.MainViewVM>().StartModule(module);
}
}
}
}
|