aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2018-11-25 10:44:37 +0200
committerShlomo Hecht <shlomo@twine-s.com>2018-11-25 10:44:37 +0200
commitbeff6af103bb0ae9b9147a907c6567bdb33abd00 (patch)
tree375eefd654c25f3b68c0cf5b3612df844a140d8e /Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels
parent57f20269fbb4c591aa73c9f5e50118310cc4892e (diff)
parentdff24e56a8906b8c9b355cf407f25f4b793beafe (diff)
downloadTango-beff6af103bb0ae9b9147a907c6567bdb33abd00.tar.gz
Tango-beff6af103bb0ae9b9147a907c6567bdb33abd00.zip
merge
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels')
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels/MainViewVM.cs135
1 files changed, 135 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels/MainViewVM.cs
new file mode 100644
index 000000000..cb48958dd
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels/MainViewVM.cs
@@ -0,0 +1,135 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core.Commands;
+using Tango.Explorer;
+using Tango.PPC.Common;
+using Tango.PPC.Common.Navigation;
+using Tango.PPC.Storage.TaskBarItems;
+using Tango.PPC.Storage.ViewContracts;
+
+namespace Tango.PPC.Storage.ViewModels
+{
+ /// <summary>
+ /// Represents the main view VM and entry point for <see cref="Storage.StorageModule"/>.
+ /// </summary>
+ /// <seealso cref="Tango.PPC.Common.PPCViewModel" />
+ public class MainViewVM : PPCViewModel<IMainView>, INavigationResultProvider<ExplorerFileItem, String>
+ {
+ private bool _allow_exit;
+ private ExplorerFileItem _selectedItem;
+
+ private String _currentPath;
+ public String CurrentPath
+ {
+ get { return _currentPath; }
+ set { _currentPath = value; RaisePropertyChangedAuto(); }
+ }
+
+ public RelayCommand CloseCommand { get; set; }
+
+ public RelayCommand<ExplorerFileItem> FileSelectedCommand { get; set; }
+
+ public MainViewVM()
+ {
+ CloseCommand = new RelayCommand(Close);
+ FileSelectedCommand = new RelayCommand<ExplorerFileItem>(OnFileSelected);
+ }
+
+ public override void OnApplicationStarted()
+ {
+
+ }
+
+ public override void OnApplicationReady()
+ {
+ base.OnApplicationReady();
+
+ NotificationProvider.PushTaskBarItem<StorageTaskBarItem>();
+ StorageProvider.StorageConnected += StorageProvider_StorageConnected;
+ StorageProvider.StorageDisconnected += StorageProvider_StorageDisconnected;
+ }
+
+ public override void OnNavigatedTo()
+ {
+ base.OnNavigatedTo();
+
+ _allow_exit = false;
+ _selectedItem = null;
+
+ if (StorageProvider.Drive != null)
+ {
+ CurrentPath = StorageProvider.Drive.RootDirectory.FullName;
+ }
+ }
+
+ private async void Close()
+ {
+ await NavigationManager.NavigateBack();
+ }
+
+ /// <summary>
+ /// Handles the storage connected event.
+ /// </summary>
+ /// <param name="sender">The sender.</param>
+ /// <param name="e">The drive info.</param>
+ private void StorageProvider_StorageConnected(object sender, System.IO.DriveInfo e)
+ {
+ InvokeUI(async () =>
+ {
+ if (await NotificationProvider.ShowQuestion("Disk Inserted. Do you want to browse?"))
+ {
+ await NavigationManager.NavigateTo(Common.Navigation.NavigationView.StorageView);
+ }
+ });
+ }
+
+ /// <summary>
+ /// Handles the storage disconnected event.
+ /// </summary>
+ /// <param name="sender">The sender.</param>
+ /// <param name="e">The drive info.</param>
+ private void StorageProvider_StorageDisconnected(object sender, System.IO.DriveInfo e)
+ {
+ InvokeUI(async () =>
+ {
+ if (IsVisible)
+ {
+ await NavigationManager.NavigateBack();
+ }
+ });
+ }
+
+ public override Task<bool> OnNavigateBackRequest()
+ {
+ if (CurrentPath == StorageProvider.Drive.RootDirectory.FullName || _allow_exit)
+ {
+ return Task.FromResult(true);
+ }
+ else
+ {
+ View.NavigateBack();
+ return Task.FromResult(false);
+ }
+ }
+
+ private async void OnFileSelected(ExplorerFileItem fileItem)
+ {
+ _allow_exit = true;
+ await NavigationManager.NavigateBack();
+ await NotificationProvider.ShowInfo($"File Selected: {fileItem.Name}");
+ }
+
+ public ExplorerFileItem GetNavigationResult()
+ {
+ return _selectedItem;
+ }
+
+ public void OnNavigationObjectReceived(string extension)
+ {
+
+ }
+ }
+}