Fix file selection for install page

This commit is contained in:
Timothy Baldridge 2021-11-08 19:36:07 -07:00
parent c14d740367
commit 2a03b01e4a
5 changed files with 117 additions and 28 deletions

View File

@ -0,0 +1,41 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Controls.ButtonSettingTextBox">
<UserControl.Styles>
<Style Selector="Button:not(:pointerover) /template/ ContentPresenter">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="LightGray" />
<Setter Property="CornerRadius" Value="0, 5, 5, 0" />
</Style>
<Style Selector="Button:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="LightGray" />
<Setter Property="CornerRadius" Value="0, 5, 5, 0" />
</Style>
<Style Selector="TextBox:not(:focus) /template/ ContentPresenter">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="LightGray" />
<Setter Property="CornerRadius" Value="5, 0, 0, 5" />
</Style>
<Style Selector="TextBox:focus /template/ ContentPresenter">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="LightGray" />
<Setter Property="CornerRadius" Value="5, 0, 0, 5" />
</Style>
</UserControl.Styles>
<Grid ColumnDefinitions="*, 30" Height="30">
<TextBox Grid.Column="0" Name="Path" Height="30" x:Name="TextBox" IsEnabled="False" />
<Button Grid.Column="1" Name="SelectButton" Height="30">
<i:MaterialIcon Kind="Search" />
</Button>
</Grid>
</UserControl>

View File

@ -0,0 +1,12 @@
using Avalonia.Controls;
namespace Wabbajack.App.Controls;
public partial class ButtonSettingTextBox : UserControl
{
public ButtonSettingTextBox()
{
InitializeComponent();
}
}

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
@ -7,6 +8,7 @@ using System.Threading.Tasks;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.ReactiveUI; using Avalonia.ReactiveUI;
using Avalonia.Threading;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
@ -14,11 +16,8 @@ using Wabbajack.Paths;
namespace Wabbajack.App.Controls; namespace Wabbajack.App.Controls;
public partial class FileSelectionBox : UserControl public partial class FileSelectionBox : ReactiveUserControl<FileSelectionBoxViewModel>
{ {
public static readonly DirectProperty<FileSelectionBox, AbsolutePath> SelectedPathProperty =
AvaloniaProperty.RegisterDirect<FileSelectionBox, AbsolutePath>(nameof(SelectedPath), o => o.SelectedPath);
public static readonly StyledProperty<string> AllowedExtensionsProperty = public static readonly StyledProperty<string> AllowedExtensionsProperty =
AvaloniaProperty.Register<FileSelectionBox, string>(nameof(AllowedExtensions)); AvaloniaProperty.Register<FileSelectionBox, string>(nameof(AllowedExtensions));
@ -63,7 +62,7 @@ public partial class FileSelectionBox : UserControl
} }
[Reactive] [Reactive]
public AbsolutePath SelectedPath { get; private set; } public AbsolutePath SelectedPath { get; set; }
public string AllowedExtensions public string AllowedExtensions
{ {
@ -79,7 +78,9 @@ public partial class FileSelectionBox : UserControl
public void Load(AbsolutePath path) public void Load(AbsolutePath path)
{ {
TextBox.Text = path.ToString(); Dispatcher.UIThread.Post(() => {
SelectedPath = path; TextBox.Text = path.ToString();
SelectedPath = path;
});
} }
} }

View File

@ -18,13 +18,13 @@
</Grid> </Grid>
<Grid Margin="40" RowDefinitions="40, 40, 40, *" ColumnDefinitions="100, *, 200" Grid.Row="1"> <Grid Margin="40" RowDefinitions="40, 40, 40, *" ColumnDefinitions="100, *, 200" Grid.Row="1">
<Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Center">ModList:</Label> <Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Center">ModList:</Label>
<controls:FileSelectionBox Grid.Column="1" Grid.Row="0" AllowedExtensions=".wabbajack" x:Name="ModListFile" /> <controls:ButtonSettingTextBox Grid.Column="1" Grid.Row="0" x:Name="ModListFile" />
<Label Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Center">Install To:</Label> <Label Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Center">Install To:</Label>
<controls:FileSelectionBox Grid.Column="1" Grid.Row="1" SelectFolder="True" x:Name="InstallPath" /> <controls:ButtonSettingTextBox Grid.Column="1" Grid.Row="1" x:Name="InstallPath" />
<Label Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center">Download To:</Label> <Label Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center">Download To:</Label>
<controls:FileSelectionBox Grid.Column="1" Grid.Row="2" SelectFolder="True" x:Name="DownloadPath" /> <controls:ButtonSettingTextBox Grid.Column="1" Grid.Row="2" x:Name="DownloadPath" />
<controls:LargeIconButton x:Name="BeginInstall" Margin="40, 0, 0, 0" Grid.Row="0" Grid.Column="2" <controls:LargeIconButton x:Name="BeginInstall" Margin="40, 0, 0, 0" Grid.Row="0" Grid.Column="2"
Grid.RowSpan="4" Icon="DownloadNetwork" Text="Install" /> Grid.RowSpan="4" Icon="DownloadNetwork" Text="Install" />

View File

@ -1,11 +1,18 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.ReactiveUI; using Avalonia.ReactiveUI;
using Avalonia.Threading;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using ReactiveUI; using ReactiveUI;
using Wabbajack.App.Interfaces; using Wabbajack.App.Interfaces;
using Wabbajack.App.ViewModels; using Wabbajack.App.ViewModels;
using Wabbajack.Common;
using Wabbajack.Paths;
namespace Wabbajack.App.Views; namespace Wabbajack.App.Views;
@ -18,30 +25,23 @@ public partial class InstallConfigurationView : ScreenBase<InstallConfigurationV
this.WhenActivated(disposables => this.WhenActivated(disposables =>
{ {
ViewModel.WhenAnyValue(vm => vm.ModListPath) ModListFile.SelectButton.Command = ReactiveCommand.CreateFromTask(SelectWabbajackFile)
.Subscribe(path => ModListFile.Load(path)) .DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.ModListPath, view => view.ModListFile.TextBox.Text)
.DisposeWith(disposables); .DisposeWith(disposables);
ViewModel.WhenAnyValue(vm => vm.Download) InstallPath.SelectButton.Command = ReactiveCommand.CreateFromTask(() =>
.Subscribe(path => DownloadPath.Load(path)) SelectFolder("Select Install Location", p => ViewModel!.Install = p))
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.Install, view => view.InstallPath.TextBox.Text)
.DisposeWith(disposables); .DisposeWith(disposables);
ViewModel.WhenAnyValue(vm => vm.Install) DownloadPath.SelectButton.Command = ReactiveCommand.CreateFromTask(() =>
.Subscribe(path => InstallPath.Load(path)) SelectFolder("Select Download Location", p => ViewModel!.Download = p))
.DisposeWith(disposables); .DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.Download, view => view.DownloadPath.TextBox.Text)
this.WhenAnyValue(view => view.ModListFile.SelectedPath)
.BindTo(ViewModel, vm => vm.ModListPath)
.DisposeWith(disposables); .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) this.OneWayBind(ViewModel, vm => vm.ModListImage, view => view.ModListImage.Source)
.DisposeWith(disposables); .DisposeWith(disposables);
@ -50,5 +50,40 @@ public partial class InstallConfigurationView : ScreenBase<InstallConfigurationV
}); });
} }
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());
});
}
public Type ViewModelType => typeof(InstallConfigurationViewModel); public Type ViewModelType => typeof(InstallConfigurationViewModel);
} }