From e547997007b89762f76bd00e08451b721eff31e6 Mon Sep 17 00:00:00 2001 From: Yuto Terada Date: Thu, 5 Sep 2024 19:21:51 +0900 Subject: [PATCH] feat: Display settings page in a dialog --- src/Beutl/App.axaml.cs | 33 ++++++----- ...ettingsPage.axaml => SettingsDialog.axaml} | 6 +- ...sPage.axaml.cs => SettingsDialog.axaml.cs} | 56 ++++++++++--------- .../PrimitiveImpls/SettingsPageExtension.cs | 45 --------------- .../LoadPrimitiveExtensionTask.cs | 1 - src/Beutl/ViewModels/MainViewModel.cs | 3 + src/Beutl/Views/MainView.axaml.cs | 16 +++--- 7 files changed, 64 insertions(+), 96 deletions(-) rename src/Beutl/Pages/{SettingsPage.axaml => SettingsDialog.axaml} (87%) rename src/Beutl/Pages/{SettingsPage.axaml.cs => SettingsDialog.axaml.cs} (86%) delete mode 100644 src/Beutl/Services/PrimitiveImpls/SettingsPageExtension.cs diff --git a/src/Beutl/App.axaml.cs b/src/Beutl/App.axaml.cs index a25dd7c24..b09216667 100644 --- a/src/Beutl/App.axaml.cs +++ b/src/Beutl/App.axaml.cs @@ -14,12 +14,14 @@ using Beutl.Configuration; using Beutl.NodeTree.Nodes; using Beutl.Operators; +using Beutl.Pages; using Beutl.Services; using Beutl.Services.StartupTasks; using Beutl.ViewModels; using Beutl.Views; using FluentAvalonia.Core; using FluentAvalonia.Styling; +using NuGet.Configuration; using Reactive.Bindings; namespace Beutl; @@ -176,22 +178,27 @@ private MainViewModel GetMainViewModel() return _mainViewModel ??= new MainViewModel(); } - private void AboutBeutlClicked(object? sender, EventArgs e) + private async void AboutBeutlClicked(object? sender, EventArgs e) { - // TODO: 情報ウィンドウを表示 - // if (_mainViewModel != null) - // { - // _mainViewModel.SelectedPage.Value = _mainViewModel.SettingsPage; - // (_mainViewModel.SettingsPage.Context as SettingsPageViewModel)?.GoToSettingsPage(); - // } + if (_mainViewModel != null + && ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } window }) + { + var settingsPage = _mainViewModel.SettingsPage; + var dialog = new SettingsDialog { DataContext = settingsPage }; + settingsPage.GoToSettingsPage(); + await dialog.ShowDialog(window); + } } - private void OpenSettingsClicked(object? sender, EventArgs e) + private async void OpenSettingsClicked(object? sender, EventArgs e) { - // if (_mainViewModel != null) - // { - // _mainViewModel.SelectedPage.Value = _mainViewModel.SettingsPage; - // (_mainViewModel.SettingsPage.Context as SettingsPageViewModel)?.GoToAccountSettingsPage(); - // } + if (_mainViewModel != null + && ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } window }) + { + var settingsPage = _mainViewModel.SettingsPage; + var dialog = new SettingsDialog { DataContext = settingsPage }; + settingsPage.GoToAccountSettingsPage(); + await dialog.ShowDialog(window); + } } } diff --git a/src/Beutl/Pages/SettingsPage.axaml b/src/Beutl/Pages/SettingsDialog.axaml similarity index 87% rename from src/Beutl/Pages/SettingsPage.axaml rename to src/Beutl/Pages/SettingsDialog.axaml index 110f4bf6c..030130e8e 100644 --- a/src/Beutl/Pages/SettingsPage.axaml +++ b/src/Beutl/Pages/SettingsDialog.axaml @@ -1,4 +1,4 @@ - - - + + diff --git a/src/Beutl/Pages/SettingsPage.axaml.cs b/src/Beutl/Pages/SettingsDialog.axaml.cs similarity index 86% rename from src/Beutl/Pages/SettingsPage.axaml.cs rename to src/Beutl/Pages/SettingsDialog.axaml.cs index 48e6d0be2..f596b5e38 100644 --- a/src/Beutl/Pages/SettingsPage.axaml.cs +++ b/src/Beutl/Pages/SettingsDialog.axaml.cs @@ -1,28 +1,38 @@ using Avalonia; +using Avalonia.Platform; using Avalonia.Controls; - using Beutl.Controls.Navigation; using Beutl.Logging; using Beutl.Pages.SettingsPages; using Beutl.Services; using Beutl.ViewModels; - using FluentAvalonia.UI.Controls; using FluentAvalonia.UI.Media.Animation; using FluentAvalonia.UI.Navigation; - +using FluentAvalonia.UI.Windowing; using Microsoft.Extensions.Logging; namespace Beutl.Pages; -public sealed partial class SettingsPage : UserControl +public sealed partial class SettingsDialog : AppWindow { private readonly PageResolver _pageResolver; - private readonly ILogger _logger = Log.CreateLogger(); + private readonly ILogger _logger = Log.CreateLogger(); - public SettingsPage() + public SettingsDialog() { InitializeComponent(); + if (OperatingSystem.IsWindows()) + { + TitleBar.ExtendsContentIntoTitleBar = true; + } + else if (OperatingSystem.IsMacOS()) + { + nav.Margin=new Thickness(0, 22, 0, 0); + ExtendClientAreaToDecorationsHint = true; + ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.PreferSystemChrome; + } + _pageResolver = new PageResolver(); _ = new NavigationProvider(frame, _pageResolver); @@ -35,6 +45,9 @@ public SettingsPage() nav.BackRequested += Nav_BackRequested; nav.SelectedItem = selected; +#if DEBUG + this.AttachDevTools(); +#endif } protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) @@ -77,37 +90,25 @@ private static List GetItems() { Content = Strings.Account, Tag = typeof(AccountSettingsPage), - IconSource = new SymbolIconSource - { - Symbol = Symbol.People - } + IconSource = new SymbolIconSource { Symbol = Symbol.People } }, new NavigationViewItem() { Content = Strings.View, Tag = typeof(ViewSettingsPage), - IconSource = new SymbolIconSource - { - Symbol = Symbol.View - } + IconSource = new SymbolIconSource { Symbol = Symbol.View } }, new NavigationViewItem() { Content = Strings.Editor, Tag = typeof(EditorSettingsPage), - IconSource = new SymbolIconSource - { - Symbol = Symbol.Edit - } + IconSource = new SymbolIconSource { Symbol = Symbol.Edit } }, new NavigationViewItem() { Content = Strings.Font, Tag = typeof(FontSettingsPage), - IconSource = new SymbolIconSource - { - Symbol = Symbol.Font - } + IconSource = new SymbolIconSource { Symbol = Symbol.Font } }, new NavigationViewItem() { @@ -209,10 +210,10 @@ public int GetDepth(Type pagetype) return 0; } else if (pagetype == typeof(StorageDetailPage) - || pagetype == typeof(EditorExtensionPriorityPage) - || pagetype == typeof(DecoderPriorityPage) - || pagetype == typeof(TelemetrySettingsPage) - || pagetype == typeof(AnExtensionSettingsPage)) + || pagetype == typeof(EditorExtensionPriorityPage) + || pagetype == typeof(DecoderPriorityPage) + || pagetype == typeof(TelemetrySettingsPage) + || pagetype == typeof(AnExtensionSettingsPage)) { return 1; } @@ -230,7 +231,8 @@ public int GetOrder(Type pagetype) "ViewSettingsPage" => 1, "EditorSettingsPage" => 2, "FontSettingsPage" => 3, - "ExtensionsSettingsPage" or "EditorExtensionPriorityPage" or "DecoderPriorityPage" or "AnExtensionSettingsPage" => 4, + "ExtensionsSettingsPage" or "EditorExtensionPriorityPage" or "DecoderPriorityPage" + or "AnExtensionSettingsPage" => 4, "StorageSettingsPage" or "StorageDetailPage" => 5, "InfomationPage" or "TelemetrySettingsPage" => 6, _ => 0, diff --git a/src/Beutl/Services/PrimitiveImpls/SettingsPageExtension.cs b/src/Beutl/Services/PrimitiveImpls/SettingsPageExtension.cs deleted file mode 100644 index 0d74069ce..000000000 --- a/src/Beutl/Services/PrimitiveImpls/SettingsPageExtension.cs +++ /dev/null @@ -1,45 +0,0 @@ -using Avalonia.Controls; - -using FluentAvalonia.UI.Controls; - -using Symbol = FluentIcons.Common.Symbol; -using SymbolIconSource = FluentIcons.FluentAvalonia.SymbolIconSource; - -namespace Beutl.Services.PrimitiveImpls; - -[PrimitiveImpl] -public sealed class SettingsPageExtension : PageExtension -{ - public static readonly SettingsPageExtension Instance = new(); - - public override string Name => "SettingsPage"; - - public override string DisplayName => "SettingsPage"; - - public override IPageContext CreateContext() - { - throw new InvalidOperationException(); - } - - public override Control CreateControl() - { - return new Pages.SettingsPage(); - } - - public override IconSource GetFilledIcon() - { - return new SymbolIconSource() - { - Symbol = Symbol.Settings, - IsFilled = true - }; - } - - public override IconSource GetRegularIcon() - { - return new SymbolIconSource() - { - Symbol = Symbol.Settings - }; - } -} diff --git a/src/Beutl/Services/StartupTasks/LoadPrimitiveExtensionTask.cs b/src/Beutl/Services/StartupTasks/LoadPrimitiveExtensionTask.cs index 94b58361d..ca3de57ac 100644 --- a/src/Beutl/Services/StartupTasks/LoadPrimitiveExtensionTask.cs +++ b/src/Beutl/Services/StartupTasks/LoadPrimitiveExtensionTask.cs @@ -11,7 +11,6 @@ public sealed class LoadPrimitiveExtensionTask : StartupTask [ ExtensionsPageExtension.Instance, OutputPageExtension.Instance, - SettingsPageExtension.Instance, SceneEditorExtension.Instance, SceneOutputExtension.Instance, SceneProjectItemExtension.Instance, diff --git a/src/Beutl/ViewModels/MainViewModel.cs b/src/Beutl/ViewModels/MainViewModel.cs index 00d98ea58..9fa7b6203 100644 --- a/src/Beutl/ViewModels/MainViewModel.cs +++ b/src/Beutl/ViewModels/MainViewModel.cs @@ -28,6 +28,7 @@ public MainViewModel() { _authorizedHttpClient = new HttpClient(); _beutlClients = new BeutlApiApplication(_authorizedHttpClient); + SettingsPage = new SettingsPageViewModel(_beutlClients); MenuBar = new MenuBarViewModel(); @@ -83,6 +84,8 @@ public MainViewModel() public ReadOnlyObservableCollection EditorExtensions { get; } + public SettingsPageViewModel SettingsPage { get; } + public Startup RunStartupTask() { IsRunningStartupTasks.Value = true; diff --git a/src/Beutl/Views/MainView.axaml.cs b/src/Beutl/Views/MainView.axaml.cs index b4b52869a..f95173534 100644 --- a/src/Beutl/Views/MainView.axaml.cs +++ b/src/Beutl/Views/MainView.axaml.cs @@ -8,6 +8,7 @@ using Beutl.Configuration; using Beutl.Logging; +using Beutl.Pages; using Beutl.Services; using Beutl.Utilities; using Beutl.ViewModels; @@ -281,14 +282,15 @@ private void ThrowUnhandledException_Click(object? sender, RoutedEventArgs e) throw new Exception("An unhandled exception occurred."); } - private void GoToInfomationPage(object? sender, RoutedEventArgs e) + private async void GoToInfomationPage(object? sender, RoutedEventArgs e) { - // TODO: 情報ウィンドウを開く - // if (DataContext is MainViewModel viewModel) - // { - // viewModel.SelectedPage.Value = viewModel.SettingsPage; - // (viewModel.SettingsPage.Context as SettingsPageViewModel)?.GoToSettingsPage(); - // } + if (DataContext is MainViewModel viewModel && TopLevel.GetTopLevel(this) is Window window) + { + var settingsPage = viewModel.SettingsPage; + var dialog = new SettingsDialog { DataContext = settingsPage }; + settingsPage.GoToSettingsPage(); + await dialog.ShowDialog(window); + } } private void OpenNotificationsClick(object? sender, RoutedEventArgs e)