wabbajack/Wabbajack.App/Views/InstallConfigurationView.axaml.cs

89 lines
3.1 KiB
C#
Raw Normal View History

2021-09-27 12:42:46 +00:00
using System;
2021-11-09 02:36:07 +00:00
using System.Collections.Generic;
using System.Linq;
2021-09-27 12:42:46 +00:00
using System.Reactive.Disposables;
using System.Reactive.Linq;
2021-11-09 02:36:07 +00:00
using System.Threading.Tasks;
using Avalonia.Controls;
2021-09-27 12:42:46 +00:00
using Avalonia.ReactiveUI;
2021-11-09 02:36:07 +00:00
using Avalonia.Threading;
2021-09-27 12:42:46 +00:00
using Microsoft.Extensions.DependencyInjection;
using ReactiveUI;
using Wabbajack.App.Interfaces;
using Wabbajack.App.ViewModels;
2021-11-09 02:36:07 +00:00
using Wabbajack.Common;
using Wabbajack.Paths;
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
namespace Wabbajack.App.Views;
2021-11-04 13:01:48 +00:00
public partial class InstallConfigurationView : ScreenBase<InstallConfigurationViewModel>, IScreenView
2021-09-27 12:42:46 +00:00
{
2021-11-04 13:01:48 +00:00
public InstallConfigurationView() : base("Install Configuration")
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
InitializeComponent();
DataContext = App.Services.GetService<InstallConfigurationViewModel>()!;
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
this.WhenActivated(disposables =>
{
2021-11-09 02:36:07 +00:00
ModListFile.SelectButton.Command = ReactiveCommand.CreateFromTask(SelectWabbajackFile)
2021-10-23 16:51:17 +00:00
.DisposeWith(disposables);
2021-11-09 02:36:07 +00:00
this.OneWayBind(ViewModel, vm => vm.ModListPath, view => view.ModListFile.TextBox.Text)
2021-10-23 16:51:17 +00:00
.DisposeWith(disposables);
2021-09-27 12:42:46 +00:00
2021-11-09 02:36:07 +00:00
InstallPath.SelectButton.Command = ReactiveCommand.CreateFromTask(() =>
SelectFolder("Select Install Location", p => ViewModel!.Install = p))
2021-10-23 16:51:17 +00:00
.DisposeWith(disposables);
2021-11-09 02:36:07 +00:00
this.OneWayBind(ViewModel, vm => vm.Install, view => view.InstallPath.TextBox.Text)
2021-10-23 16:51:17 +00:00
.DisposeWith(disposables);
2021-11-09 02:36:07 +00:00
DownloadPath.SelectButton.Command = ReactiveCommand.CreateFromTask(() =>
SelectFolder("Select Download Location", p => ViewModel!.Download = p))
2021-10-23 16:51:17 +00:00
.DisposeWith(disposables);
2021-11-09 02:36:07 +00:00
this.OneWayBind(ViewModel, vm => vm.Download, view => view.DownloadPath.TextBox.Text)
.DisposeWith(disposables);
2021-11-08 23:17:33 +00:00
this.OneWayBind(ViewModel, vm => vm.ModListImage, view => view.ModListImage.Source)
.DisposeWith(disposables);
2021-11-04 13:01:48 +00:00
this.BindCommand(ViewModel, vm => vm.BeginCommand, view => view.BeginInstall.Button)
.DisposeWith(disposables);
2021-10-23 16:51:17 +00:00
});
2021-09-27 12:42:46 +00:00
}
2021-10-23 16:51:17 +00:00
2021-11-09 02:36:07 +00:00
private async Task SelectWabbajackFile()
{
var fod = new OpenFileDialog()
{
Filters = new List<FileDialogFilter> {new()
{
Name = "Wabbajack",
Extensions = new List<string> {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<AbsolutePath> toCall)
{
var fod = new OpenFolderDialog
{
Title = title
};
var result = await fod.ShowAsync(App.MainWindow);
if (result == null) return;
Dispatcher.UIThread.Post(() =>
{
toCall(result.ToAbsolutePath());
});
}
2021-10-23 16:51:17 +00:00
public Type ViewModelType => typeof(InstallConfigurationViewModel);
2021-09-27 12:42:46 +00:00
}