Skip to content

Commit 07912b3

Browse files
committed
improved the context menu
1 parent 249e74e commit 07912b3

File tree

2 files changed

+291
-236
lines changed

2 files changed

+291
-236
lines changed

K8sFileBrowser/ViewModels/MainWindowViewModel.cs

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using System.Threading.Tasks;
1010
using K8sFileBrowser.Models;
1111
using K8sFileBrowser.Services;
12-
using Microsoft.IdentityModel.Tokens;
1312
using ReactiveUI;
1413
using ReactiveUI.Fody.Helpers;
1514
using Serilog;
@@ -65,14 +64,11 @@ public class MainWindowViewModel : ViewModelBase
6564
#endregion Properties
6665

6766
#region Commands
68-
69-
public ReactiveCommand<Unit, Unit> DownloadCommand { get; private set; } = null!;
67+
7068
public ReactiveCommand<Unit, Unit> DownloadLogCommand { get; private set; } = null!;
7169
public ReactiveCommand<Unit, Unit> RefreshCommand { get; private set; } = null!;
7270
public ReactiveCommand<Unit, Unit> ParentCommand { get; private set; } = null!;
73-
public ReactiveCommand<Unit, Unit> OpenCommand { get; private set; } = null!;
7471
public ReactiveCommand<FileInformation, Unit> OpenContextCommand { get; private set; } = null!;
75-
7672
public ReactiveCommand<FileInformation, Unit> DownloadContextCommand { get; private set; } = null!;
7773
private ReactiveCommand<Namespace, IEnumerable<Pod>> GetPodsForNamespace { get; set; } = null!;
7874

@@ -85,9 +81,7 @@ public MainWindowViewModel()
8581
Version = Assembly.GetExecutingAssembly().GetName().Version?.ToString();
8682

8783
// commands
88-
ConfigureOpenDirectoryCommand();
8984
ConfigureOpenDirectoryContextCommand();
90-
ConfigureDownloadFileCommand(kubernetesService);
9185
ConfigureDownloadFileContextCommand(kubernetesService);
9286
ConfigureRefreshCommand(kubernetesService);
9387
ConfigureDownloadLogCommand(kubernetesService);
@@ -275,32 +269,7 @@ await Observable.Start(() =>
275269
.Subscribe(ShowErrorMessage);
276270
}
277271

278-
private void ConfigureDownloadFileCommand(IKubernetesService kubernetesService)
279-
{
280-
var isFile = this
281-
.WhenAnyValue(x => x.SelectedFile, x => x.Message.IsVisible)
282-
.Select(x => x is { Item1.Type: FileType.File, Item2: false });
283-
284-
DownloadCommand = ReactiveCommand.CreateFromTask(async () =>
285-
{
286-
await Observable.StartAsync(async () =>
287-
{
288-
var fileName = SelectedFile!.Name.Substring(SelectedFile!.Name.LastIndexOf('/') + 1,
289-
SelectedFile!.Name.Length - SelectedFile!.Name.LastIndexOf('/') - 1);
290-
var saveFileName = await ApplicationHelper.SaveFile(_lastDirectory, fileName);
291-
if (saveFileName != null)
292-
{
293-
SetLastDirectory(saveFileName);
294-
ShowWorkingMessage("Downloading File...");
295-
await kubernetesService.DownloadFile(SelectedNamespace, SelectedPod, SelectedContainer, SelectedFile, saveFileName);
296-
HideWorkingMessage();
297-
}
298-
}, RxApp.TaskpoolScheduler);
299-
}, isFile, RxApp.MainThreadScheduler);
300-
301-
DownloadCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler)
302-
.Subscribe(ShowErrorMessage);
303-
}
272+
304273

305274
private void ConfigureDownloadFileContextCommand(IKubernetesService kubernetesService)
306275
{
@@ -322,33 +291,15 @@ await Observable.StartAsync(async () =>
322291
}, RxApp.TaskpoolScheduler);
323292
}, outputScheduler: RxApp.MainThreadScheduler);
324293

325-
DownloadCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler)
294+
DownloadContextCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler)
326295
.Subscribe(ShowErrorMessage);
327296
}
328297

329298
private void SetLastDirectory(string saveFileName)
330299
{
331300
_lastDirectory = saveFileName.Substring(0, saveFileName.LastIndexOf(Path.DirectorySeparatorChar));
332301
}
333-
334-
private void ConfigureOpenDirectoryCommand()
335-
{
336-
var isDirectory = this
337-
.WhenAnyValue(x => x.SelectedFile, x => x.Message.IsVisible)
338-
.Select(x => x is { Item1.Type: FileType.Directory, Item2: false });
339-
340-
OpenCommand = ReactiveCommand.Create(() =>
341-
{
342-
if (".." == SelectedFile?.Name)
343-
SelectedPath = SelectedFile?.Parent;
344-
else
345-
SelectedPath = SelectedFile != null ? SelectedFile!.Name : "/";
346-
},
347-
isDirectory, RxApp.MainThreadScheduler);
348-
349-
OpenCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler)
350-
.Subscribe(ShowErrorMessage);
351-
}
302+
352303

353304
private void ConfigureOpenDirectoryContextCommand()
354305
{
@@ -357,7 +308,7 @@ private void ConfigureOpenDirectoryContextCommand()
357308
SelectedPath = ".." == file.Name ? file.Parent : file.Name;
358309
}, outputScheduler: RxApp.MainThreadScheduler);
359310

360-
OpenCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler)
311+
OpenContextCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler)
361312
.Subscribe(ShowErrorMessage);
362313
}
363314

0 commit comments

Comments
 (0)