diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-20 04:03:05 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-20 04:03:05 +0200 |
| commit | d0dba9752d0a8e787d9ae1d4d25542bd4b386df6 (patch) | |
| tree | b71977215c188d65d61fcfb66e982a8363b4d803 /Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs | |
| parent | 7f0b3b209792cb935b9cfca4542c45318a309717 (diff) | |
| download | Tango-d0dba9752d0a8e787d9ae1d4d25542bd4b386df6.tar.gz Tango-d0dba9752d0a8e787d9ae1d4d25542bd4b386df6.zip | |
Implemented priority queues for Transport Layer.
Working on file/folder download.
Diffstat (limited to 'Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs | 96 |
1 files changed, 94 insertions, 2 deletions
diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs index 20a960243..cba25303e 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; using System.IO; using System.Linq; using System.Text; @@ -9,6 +11,7 @@ using Tango.Core.Commands; using Tango.FileSystem; using Tango.FSE.Common; using Tango.FSE.Common.Connection; +using Tango.FSE.Common.FileSystem; using static Tango.SharedUI.Controls.NavigationControl; namespace Tango.FSE.PPCConsole.ViewModels @@ -36,20 +39,36 @@ namespace Tango.FSE.PPCConsole.ViewModels set { _drives = value; RaisePropertyChangedAuto(); } } + public ObservableCollection<FileSystemItem> SelectedItems { get; set; } + public ObservableCollection<FileSystemHandler> FileSystemHandlers { get; set; } public RelayCommand NavigateCommand { get; set; } public RelayCommand<FileSystemItem> OpenItemCommand { get; set; } public RelayCommand BackCommand { get; set; } public RelayCommand<String> NavigateSpecialFolderCommand { get; set; } public RelayCommand<String> NavigateToFolderCommand { get; set; } + public RelayCommand<IList<FileSystemItem>> DeleteCommand { get; set; } + public RelayCommand<List<FileSystemItem>> DropCommand { get; set; } + public RelayCommand<List<DragItem>> DragCommand { get; set; } + public RelayCommand<FileSystemHandler> DeleteFileSystemHandlerCommand { get; set; } + public RelayCommand<FileSystemHandler> OpenFileSystemHandlerDestinationCommand { get; set; } + public RelayCommand<FileSystemHandler> RetryFailedFileSystemHandlerCommand { get; set; } + public FileSystemViewVM() { + SelectedItems = new ObservableCollection<FileSystemItem>(); + FileSystemHandlers = new ObservableCollection<FileSystemHandler>(); NavigateCommand = new RelayCommand(NavigateToCurrentPath); OpenItemCommand = new RelayCommand<FileSystemItem>(OpenFileSystemItem); BackCommand = new RelayCommand(NavigateBack, () => !(CurrentItem is FolderItem) || !(CurrentItem as FolderItem).IsRoot); NavigateSpecialFolderCommand = new RelayCommand<string>(NavigateToSpecialFolder); - NavigateToFolderCommand = new RelayCommand<string>(async (x) => await Navigate(x)); + NavigateToFolderCommand = new RelayCommand<string>(async (x) => await Navigate(x)); + DeleteCommand = new RelayCommand<IList<FileSystemItem>>(DeleteSelectedItems); + DragCommand = new RelayCommand<List<DragItem>>(OnItemsDraggedOut); + DeleteFileSystemHandlerCommand = new RelayCommand<FileSystemHandler>(DeleteFileSystemHandler); + OpenFileSystemHandlerDestinationCommand = new RelayCommand<FileSystemHandler>(OpenFileSystemHandlerDestination); + RetryFailedFileSystemHandlerCommand = new RelayCommand<FileSystemHandler>(RetryFailedFileSystemHandler); } private async void NavigateBack() @@ -88,10 +107,83 @@ namespace Tango.FSE.PPCConsole.ViewModels private async void OpenFileSystemItem(FileSystemItem item) { - if (item != null) + if (item == null) return; + + if (item.Type == FileSystemItemType.Folder || item.Type == FileSystemItemType.Drive) { await Navigate(item.Path); } + else if (item.Type == FileSystemItemType.File) + { + //TODO: Download/Open file?... + } + } + + private async void DeleteSelectedItems(IList<FileSystemItem> items) + { + if (items != null && items.Count > 0) + { + if (await NotificationProvider.ShowWarningQuestion("Are you sure you want to delete the selected files/folders?", "DELETE")) + { + //TODO: Delete items + } + } + } + + private async void OnItemsDraggedOut(List<DragItem> items) + { + foreach (var item in items.Where(x => x.FileSystemItem.Type != FileSystemItemType.Drive)) + { + Debug.WriteLine($"Dropped out: {item.FileSystemItem.Name} => {item.Destination}"); + var handler = await FileSystemProvider.Download(item.FileSystemItem, item.Destination); + FileSystemHandlers.Insert(0, handler); + } + } + + private async void DeleteFileSystemHandler(FileSystemHandler handler) + { + if (handler.Status != FileSystemHandlerStatus.Completed && handler.Status != FileSystemHandlerStatus.Failed) + { + if (await NotificationProvider.ShowWarningQuestion($"This item is currently {handler.Status}. Do you wish to abort and delete this item?")) + { + try + { + handler.Abort(); + } + catch { } + + FileSystemHandlers.Remove(handler); + } + } + else + { + FileSystemHandlers.Remove(handler); + } + } + + private void OpenFileSystemHandlerDestination(FileSystemHandler handler) + { + String destination = String.Empty; + + if (File.Exists(handler.Destination) || Directory.Exists(handler.Destination)) + { + destination = handler.Destination; + Process.Start("explorer.exe", string.Format("/select,\"{0}\"", destination)); + } + else + { + destination = Path.GetDirectoryName(handler.Destination); + Process.Start("explorer.exe", destination); + } + } + + private async void RetryFailedFileSystemHandler(FileSystemHandler handler) + { + if (handler.Status == FileSystemHandlerStatus.Failed) + { + var newHandler = await FileSystemProvider.Download(handler.FileSystemItem, Path.GetDirectoryName(handler.Destination)); + FileSystemHandlers.Replace(handler, newHandler); + } } private async void NavigateToSpecialFolder(string folder) |
