Skip to content

Commit

Permalink
"設定 > 情報"ページにバージョンの表示を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
yuto-trd committed Aug 21, 2023
1 parent b30f8ad commit 20e3aa6
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 34 deletions.
9 changes: 9 additions & 0 deletions src/Beutl.Language/SettingsPage.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Beutl.Language/SettingsPage.ja.resx
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,7 @@
<data name="This_file_extension_already_exists" xml:space="preserve">
<value>この拡張子は既に存在しています。</value>
</data>
<data name="CopyVersionInfo" xml:space="preserve">
<value>バージョン情報をコピー</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/Beutl.Language/SettingsPage.resx
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,7 @@
<data name="This_file_extension_already_exists" xml:space="preserve">
<value>This file extension already exists.</value>
</data>
<data name="CopyVersionInfo" xml:space="preserve">
<value>Copy version info</value>
</data>
</root>
18 changes: 18 additions & 0 deletions src/Beutl/Assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 26 additions & 17 deletions src/Beutl/Pages/SettingsPage.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,22 @@ public SettingsPage()
});
}

//protected override async void OnDataContextChanged(EventArgs e)
//{
// base.OnDataContextChanged(e);
// if (DataContext is SettingsPageViewModel settingsPage)
// {
// await _navigationProvider.NavigateAsync(_ => true, () => settingsPage.Account);
// }
//}
protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);
if (DataContext is SettingsPageViewModel settingsPage)
{
settingsPage.NavigateRequested.Subscribe(OnNavigateRequested);
}
}

private void OnNavigateRequested(object obj)
{
Type pageType = _pageResolver.GetPageType(obj.GetType());

NavigationTransitionInfo transitionInfo = SharedNavigationTransitionInfo.Instance;
frame.Navigate(pageType, obj, transitionInfo);
}

private static List<NavigationViewItem> GetItems()
{
Expand Down Expand Up @@ -136,15 +144,16 @@ private void OnItemInvoked(NavigationViewItem nvi)
&& DataContext is SettingsPageViewModel settingsPage)
{
NavigationTransitionInfo transitionInfo = SharedNavigationTransitionInfo.Instance;
object? parameter = null;
if (typ == typeof(AccountSettingsPage))
{
parameter = settingsPage.Account;
}
else if (typ == typeof(StorageSettingsPage))
{
parameter = settingsPage.Storage;
}
object? parameter = typ.Name switch
{
"AccountSettingsPage" => settingsPage.Account,
"ViewSettingsPage" => settingsPage.View,
"FontSettingsPage" => settingsPage.Font,
"ExtensionsSettingsPage" => settingsPage.ExtensionsPage,
"StorageSettingsPage" => settingsPage.Storage,
"InfomationPage" => settingsPage.Infomation,
_ => null,
};

frame.Navigate(typ, parameter, transitionInfo);
}
Expand Down
3 changes: 0 additions & 3 deletions src/Beutl/Pages/SettingsPages/FontSettingsPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
d:DesignWidth="800"
x:DataType="vm:FontSettingsPageViewModel"
mc:Ignorable="d">
<UserControl.DataContext>
<vm:FontSettingsPageViewModel />
</UserControl.DataContext>
<StackPanel Margin="10,0">
<ui:CommandBar DefaultLabelPosition="Right">
<ui:CommandBar.PrimaryCommands>
Expand Down
49 changes: 44 additions & 5 deletions src/Beutl/Pages/SettingsPages/InfomationPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,66 @@
xmlns:lang="using:Beutl.Language"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="using:FluentAvalonia.UI.Controls"
xmlns:viewModel="using:Beutl.ViewModels.SettingsPages"
d:DesignHeight="450"
d:DesignWidth="800"
x:CompileBindings="True"
x:DataType="viewModel:InfomationPageViewModel"
mc:Ignorable="d">

