mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-12-14 19:36:59 +00:00
combine SetupWizardPage and the builder type since the builder mutated an instance of the built type anyways
This commit is contained in:
parent
aba0049a5e
commit
e54cd90adc
6 changed files with 87 additions and 102 deletions
|
|
@ -11,18 +11,10 @@ namespace Ryujinx.Ava.Systems.SetupWizard
|
|||
/// </summary>
|
||||
public abstract Task Start();
|
||||
|
||||
protected ValueTask<bool> FirstPage()
|
||||
{
|
||||
SetupWizardPageBuilder builder = new(presenter, isFirstPage: true);
|
||||
protected SetupWizardPage FirstPage()
|
||||
=> new(presenter, isFirstPage: true);
|
||||
|
||||
return builder
|
||||
.WithTitle(LocaleKeys.SetupWizardFirstPageTitle)
|
||||
.WithContent(LocaleKeys.SetupWizardFirstPageContent)
|
||||
.WithActionContent(LocaleKeys.SetupWizardFirstPageAction)
|
||||
.Show();
|
||||
}
|
||||
|
||||
protected SetupWizardPageBuilder NextPage()
|
||||
protected SetupWizardPage NextPage()
|
||||
=> new(presenter);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
66
src/Ryujinx/Systems/SetupWizard/SetupWizardPage.Builder.cs
Normal file
66
src/Ryujinx/Systems/SetupWizard/SetupWizardPage.Builder.cs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Ryujinx.Ava.Common.Locale;
|
||||
using Ryujinx.Ava.UI.Controls;
|
||||
using Ryujinx.Ava.UI.ViewModels;
|
||||
|
||||
namespace Ryujinx.Ava.Systems.SetupWizard
|
||||
{
|
||||
public partial class SetupWizardPage
|
||||
{
|
||||
public SetupWizardPage WithTitle(LocaleKeys title) => WithTitle(LocaleManager.Instance[title]);
|
||||
|
||||
public SetupWizardPage WithTitle(string title)
|
||||
{
|
||||
Title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SetupWizardPage WithContent(LocaleKeys content) => WithContent(LocaleManager.Instance[content]);
|
||||
|
||||
public SetupWizardPage WithContent(object? content)
|
||||
{
|
||||
if (content is StyledElement { Parent: ContentControl parent })
|
||||
{
|
||||
parent.Content = null;
|
||||
}
|
||||
|
||||
Content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SetupWizardPage WithHelpContent(LocaleKeys content) =>
|
||||
WithHelpContent(LocaleManager.Instance[content]);
|
||||
|
||||
public SetupWizardPage WithHelpContent(object? content)
|
||||
{
|
||||
HelpContent = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SetupWizardPage WithContent<TControl>(object? context = null) where TControl : Control, new()
|
||||
{
|
||||
Content = new TControl { DataContext = context };
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public SetupWizardPage WithContent<TControl, TViewModel>(out TViewModel boundViewModel)
|
||||
where TControl : RyujinxControl<TViewModel>, new()
|
||||
where TViewModel : BaseModel, new()
|
||||
{
|
||||
boundViewModel = new();
|
||||
|
||||
return WithContent<TControl>(boundViewModel);
|
||||
}
|
||||
|
||||
public SetupWizardPage WithActionContent(LocaleKeys content) =>
|
||||
WithActionContent(LocaleManager.Instance[content]);
|
||||
|
||||
public SetupWizardPage WithActionContent(object? content)
|
||||
{
|
||||
ActionContent = content;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,10 +8,10 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Ryujinx.Ava.Systems.SetupWizard
|
||||
{
|
||||
public partial class SetupWizardPage(bool isFirstPage = false) : BaseModel
|
||||
public partial class SetupWizardPage(ContentPresenter contentPresenter, bool isFirstPage = false) : BaseModel
|
||||
{
|
||||
protected bool? _result;
|
||||
protected readonly CancellationTokenSource _cancellationTokenSource = new();
|
||||
private bool? _result;
|
||||
private readonly CancellationTokenSource _cts = new();
|
||||
|
||||
public bool IsFirstPage { get; } = isFirstPage;
|
||||
|
||||
|
|
@ -30,23 +30,23 @@ namespace Ryujinx.Ava.Systems.SetupWizard
|
|||
private void MoveBack()
|
||||
{
|
||||
_result = false;
|
||||
_cancellationTokenSource.Cancel();
|
||||
_cts.Cancel();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void MoveNext()
|
||||
{
|
||||
_result = true;
|
||||
_cancellationTokenSource.Cancel();
|
||||
_cts.Cancel();
|
||||
}
|
||||
|
||||
public async ValueTask<bool> Show(ContentPresenter presenter)
|
||||
public async ValueTask<bool> Show()
|
||||
{
|
||||
presenter.Content = new SetupWizardPageView { DataContext = this, };
|
||||
contentPresenter.Content = new SetupWizardPageView { ViewModel = this };
|
||||
|
||||
try
|
||||
{
|
||||
await Task.Delay(-1, _cancellationTokenSource.Token);
|
||||
await Task.Delay(-1, _cts.Token);
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,80 +0,0 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Presenters;
|
||||
using Ryujinx.Ava.Common.Locale;
|
||||
using Ryujinx.Ava.UI.Controls;
|
||||
using Ryujinx.Ava.UI.ViewModels;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ryujinx.Ava.Systems.SetupWizard
|
||||
{
|
||||
public class SetupWizardPageBuilder(ContentPresenter presenter, bool isFirstPage = false)
|
||||
{
|
||||
private readonly SetupWizardPage _page = new(isFirstPage);
|
||||
|
||||
public SetupWizardPage Build()
|
||||
{
|
||||
return _page;
|
||||
}
|
||||
|
||||
public SetupWizardPageBuilder WithTitle(LocaleKeys title) => WithTitle(LocaleManager.Instance[title]);
|
||||
|
||||
public SetupWizardPageBuilder WithTitle(string title)
|
||||
{
|
||||
_page.Title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SetupWizardPageBuilder WithContent(LocaleKeys content) => WithContent(LocaleManager.Instance[content]);
|
||||
|
||||
public SetupWizardPageBuilder WithContent(object? content)
|
||||
{
|
||||
if (content is StyledElement { Parent: ContentControl parent })
|
||||
{
|
||||
parent.Content = null;
|
||||
}
|
||||
|
||||
_page.Content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SetupWizardPageBuilder WithHelpContent(LocaleKeys content) =>
|
||||
WithHelpContent(LocaleManager.Instance[content]);
|
||||
|
||||
public SetupWizardPageBuilder WithHelpContent(object? content)
|
||||
{
|
||||
_page.HelpContent = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SetupWizardPageBuilder WithContent<TControl>(object? context = null) where TControl : Control, new()
|
||||
{
|
||||
_page.Content = new TControl { DataContext = context };
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public SetupWizardPageBuilder WithContent<TControl, TViewModel>(out TViewModel boundViewModel)
|
||||
where TControl : RyujinxControl<TViewModel>, new()
|
||||
where TViewModel : BaseModel, new()
|
||||
{
|
||||
boundViewModel = new();
|
||||
|
||||
return WithContent<TControl>(boundViewModel);
|
||||
}
|
||||
|
||||
public SetupWizardPageBuilder WithActionContent(LocaleKeys content) =>
|
||||
WithActionContent(LocaleManager.Instance[content]);
|
||||
|
||||
public SetupWizardPageBuilder WithActionContent(object? content)
|
||||
{
|
||||
_page.ActionContent = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ValueTask<bool> Show()
|
||||
{
|
||||
return _page.Show(presenter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
</DataTemplate>
|
||||
</ContentPresenter.DataTemplates>
|
||||
</ContentPresenter>
|
||||
|
||||
|
||||
<Grid Grid.Row="2"
|
||||
ColumnDefinitions="Auto,*"
|
||||
IsVisible="{Binding #InfoToggle.IsChecked}">
|
||||
|
|
@ -53,7 +53,7 @@
|
|||
Padding="6">
|
||||
<fa:Icon Value="fa-solid fa-circle-info" />
|
||||
</ToggleButton>
|
||||
|
||||
|
||||
<Button IsVisible="{Binding !IsFirstPage}"
|
||||
Grid.Column="1"
|
||||
Content="{ext:Locale SetupWizardActionBack}"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using Avalonia.Controls.Presenters;
|
||||
using Gommon;
|
||||
using Ryujinx.Ava.Common.Locale;
|
||||
using Ryujinx.Ava.Systems.Configuration;
|
||||
|
|
@ -27,7 +28,13 @@ namespace Ryujinx.Ava.UI.SetupWizard
|
|||
NotificationHelper.SetNotificationManager(wizardWindow);
|
||||
RyujinxSetupWizardWindow.IsOpen = true;
|
||||
Start:
|
||||
await FirstPage();
|
||||
await FirstPage()
|
||||
.WithTitle(LocaleKeys.SetupWizardFirstPageTitle)
|
||||
.WithContent(LocaleKeys.SetupWizardFirstPageContent)
|
||||
.WithActionContent(LocaleKeys.SetupWizardFirstPageAction)
|
||||
.Show();
|
||||
// result is unhandled as the first page cannot display anything other than the next button.
|
||||
// back does not need to be handled
|
||||
|
||||
Keys:
|
||||
if (!await SetupKeys())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue