From 2a03b01e4aab4ee9a39d0df92a950bbfd9f8f195 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Mon, 8 Nov 2021 19:36:07 -0700 Subject: [PATCH] Fix file selection for install page --- .../Controls/ButtonSettingTextBox.axaml | 41 +++++++++++ .../Controls/ButtonSettingTextBox.axaml.cs | 12 ++++ .../Controls/FileSelectionBox.axaml.cs | 15 ++-- .../Views/InstallConfigurationView.axaml | 6 +- .../Views/InstallConfigurationView.axaml.cs | 71 ++++++++++++++----- 5 files changed, 117 insertions(+), 28 deletions(-) create mode 100644 Wabbajack.App/Controls/ButtonSettingTextBox.axaml create mode 100644 Wabbajack.App/Controls/ButtonSettingTextBox.axaml.cs diff --git a/Wabbajack.App/Controls/ButtonSettingTextBox.axaml b/Wabbajack.App/Controls/ButtonSettingTextBox.axaml new file mode 100644 index 00000000..549fbb1c --- /dev/null +++ b/Wabbajack.App/Controls/ButtonSettingTextBox.axaml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Wabbajack.App/Controls/ButtonSettingTextBox.axaml.cs b/Wabbajack.App/Controls/ButtonSettingTextBox.axaml.cs new file mode 100644 index 00000000..bad8d6db --- /dev/null +++ b/Wabbajack.App/Controls/ButtonSettingTextBox.axaml.cs @@ -0,0 +1,12 @@ +using Avalonia.Controls; + +namespace Wabbajack.App.Controls; + +public partial class ButtonSettingTextBox : UserControl +{ + public ButtonSettingTextBox() + { + InitializeComponent(); + } + +} \ No newline at end of file diff --git a/Wabbajack.App/Controls/FileSelectionBox.axaml.cs b/Wabbajack.App/Controls/FileSelectionBox.axaml.cs index 7ca6efcd..a99124b3 100644 --- a/Wabbajack.App/Controls/FileSelectionBox.axaml.cs +++ b/Wabbajack.App/Controls/FileSelectionBox.axaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Reactive.Disposables; using System.Reactive.Linq; @@ -7,6 +8,7 @@ using System.Threading.Tasks; using Avalonia; using Avalonia.Controls; using Avalonia.ReactiveUI; +using Avalonia.Threading; using Microsoft.Extensions.DependencyInjection; using ReactiveUI; using ReactiveUI.Fody.Helpers; @@ -14,11 +16,8 @@ using Wabbajack.Paths; namespace Wabbajack.App.Controls; -public partial class FileSelectionBox : UserControl +public partial class FileSelectionBox : ReactiveUserControl { - public static readonly DirectProperty SelectedPathProperty = - AvaloniaProperty.RegisterDirect(nameof(SelectedPath), o => o.SelectedPath); - public static readonly StyledProperty AllowedExtensionsProperty = AvaloniaProperty.Register(nameof(AllowedExtensions)); @@ -63,7 +62,7 @@ public partial class FileSelectionBox : UserControl } [Reactive] - public AbsolutePath SelectedPath { get; private set; } + public AbsolutePath SelectedPath { get; set; } public string AllowedExtensions { @@ -79,7 +78,9 @@ public partial class FileSelectionBox : UserControl public void Load(AbsolutePath path) { - TextBox.Text = path.ToString(); - SelectedPath = path; + Dispatcher.UIThread.Post(() => { + TextBox.Text = path.ToString(); + SelectedPath = path; + }); } } \ No newline at end of file diff --git a/Wabbajack.App/Views/InstallConfigurationView.axaml b/Wabbajack.App/Views/InstallConfigurationView.axaml index f37b4040..a7ba5639 100644 --- a/Wabbajack.App/Views/InstallConfigurationView.axaml +++ b/Wabbajack.App/Views/InstallConfigurationView.axaml @@ -18,13 +18,13 @@ - + - + - + diff --git a/Wabbajack.App/Views/InstallConfigurationView.axaml.cs b/Wabbajack.App/Views/InstallConfigurationView.axaml.cs index 3ed03b14..7ae7a93e 100644 --- a/Wabbajack.App/Views/InstallConfigurationView.axaml.cs +++ b/Wabbajack.App/Views/InstallConfigurationView.axaml.cs @@ -1,11 +1,18 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Reactive.Disposables; using System.Reactive.Linq; +using System.Threading.Tasks; +using Avalonia.Controls; using Avalonia.ReactiveUI; +using Avalonia.Threading; using Microsoft.Extensions.DependencyInjection; using ReactiveUI; using Wabbajack.App.Interfaces; using Wabbajack.App.ViewModels; +using Wabbajack.Common; +using Wabbajack.Paths; namespace Wabbajack.App.Views; @@ -18,30 +25,23 @@ public partial class InstallConfigurationView : ScreenBase { - ViewModel.WhenAnyValue(vm => vm.ModListPath) - .Subscribe(path => ModListFile.Load(path)) + ModListFile.SelectButton.Command = ReactiveCommand.CreateFromTask(SelectWabbajackFile) + .DisposeWith(disposables); + this.OneWayBind(ViewModel, vm => vm.ModListPath, view => view.ModListFile.TextBox.Text) .DisposeWith(disposables); - ViewModel.WhenAnyValue(vm => vm.Download) - .Subscribe(path => DownloadPath.Load(path)) + InstallPath.SelectButton.Command = ReactiveCommand.CreateFromTask(() => + SelectFolder("Select Install Location", p => ViewModel!.Install = p)) + .DisposeWith(disposables); + this.OneWayBind(ViewModel, vm => vm.Install, view => view.InstallPath.TextBox.Text) .DisposeWith(disposables); - ViewModel.WhenAnyValue(vm => vm.Install) - .Subscribe(path => InstallPath.Load(path)) + DownloadPath.SelectButton.Command = ReactiveCommand.CreateFromTask(() => + SelectFolder("Select Download Location", p => ViewModel!.Download = p)) .DisposeWith(disposables); - - this.WhenAnyValue(view => view.ModListFile.SelectedPath) - .BindTo(ViewModel, vm => vm.ModListPath) + this.OneWayBind(ViewModel, vm => vm.Download, view => view.DownloadPath.TextBox.Text) .DisposeWith(disposables); - - this.WhenAnyValue(view => view.DownloadPath.SelectedPath) - .BindTo(ViewModel, vm => vm.Download) - .DisposeWith(disposables); - - this.WhenAnyValue(view => view.InstallPath.SelectedPath) - .BindTo(ViewModel, vm => vm.Install) - .DisposeWith(disposables); - + this.OneWayBind(ViewModel, vm => vm.ModListImage, view => view.ModListImage.Source) .DisposeWith(disposables); @@ -50,5 +50,40 @@ public partial class InstallConfigurationView : ScreenBase {new() + { + Name = "Wabbajack", + Extensions = new List {Ext.Wabbajack.ToString()} + } + } + }; + var result = await fod.ShowAsync(App.MainWindow); + if (result == null) return; + + Dispatcher.UIThread.Post(() => + { + ViewModel!.ModListPath = result.First().ToAbsolutePath(); + }); + } + + public async Task SelectFolder(string title, Action toCall) + { + var fod = new OpenFolderDialog + { + Title = title + }; + var result = await fod.ShowAsync(App.MainWindow); + if (result == null) return; + + Dispatcher.UIThread.Post(() => + { + toCall(result.ToAbsolutePath()); + }); + } + public Type ViewModelType => typeof(InstallConfigurationViewModel); } \ No newline at end of file