<ScrollViewer Padding="18">
<StackPanel Margin="10,0"
VerticalAlignment="Stretch"
Orientation="Vertical"
Spacing="4">
<DockPanel Margin="0,0,0,16">
<Image Width="78"
Height="78"
DockPanel.Dock="Left"
RenderOptions.BitmapInterpolationMode="HighQuality"
Source="/Assets/logo.png">
<Image.Clip>
<EllipseGeometry RadiusX="39"
RadiusY="39"
Rect="0,0,78,78" />
</Image.Clip>
</Image>

<Button VerticalAlignment="Bottom"
Click="CopyVersion_Click"
DockPanel.Dock="Right"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Theme="{StaticResource TransparentButton}">
<StackPanel Orientation="Horizontal" Spacing="4">
<ui:SymbolIcon Symbol="Copy" />
<TextBlock Text="{x:Static lang:SettingsPage.CopyVersionInfo}" Theme="{StaticResource CaptionTextBlockStyle}" />
</StackPanel>
</Button>

<StackPanel Margin="12,0"
VerticalAlignment="Center"
Spacing="0">
<TextBlock Text="Beutl" Theme="{StaticResource TitleTextBlockStyle}" />

<TextBlock Text="{Binding CurrentVersion}" Theme="{StaticResource BodyTextBlockStyle}" />

<TextBlock Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Text="{Binding BuildMetadata}"
Theme="{StaticResource CaptionTextBlockStyle}" />
</StackPanel>
</DockPanel>
<ctrls:OptionsDisplayItem Expands="True"
Header="{x:Static lang:Strings.Links}"
Icon="Link">
Icon="Link"
IsExpanded="True">
<ctrls:OptionsDisplayItem.Content>
<Grid Margin="32,16" ColumnDefinitions="*,*">
<StackPanel>
<ui:HyperlinkButton Content="{x:Static lang:Strings.SourceCode}" NavigateUri="https://github.com/b-editor/beutl" />
<ui:HyperlinkButton Content="{x:Static lang:Strings.SourceCode}" NavigateUri="{Binding GitRepositoryUrl}" />
</StackPanel>

<StackPanel Grid.Column="1">
<ui:HyperlinkButton Content="{x:Static lang:Strings.License}" NavigateUri="https://github.com/b-editor/beutl/blob/main/LICENSE" />
<ui:HyperlinkButton Content="{x:Static lang:Strings.ThirdPartyLicenses}" NavigateUri="https://github.com/b-editor/beutl/blob/main/THIRD_PARTY_NOTICES.md" />
<ui:HyperlinkButton Content="{x:Static lang:Strings.License}" NavigateUri="{Binding LicenseUrl}" />
<ui:HyperlinkButton Content="{x:Static lang:Strings.ThirdPartyLicenses}" NavigateUri="{Binding ThirdPartyNoticesUrl}" />
</StackPanel>
</Grid>
</ctrls:OptionsDisplayItem.Content>
Expand Down
13 changes: 12 additions & 1 deletion src/Beutl/Pages/SettingsPages/InfomationPage.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Avalonia.Controls;
#pragma warning disable CS0436

using Avalonia.Controls;
using Avalonia.Interactivity;

namespace Beutl.Pages.SettingsPages;
public sealed partial class InfomationPage : UserControl
Expand All @@ -7,4 +10,12 @@ public InfomationPage()
{
InitializeComponent();
}

private async void CopyVersion_Click(object? sender, RoutedEventArgs e)
{
if (TopLevel.GetTopLevel(this)?.Clipboard is { } clipboard)
{
await clipboard.SetTextAsync(GitVersionInformation.InformationalVersion);
}
}
}
3 changes: 0 additions & 3 deletions src/Beutl/Pages/SettingsPages/ViewSettingsPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
d:DesignWidth="800"
x:DataType="vm:ViewSettingsPageViewModel"
mc:Ignorable="d">
<UserControl.DataContext>
<vm:ViewSettingsPageViewModel />
</UserControl.DataContext>
<ScrollViewer Padding="18">
<StackPanel Margin="10,0"
VerticalAlignment="Stretch"
Expand Down
3 changes: 1 addition & 2 deletions src/Beutl/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public MainViewModel()
_logger = Log.ForContext<MainViewModel>();
_authorizedHttpClient = new HttpClient();
_beutlClients = new BeutlApiApplication(_authorizedHttpClient);
ExtensionProvider.Current = _beutlClients.GetResource<ExtensionProvider>();

