diff options
| author | Avi Levkovich <avi@twine-s.com> | 2020-03-25 17:46:56 +0200 |
|---|---|---|
| committer | Avi Levkovich <avi@twine-s.com> | 2020-03-25 17:46:56 +0200 |
| commit | aa732a33f7c63ce4438ec2b79fedb641ffd22b05 (patch) | |
| tree | 86ccf57c1dfb6801de16f15d681539c02b007508 /Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs | |
| parent | d29da53d6f71f45749c0ede5b4cd7281ed3a270e (diff) | |
| parent | 8f57d4962fa84499c8a153ebfff6e7766434ee1c (diff) | |
| download | Tango-aa732a33f7c63ce4438ec2b79fedb641ffd22b05.tar.gz Tango-aa732a33f7c63ce4438ec2b79fedb641ffd22b05.zip | |
merge conflicts -take remote
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 | 203 |
1 files changed, 199 insertions, 4 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 cba25303e..e10cc0ad1 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,4 +1,5 @@ -using System; +using MaterialDesignThemes.Wpf; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; @@ -53,6 +54,11 @@ namespace Tango.FSE.PPCConsole.ViewModels public RelayCommand<FileSystemHandler> DeleteFileSystemHandlerCommand { get; set; } public RelayCommand<FileSystemHandler> OpenFileSystemHandlerDestinationCommand { get; set; } public RelayCommand<FileSystemHandler> RetryFailedFileSystemHandlerCommand { get; set; } + public RelayCommand<List<FileSystemItem>> CopyPasteCommand { get; set; } + public RelayCommand<List<FileSystemItem>> CutPasteCommand { get; set; } + public RelayCommand<List<FileSystemItem>> DownloadCommand { get; set; } + public RelayCommand<FileSystemItem> RenameCommand { get; set; } + public RelayCommand NewFolderCommand { get; set; } public FileSystemViewVM() @@ -69,6 +75,11 @@ namespace Tango.FSE.PPCConsole.ViewModels DeleteFileSystemHandlerCommand = new RelayCommand<FileSystemHandler>(DeleteFileSystemHandler); OpenFileSystemHandlerDestinationCommand = new RelayCommand<FileSystemHandler>(OpenFileSystemHandlerDestination); RetryFailedFileSystemHandlerCommand = new RelayCommand<FileSystemHandler>(RetryFailedFileSystemHandler); + CopyPasteCommand = new RelayCommand<List<FileSystemItem>>((items) => PasteItems(items, false)); + CutPasteCommand = new RelayCommand<List<FileSystemItem>>((items) => PasteItems(items, true)); + DownloadCommand = new RelayCommand<List<FileSystemItem>>(DownloadSelectedItems); + RenameCommand = new RelayCommand<FileSystemItem>(RenameFileSystemItem); + NewFolderCommand = new RelayCommand(CreateNewFolder); } private async void NavigateBack() @@ -97,7 +108,10 @@ namespace Tango.FSE.PPCConsole.ViewModels private async void MachineProvider_MachineConnected(object sender, MachineConnectedEventArgs e) { - await Navigate(null); + if (e.DifferentFromPrevious) + { + await Navigate(null); + } } private async void NavigateToCurrentPath() @@ -123,9 +137,41 @@ namespace Tango.FSE.PPCConsole.ViewModels { if (items != null && items.Count > 0) { - if (await NotificationProvider.ShowWarningQuestion("Are you sure you want to delete the selected files/folders?", "DELETE")) + if (await NotificationProvider.ShowWarningQuestion($"Are you sure you want to delete {(items.Count == 1 ? $"'{items.First().Name}'" : $"the {items.Count} selected files/folders")}?", "DELETE")) { - //TODO: Delete items + using (var task = NotificationProvider.PushTaskItem("Removing...")) + { + int remainingItems = items.Count; + + foreach (var item in items) + { + task.UpdateProgress($"Removing '{item.Name}'..."); + + try + { + remainingItems--; + await FileSystemProvider.Delete(item); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Could not remove '{item.Name}'."); + + if (remainingItems > 0) + { + if (!await NotificationProvider.ShowWarningQuestion($"Could not remove '{item.Name}'.\n{ex.FlattenMessage()}\nDo you wish to continue removing the remaining items?")) + { + break; + } + } + else + { + await NotificationProvider.ShowError($"Could not remove '{item.Name}'.\n{ex.FlattenMessage()}"); + } + } + } + } + + NavigateToCurrentPath(); } } } @@ -135,6 +181,15 @@ namespace Tango.FSE.PPCConsole.ViewModels foreach (var item in items.Where(x => x.FileSystemItem.Type != FileSystemItemType.Drive)) { Debug.WriteLine($"Dropped out: {item.FileSystemItem.Name} => {item.Destination}"); + + if (File.Exists(Path.Combine(item.Destination, item.FileSystemItem.Name)) || Directory.Exists(Path.Combine(item.Destination, item.FileSystemItem.Name))) + { + if (!await NotificationProvider.ShowWarningQuestion($"'{item.FileSystemItem.Name}' already exists on '{Path.GetDirectoryName(item.Destination)}'. Do you want to overwrite?")) + { + continue; + } + } + var handler = await FileSystemProvider.Download(item.FileSystemItem, item.Destination); FileSystemHandlers.Insert(0, handler); } @@ -234,6 +289,146 @@ namespace Tango.FSE.PPCConsole.ViewModels } } + private async void PasteItems(List<FileSystemItem> items, bool move = false) + { + using (var task = NotificationProvider.PushTaskItem("Please wait...")) + { + int remainingItems = items.Count; + + foreach (var item in items) + { + Debug.WriteLine($"{(move ? "Cut" : "Copy")} Paste Item '{item.Name}' To '{CurrentItem.Name}'."); + + try + { + remainingItems--; + + if (move) + { + task.UpdateProgress($"Moving '{item.Name}'..."); + await FileSystemProvider.Move(item, CurrentItem); + } + else + { + task.UpdateProgress($"Copying '{item.Name}'..."); + await FileSystemProvider.Copy(item, CurrentItem); + } + } + catch (Exception ex) + { + string operation = move ? "move" : "copy"; + + LogManager.Log(ex, $"Could not {operation} '{item.Name}'."); + + if (remainingItems > 0) + { + if (!await NotificationProvider.ShowWarningQuestion($"Could not {operation} '{item.Name}'.\n{ex.FlattenMessage()}\nDo you wish to continue with the remaining items?")) + { + break; + } + } + else + { + await NotificationProvider.ShowError($"Could not {operation} '{item.Name}'.\n{ex.FlattenMessage()}"); + } + } + } + + NavigateToCurrentPath(); + } + } + + private async void DownloadSelectedItems(List<FileSystemItem> items) + { + var result = await StorageProvider.SelectFolder("Select download destination folder"); + if (result) + { + + String destination = result.SelectedItem; + + Debug.WriteLine($"Download to {result.SelectedItem}"); + + foreach (var item in items.Where(x => x.Type != FileSystemItemType.Drive)) + { + if (File.Exists(Path.Combine(destination, item.Name)) || Directory.Exists(Path.Combine(destination, item.Name))) + { + if (!await NotificationProvider.ShowWarningQuestion($"'{item.Name}' already exists on '{Path.GetDirectoryName(destination)}'. Do you want to overwrite?")) + { + continue; + } + } + + var handler = await FileSystemProvider.Download(item, destination); + FileSystemHandlers.Insert(0, handler); + } + } + } + + private async void RenameFileSystemItem(FileSystemItem item) + { + if (item.Type != FileSystemItemType.Drive) + { + var result = await NotificationProvider.ShowInputBox( + "Rename", + $"Please enter a new {(item.Type == FileSystemItemType.File ? "file" : "folder")} name and press 'ENTER'.", + PackIconKind.Rename, item.Name, + $"{(item.Type == FileSystemItemType.File ? "file" : "folder")} name", + 100, + "RENAME"); + + if (result.Confirmed && result.Input != item.Name) + { + try + { + using (NotificationProvider.PushTaskItem("Renaming...")) + { + await FileSystemProvider.Rename(item, result.Input); + item.Path = Path.Combine(Path.GetDirectoryName(item.Path), result.Input); + } + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error renaming '{item.Path}' to {result.Input}."); + await NotificationProvider.ShowError($"Error renaming '{item.Name}'.\n{ex.FlattenMessage()}"); + } + } + } + } + + private async void CreateNewFolder() + { + if (CurrentItem == null) return; + if (CurrentItem is FolderItem) + { + if ((CurrentItem as FolderItem).IsRoot) return; + } + + var result = await NotificationProvider.ShowInputBox( + "New Folder", + $"Please enter a folder name and press 'ENTER'.", + PackIconKind.FolderAdd, "untitled", + "folder name", + 100, + "CREATE"); + + if (result.Confirmed) + { + try + { + using (NotificationProvider.PushTaskItem("Creating new folder...")) + { + var folderItem = await FileSystemProvider.CreateFolder(CurrentItem, result.Input); + NavigateToCurrentPath(); //Instead of inserting folder item just refresh the current path... + } + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error creating new folder '{Path.Combine(CurrentItem.Path,result.Input)}."); + await NotificationProvider.ShowError($"Error creating folder '{result.Input}'.\n{ex.FlattenMessage()}"); + } + } + } + private void OnCurrentItemChanged() { CurrentPath = CurrentItem.Path; |
