diff --git a/sources/Directory.Packages.props b/sources/Directory.Packages.props index 764041d30f..997563339e 100644 --- a/sources/Directory.Packages.props +++ b/sources/Directory.Packages.props @@ -11,6 +11,7 @@ + @@ -147,4 +148,4 @@ - + \ No newline at end of file diff --git a/sources/editor/Stride.GameStudio.Avalonia/Services/MarkdownFileViewerService.cs b/sources/editor/Stride.GameStudio.Avalonia/Services/MarkdownFileViewerService.cs new file mode 100644 index 0000000000..61cea34279 --- /dev/null +++ b/sources/editor/Stride.GameStudio.Avalonia/Services/MarkdownFileViewerService.cs @@ -0,0 +1,48 @@ +using System; +using System.IO; +using Avalonia; +using Avalonia.Controls; +using Stride.GameStudio.Avalonia.Views; + +namespace Stride.GameStudio.Avalonia.Services +{ + public static class MarkdownFileViewerService + { + public static void ShowFile(string filePath, string title = "Markdown Viewer") + { + 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(); + } + } +} diff --git a/sources/editor/Stride.GameStudio.Avalonia/Stride.GameStudio.Avalonia.csproj b/sources/editor/Stride.GameStudio.Avalonia/Stride.GameStudio.Avalonia.csproj index b635ce46fc..08a76ef05d 100644 --- a/sources/editor/Stride.GameStudio.Avalonia/Stride.GameStudio.Avalonia.csproj +++ b/sources/editor/Stride.GameStudio.Avalonia/Stride.GameStudio.Avalonia.csproj @@ -34,6 +34,7 @@ + @@ -46,5 +47,11 @@ + + + MarkdownViewerWindow.axaml + + + diff --git a/sources/editor/Stride.GameStudio.Avalonia/Views/AboutWindow.axaml.cs b/sources/editor/Stride.GameStudio.Avalonia/Views/AboutWindow.axaml.cs index 7c3343b098..89ed94c1e1 100644 --- a/sources/editor/Stride.GameStudio.Avalonia/Views/AboutWindow.axaml.cs +++ b/sources/editor/Stride.GameStudio.Avalonia/Views/AboutWindow.axaml.cs @@ -6,6 +6,7 @@ using Avalonia.Controls; using Avalonia.Interactivity; using Markdown.Avalonia; +using Stride.GameStudio.Avalonia.Services; namespace Stride.GameStudio.Avalonia.Views; @@ -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"); } } diff --git a/sources/editor/Stride.GameStudio.Avalonia/Views/MarkdownViewerWindow.axaml b/sources/editor/Stride.GameStudio.Avalonia/Views/MarkdownViewerWindow.axaml new file mode 100644 index 0000000000..1382eb7d8b --- /dev/null +++ b/sources/editor/Stride.GameStudio.Avalonia/Views/MarkdownViewerWindow.axaml @@ -0,0 +1,18 @@ + + + + + + diff --git a/sources/editor/Stride.GameStudio.Avalonia/Views/MarkdownViewerWindow.axaml.cs b/sources/editor/Stride.GameStudio.Avalonia/Views/MarkdownViewerWindow.axaml.cs new file mode 100644 index 0000000000..593d8e7d4a --- /dev/null +++ b/sources/editor/Stride.GameStudio.Avalonia/Views/MarkdownViewerWindow.axaml.cs @@ -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("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); + } +} + +