-
-
Notifications
You must be signed in to change notification settings - Fork 1k
No:2743 - 𝐒 Improve GameStudio's About window - Added a new markdown plugin window to show "MIT License" and "See all list" links in the About page #2921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: xplat-editor
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
|
@@ -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> | ||
|
||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
<Import Project="$(StrideSdkTargets)" /> | ||
</Project> |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be generated automatically by the analyzers provided by Avalonia libraries. |
||
} | ||
|
||
|
There was a problem hiding this comment.
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.