_primitivePageExtensions = new PageExtension[]
{
Expand Down Expand Up @@ -502,8 +503,6 @@ public EditorExtension[] GetEditorExtensions()

public void RegisterServices()
{
ExtensionProvider.Current = _beutlClients.GetResource<ExtensionProvider>();

if (Application.Current is { ApplicationLifetime: IControlledApplicationLifetime lifetime })
{
lifetime.Exit += OnExit;
Expand Down
26 changes: 24 additions & 2 deletions src/Beutl/ViewModels/SettingsPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,48 @@
using Beutl.Api;
using Beutl.Extensibility;
using System.Reactive.Subjects;

using Beutl.Api;
using Beutl.Services.PrimitiveImpls;
using Beutl.ViewModels.SettingsPages;

namespace Beutl.ViewModels;

public sealed class SettingsPageViewModel : IPageContext
{
private readonly Subject<object> _navigateRequested = new();

public SettingsPageViewModel(BeutlApiApplication clients)
{
Account = new AccountSettingsPageViewModel(clients);
View = new ViewSettingsPageViewModel();
Font = new FontSettingsPageViewModel();
ExtensionsPage = new ExtensionsSettingsPageViewModel();
Storage = new StorageSettingsPageViewModel(clients.AuthorizedUser);
Infomation = new InfomationPageViewModel();
}

public AccountSettingsPageViewModel Account { get; }

public ViewSettingsPageViewModel View { get; }

public FontSettingsPageViewModel Font { get; }

public ExtensionsSettingsPageViewModel ExtensionsPage { get; }

public StorageSettingsPageViewModel Storage { get; }

public InfomationPageViewModel Infomation { get; }

public PageExtension Extension => SettingsPageExtension.Instance;

public string Header => Strings.Settings;

public IObservable<object> NavigateRequested => _navigateRequested;

public void GoToSettingsPage()
{
_navigateRequested.OnNext(Infomation);
}

public void Dispose()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Reactive.Bindings;

namespace Beutl.ViewModels.SettingsPages;

public sealed class FontSettingsPageViewModel : PageContext
{
public FontSettingsPageViewModel()
Expand Down
18 changes: 18 additions & 0 deletions src/Beutl/ViewModels/SettingsPages/InfomationPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma warning disable CS0436

using Beutl.Controls.Navigation;

namespace Beutl.ViewModels.SettingsPages;

public sealed class InfomationPageViewModel : PageContext
{
public string CurrentVersion { get; } = GitVersionInformation.SemVer;

public string BuildMetadata { get; } = GitVersionInformation.FullBuildMetaData;

public string GitRepositoryUrl { get; } = "https://github.com/b-editor/beutl";

public string LicenseUrl { get; } = "https://github.com/b-editor/beutl/blob/main/LICENSE";

public string ThirdPartyNoticesUrl { get; } = "https://github.com/b-editor/beutl/blob/main/THIRD_PARTY_NOTICES.md";
}
1 change: 1 addition & 0 deletions src/Beutl/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
<MenuItem Click="GC_Collect_Click"
Header="GC.Collect"
IsVisible="{Binding IsDebuggerAttached}" />
<MenuItem Click="GoToInfomationPage" Header="{x:Static lang:Strings.Info}" />
</MenuItem>
</Menu>

Expand Down
9 changes: 9 additions & 0 deletions src/Beutl/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,15 @@ private void GC_Collect_Click(object? sender, RoutedEventArgs e)
""");
}

private void GoToInfomationPage(object? sender, RoutedEventArgs e)
{
if (DataContext is MainViewModel viewModel)
{
viewModel.SelectedPage.Value = viewModel.SettingsPage;
(viewModel.SettingsPage.Context as SettingsPageViewModel)?.GoToSettingsPage();
}
}

private void OpenNotificationsClick(object? sender, RoutedEventArgs e)
{
if (HiddenNotificationPanel.Children.Count > 0
Expand Down

0 comments on commit 20e3aa6

Please sign in to comment.