wabbajack/Wabbajack.App/Screens/CompilerConfigurationView.axaml.cs

107 lines
4.0 KiB
C#
Raw Normal View History

2021-10-14 04:46:43 +00:00
using System.Collections.Generic;
2021-10-13 21:51:00 +00:00
using System.Linq;
using System.Reactive.Disposables;
2021-10-13 21:51:00 +00:00
using System.Threading.Tasks;
using Avalonia.Controls;
2021-10-14 04:46:43 +00:00
using Avalonia.Interactivity;
using Avalonia.Threading;
using ReactiveUI;
2021-10-13 21:51:00 +00:00
using Wabbajack.App.Controls;
2021-11-05 11:47:14 +00:00
using Wabbajack.App.Extensions;
using Wabbajack.App.Views;
2021-10-13 21:51:00 +00:00
using Wabbajack.Common;
using Wabbajack.Paths;
2021-10-23 16:51:17 +00:00
namespace Wabbajack.App.Screens;
public partial class CompilerConfigurationView : ScreenBase<CompilerConfigurationViewModel>
{
2021-11-04 13:01:48 +00:00
public CompilerConfigurationView() : base("Compiler Configuration")
{
2021-10-23 16:51:17 +00:00
InitializeComponent();
AddAlwaysEnabled.Command = ReactiveCommand.Create(() => AddAlwaysEnabled_Command().FireAndForget());
2021-11-05 22:58:08 +00:00
AddOtherProfile.Command = ReactiveCommand.Create(() => AddOtherProfile_Command().FireAndForget());
2021-10-23 16:51:17 +00:00
this.WhenActivated(disposables =>
{
2021-10-23 16:51:17 +00:00
this.Bind(ViewModel, vm => vm.Title, view => view.Title.Text)
.DisposeWith(disposables);
2021-11-05 11:47:14 +00:00
SettingsFile.BindFileSelectionBox(ViewModel, vm => vm.SettingsFile)
2021-10-23 16:51:17 +00:00
.DisposeWith(disposables);
2021-11-05 11:47:14 +00:00
Source.BindFileSelectionBox(ViewModel, vm => vm.Source)
2021-10-23 16:51:17 +00:00
.DisposeWith(disposables);
2021-11-05 11:47:14 +00:00
DownloadsFolder.BindFileSelectionBox(ViewModel, vm => vm.Downloads)
2021-10-23 16:51:17 +00:00
.DisposeWith(disposables);
2021-10-13 21:51:00 +00:00
2021-11-05 11:47:14 +00:00
OutputFolder.BindFileSelectionBox(ViewModel, vm => vm.OutputFolder)
2021-10-23 16:51:17 +00:00
.DisposeWith(disposables);
2021-10-23 16:51:17 +00:00
this.OneWayBind(ViewModel, vm => vm.AllGames, view => view.BaseGame.Items)
.DisposeWith(disposables);
2021-10-23 16:51:17 +00:00
this.Bind(ViewModel, vm => vm.BaseGame, view => view.BaseGame.SelectedItem)
.DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.StartCompilation, view => view.StartCompilation)
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.AlwaysEnabled, view => view.AlwaysEnabledList.Items,
d => d!.Select(itm => new RemovableItemViewModel
{
Text = itm.ToString(),
DeleteCommand = ReactiveCommand.Create(() => { ViewModel?.RemoveAlwaysExcluded(itm); })
}))
.DisposeWith(disposables);
2021-11-05 22:58:08 +00:00
this.OneWayBind(ViewModel, vm => vm.OtherProfiles, view => view.OtherProfilesList.Items,
d => d!.Select(itm => new RemovableItemViewModel
{
Text = itm.ToString(),
DeleteCommand = ReactiveCommand.Create(() => { ViewModel?.RemoveOtherProfile(itm); })
}))
.DisposeWith(disposables);
2021-10-23 16:51:17 +00:00
});
}
2021-11-05 22:58:08 +00:00
private async Task AddOtherProfile_Command()
{
var dialog = new OpenFolderDialog
{
Title = "Select a profile folder"
};
var result = await dialog.ShowAsync(App.MainWindow);
if (!string.IsNullOrWhiteSpace(result))
ViewModel!.AddOtherProfile(result.ToAbsolutePath());
}
2021-10-23 16:51:17 +00:00
private async Task AddAlwaysEnabled_Command()
{
var dialog = new OpenFolderDialog
{
Title = "Select a folder"
};
var result = await dialog.ShowAsync(App.MainWindow);
if (!string.IsNullOrWhiteSpace(result))
ViewModel!.AddAlwaysExcluded(result.ToAbsolutePath());
}
2021-10-13 21:51:00 +00:00
2021-10-23 16:51:17 +00:00
private void InferSettings_OnClick(object? sender, RoutedEventArgs e)
{
Dispatcher.UIThread.InvokeAsync(async () =>
2021-10-13 21:51:00 +00:00
{
2021-10-23 16:51:17 +00:00
var dialog = new OpenFileDialog
2021-10-13 21:51:00 +00:00
{
2021-10-23 16:51:17 +00:00
Title = "Select a modlist.txt file",
Filters = new List<FileDialogFilter>
{new() {Extensions = new List<string> {"txt"}, Name = "modlist.txt"}},
AllowMultiple = false
2021-10-13 21:51:00 +00:00
};
var result = await dialog.ShowAsync(App.MainWindow);
2021-10-23 16:51:17 +00:00
if (result is {Length: > 0})
await ViewModel!.InferSettingsFromModlistTxt(result.First().ToAbsolutePath());
});
}
}