From 07912b3239e09d79af0849108c449b5f374c7e35 Mon Sep 17 00:00:00 2001 From: Andreas Billmann Date: Thu, 13 Mar 2025 06:19:04 +0100 Subject: [PATCH] improved the context menu --- .../ViewModels/MainWindowViewModel.cs | 59 +-- K8sFileBrowser/Views/MainWindow.axaml | 470 +++++++++++------- 2 files changed, 292 insertions(+), 237 deletions(-) diff --git a/K8sFileBrowser/ViewModels/MainWindowViewModel.cs b/K8sFileBrowser/ViewModels/MainWindowViewModel.cs index 96091f7..aee7877 100644 --- a/K8sFileBrowser/ViewModels/MainWindowViewModel.cs +++ b/K8sFileBrowser/ViewModels/MainWindowViewModel.cs @@ -9,7 +9,6 @@ using System.Reflection; using System.Threading.Tasks; using K8sFileBrowser.Models; using K8sFileBrowser.Services; -using Microsoft.IdentityModel.Tokens; using ReactiveUI; using ReactiveUI.Fody.Helpers; using Serilog; @@ -65,14 +64,11 @@ public class MainWindowViewModel : ViewModelBase #endregion Properties #region Commands - - public ReactiveCommand DownloadCommand { get; private set; } = null!; + public ReactiveCommand DownloadLogCommand { get; private set; } = null!; public ReactiveCommand RefreshCommand { get; private set; } = null!; public ReactiveCommand ParentCommand { get; private set; } = null!; - public ReactiveCommand OpenCommand { get; private set; } = null!; public ReactiveCommand OpenContextCommand { get; private set; } = null!; - public ReactiveCommand DownloadContextCommand { get; private set; } = null!; private ReactiveCommand> GetPodsForNamespace { get; set; } = null!; @@ -85,9 +81,7 @@ public class MainWindowViewModel : ViewModelBase Version = Assembly.GetExecutingAssembly().GetName().Version?.ToString(); // commands - ConfigureOpenDirectoryCommand(); ConfigureOpenDirectoryContextCommand(); - ConfigureDownloadFileCommand(kubernetesService); ConfigureDownloadFileContextCommand(kubernetesService); ConfigureRefreshCommand(kubernetesService); ConfigureDownloadLogCommand(kubernetesService); @@ -275,32 +269,7 @@ public class MainWindowViewModel : ViewModelBase .Subscribe(ShowErrorMessage); } - private void ConfigureDownloadFileCommand(IKubernetesService kubernetesService) - { - var isFile = this - .WhenAnyValue(x => x.SelectedFile, x => x.Message.IsVisible) - .Select(x => x is { Item1.Type: FileType.File, Item2: false }); - - DownloadCommand = ReactiveCommand.CreateFromTask(async () => - { - await Observable.StartAsync(async () => - { - var fileName = SelectedFile!.Name.Substring(SelectedFile!.Name.LastIndexOf('/') + 1, - SelectedFile!.Name.Length - SelectedFile!.Name.LastIndexOf('/') - 1); - var saveFileName = await ApplicationHelper.SaveFile(_lastDirectory, fileName); - if (saveFileName != null) - { - SetLastDirectory(saveFileName); - ShowWorkingMessage("Downloading File..."); - await kubernetesService.DownloadFile(SelectedNamespace, SelectedPod, SelectedContainer, SelectedFile, saveFileName); - HideWorkingMessage(); - } - }, RxApp.TaskpoolScheduler); - }, isFile, RxApp.MainThreadScheduler); - - DownloadCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler) - .Subscribe(ShowErrorMessage); - } + private void ConfigureDownloadFileContextCommand(IKubernetesService kubernetesService) { @@ -322,7 +291,7 @@ public class MainWindowViewModel : ViewModelBase }, RxApp.TaskpoolScheduler); }, outputScheduler: RxApp.MainThreadScheduler); - DownloadCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler) + DownloadContextCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler) .Subscribe(ShowErrorMessage); } @@ -330,25 +299,7 @@ public class MainWindowViewModel : ViewModelBase { _lastDirectory = saveFileName.Substring(0, saveFileName.LastIndexOf(Path.DirectorySeparatorChar)); } - - private void ConfigureOpenDirectoryCommand() - { - var isDirectory = this - .WhenAnyValue(x => x.SelectedFile, x => x.Message.IsVisible) - .Select(x => x is { Item1.Type: FileType.Directory, Item2: false }); - - OpenCommand = ReactiveCommand.Create(() => - { - if (".." == SelectedFile?.Name) - SelectedPath = SelectedFile?.Parent; - else - SelectedPath = SelectedFile != null ? SelectedFile!.Name : "/"; - }, - isDirectory, RxApp.MainThreadScheduler); - - OpenCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler) - .Subscribe(ShowErrorMessage); - } + private void ConfigureOpenDirectoryContextCommand() { @@ -357,7 +308,7 @@ public class MainWindowViewModel : ViewModelBase SelectedPath = ".." == file.Name ? file.Parent : file.Name; }, outputScheduler: RxApp.MainThreadScheduler); - OpenCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler) + OpenContextCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler) .Subscribe(ShowErrorMessage); } diff --git a/K8sFileBrowser/Views/MainWindow.axaml b/K8sFileBrowser/Views/MainWindow.axaml index 7452726..f9e06cd 100644 --- a/K8sFileBrowser/Views/MainWindow.axaml +++ b/K8sFileBrowser/Views/MainWindow.axaml @@ -15,196 +15,300 @@ - + - - + + + + . - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file