Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sources/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageVersion Include="DotRecast.Recast.Toolset" Version="2024.3.1" />
<PackageVersion Include="FFmpeg.AutoGen" Version="3.4.0.2" />
<PackageVersion Include="K4os.Compression.LZ4.Legacy" Version="1.3.6" />
<PackageVersion Include="Markdown.Avalonia" Version="11.0.2" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packages are grouped depending on their runtime or design dependency. Here it is only used by the GaleStudio so it should be next to the other Avalonia dependencies.

<PackageVersion Include="Microsoft.Management.Infrastructure" Version="3.0.0-preview.4" />
<PackageVersion Include="Microsoft.NETCore.Platforms" Version="7.0.4" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
Expand Down Expand Up @@ -147,4 +148,4 @@
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" PrivateAssets="all" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this shouldn't be necessary thanks to implicit usings.

using System.IO;
using Avalonia;
using Avalonia.Controls;
using Stride.GameStudio.Avalonia.Views;

namespace Stride.GameStudio.Avalonia.Services
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use file scope namespace

{
public static class MarkdownFileViewerService
{
public static void ShowFile(string filePath, string title = "Markdown Viewer")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this helper method should be made async. Have a look at the other dialog implementations in the DialogService.

{
try
{
if (!File.Exists(filePath))
{
ShowError($"We are facing some technical challenges to fetch the content: {filePath}", title);
return;
}

string markdownContent = File.ReadAllText(filePath);
var window = new MarkdownViewerWindow(markdownContent, title);
window.Show();
}
catch (Exception ex)
{
ShowError($"Failed to open markdown file:\n{ex.Message}", title);
}
}

private static void ShowError(string message, string title)
{
var errorWindow = new Window
{
Title = title,
Width = 400,
Height = 200,
Content = new TextBlock
{
Text = message,
Margin = new Thickness(20)
},
WindowStartupLocation = WindowStartupLocation.CenterScreen
};
errorWindow.Show();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<PackageReference Include="Avalonia.Fonts.Inter" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" />
<PackageReference Include="Markdown.Avalonia" />
<PackageReference Include="Xaml.Behaviors.Interactions" />
</ItemGroup>

Expand All @@ -46,5 +47,11 @@
<ProjectReference Include="..\Stride.Assets.Editor.Avalonia\Stride.Assets.Editor.Avalonia.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Views\MarkdownViewerWindow.axaml.cs">
<DependentUpon>MarkdownViewerWindow.axaml</DependentUpon>
</Compile>
</ItemGroup>
Comment on lines +50 to +54
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.axaml files and their .cs counterpart are detected automatically. There is no need to add them to the project file.


<Import Project="$(StrideSdkTargets)" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Markdown.Avalonia;
using Stride.GameStudio.Avalonia.Services;

namespace Stride.GameStudio.Avalonia.Views;

Expand Down Expand Up @@ -54,11 +55,11 @@ private static void OpenLink(string url)

private void License_OnClick(object? sender, RoutedEventArgs e)
{
OpenLink("LICENSE.md");
MarkdownFileViewerService.ShowFile("LICENSE.md", "License");
}

private void ThirdParty_OnClick(object? sender, RoutedEventArgs e)
{
OpenLink("THIRD PARTY.md");
MarkdownFileViewerService.ShowFile("THIRD PARTY.md", "Third Party Licenses");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:markdown="clr-namespace:Markdown.Avalonia;assembly=Markdown.Avalonia"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:md="https://github.com/whistyun/Markdown.Avalonia.Tight"
xmlns:sd="http://schemas.stride3d.net/xaml/presentation"
x:Class="Stride.GameStudio.Avalonia.Views.MarkdownViewerWindow"
Width="600" Height="300"
Icon="/Assets/GameStudio.ico"
Title="{sd:LocalizeString About Stride, Context=About}" ShowInTaskbar="False"
CanResize="False" SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterOwner">

<ScrollViewer Margin="10">
<markdown:MarkdownScrollViewer x:Name="MarkdownViewer" />
</ScrollViewer>
</Window>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.

using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Markdown.Avalonia;

namespace Stride.GameStudio.Avalonia.Views;

public partial class MarkdownViewerWindow : Window
{
private MarkdownScrollViewer? _markdownViewer;

public MarkdownViewerWindow(string markdownText, string title = "Markdown Viewer")
{
InitializeComponent();

Title = title;

_markdownViewer = this.FindControl<MarkdownScrollViewer>("MarkdownViewer");

if (_markdownViewer is not null)
{
_markdownViewer.Markdown = markdownText;
}
else
{
Content = new TextBlock
{
Text = "Error: Markdown viewer could not be loaded.",
Margin = new Thickness(20)
};
}
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
Comment on lines +37 to +40
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be generated automatically by the analyzers provided by Avalonia libraries.

}