aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/FileSystemViewVM.cs
diff options
context:
space:
mode:
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.cs146
1 files changed, 142 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..f074294b2 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,10 @@ 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 FileSystemViewVM()
@@ -69,6 +74,10 @@ 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);
}
private async void NavigateBack()
@@ -97,7 +106,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 +135,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 +179,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 +287,91 @@ 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 void DownloadSelectedItems(List<FileSystemItem> items)
+ {
+
+ }
+
+ 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 void OnCurrentItemChanged()
{
CurrentPath = CurrentItem.Path;