Skip to content

Commit

Permalink
feat: Display settings page in a dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
yuto-trd committed Sep 5, 2024
1 parent 2c6b847 commit e547997
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 96 deletions.
33 changes: 20 additions & 13 deletions src/Beutl/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<UserControl x:Class="Beutl.Pages.SettingsPage"
<UserControl x:Class="Beutl.Pages.SettingsDialog"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand All @@ -20,7 +20,7 @@
<Setter Property="CornerRadius" Value="{DynamicResource NavigationViewContentGridCornerRadius}" />
</Style>
</ui:NavigationView.Styles>
<!-- InvalidCastException対策に{x:Null}を指定 -->
<ui:Frame DataContext="{x:Null}" x:Name="frame" />
<!-- InvalidCastException対策に{x:Null}を指定 -->
<ui:Frame x:Name="frame" DataContext="{x:Null}" />
</ui:NavigationView>
</UserControl>
Original file line number Diff line number Diff line change
@@ -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<SettingsPage>();
private readonly ILogger _logger = Log.CreateLogger<SettingsDialog>();

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);

Expand All @@ -35,6 +45,9 @@ public SettingsPage()
nav.BackRequested += Nav_BackRequested;

nav.SelectedItem = selected;
#if DEBUG
this.AttachDevTools();
#endif
}

protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
Expand Down Expand Up @@ -77,37 +90,25 @@ private static List<NavigationViewItem> 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()
{
Expand Down Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down
45 changes: 0 additions & 45 deletions src/Beutl/Services/PrimitiveImpls/SettingsPageExtension.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public sealed class LoadPrimitiveExtensionTask : StartupTask
[
ExtensionsPageExtension.Instance,
OutputPageExtension.Instance,
SettingsPageExtension.Instance,
SceneEditorExtension.Instance,
SceneOutputExtension.Instance,
SceneProjectItemExtension.Instance,
Expand Down
3 changes: 3 additions & 0 deletions src/Beutl/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public MainViewModel()
{
_authorizedHttpClient = new HttpClient();
_beutlClients = new BeutlApiApplication(_authorizedHttpClient);
SettingsPage = new SettingsPageViewModel(_beutlClients);

MenuBar = new MenuBarViewModel();

Expand Down Expand Up @@ -83,6 +84,8 @@ public MainViewModel()

public ReadOnlyObservableCollection<EditorExtension> EditorExtensions { get; }

public SettingsPageViewModel SettingsPage { get; }

public Startup RunStartupTask()
{
IsRunningStartupTasks.Value = true;
Expand Down
16 changes: 9 additions & 7 deletions src/Beutl/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

using Beutl.Configuration;
using Beutl.Logging;
using Beutl.Pages;
using Beutl.Services;
using Beutl.Utilities;
using Beutl.ViewModels;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e547997

Please sign in to comment.