mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Plugins - Added help pages
This commit is contained in:
1 parent
b59e898dd3
commit
949106e470
12 files changed
+134
-43
No files matched your search
@@ -3,25 +3,13 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:avalonia="clr-namespace:Markdown.Avalonia;assembly=Markdown.Avalonia"
|
||||
xmlns:plugins="clr-namespace:Artemis.UI.Screens.Plugins"
|
||||
xmlns:ctxt="clr-namespace:ColorTextBlock.Avalonia;assembly=ColorTextBlock.Avalonia"
|
||||
xmlns:help="clr-namespace:Artemis.UI.Screens.Plugins.Help"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Plugins.Help.MarkdownPluginHelpPageView"
|
||||
x:DataType="help:MarkdownPluginHelpPageViewModel">
|
||||
<avalonia:MarkdownScrollViewer Markdown="{CompiledBinding MarkdownText}" MarkdownStyleName="FluentAvalonia">
|
||||
<avalonia:MarkdownScrollViewer.Styles>
|
||||
<Style Selector="ctxt|CHyperlink">
|
||||
<Setter Property="Foreground" Value="{DynamicResource SystemAccentColorLight3}" />
|
||||
</Style>
|
||||
<Style Selector="ctxt|CHyperlink:pointerover">
|
||||
<Setter Property="Foreground" Value="{DynamicResource SystemAccentColorLight1}" />
|
||||
</Style>
|
||||
<Style Selector="Grid.List">
|
||||
<Style.Setters>
|
||||
<Setter Property="Margin" Value="20,0,0,0"/>
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
<StyleInclude Source="/Styles/Markdown.axaml"/>
|
||||
</avalonia:MarkdownScrollViewer.Styles>
|
||||
</avalonia:MarkdownScrollViewer>
|
||||
</UserControl>
|
||||
@@ -1,9 +1,10 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Plugins.Help;
|
||||
|
||||
public partial class MarkdownPluginHelpPageView : UserControl
|
||||
public partial class MarkdownPluginHelpPageView : ReactiveUserControl<MarkdownPluginHelpPageViewModel>
|
||||
{
|
||||
public MarkdownPluginHelpPageView()
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Threading.Tasks;
|
||||
@@ -9,13 +10,23 @@ namespace Artemis.UI.Screens.Plugins.Help;
|
||||
|
||||
public class MarkdownPluginHelpPageViewModel : ActivatableViewModelBase, IPluginHelpPage
|
||||
{
|
||||
private string? _markdownText;
|
||||
private readonly MarkdownPluginHelpPage _helpPage;
|
||||
private string? _markdownText;
|
||||
|
||||
public MarkdownPluginHelpPageViewModel(MarkdownPluginHelpPage helpPage)
|
||||
{
|
||||
_helpPage = helpPage;
|
||||
this.WhenActivated(d => Load().DisposeWith(d));
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
FileSystemWatcher watcher = new();
|
||||
watcher.Path = Path.GetDirectoryName(_helpPage.MarkdownFile) ?? throw new InvalidOperationException($"Path \"{_helpPage.MarkdownFile}\" does not contain a directory");
|
||||
watcher.Filter = Path.GetFileName(_helpPage.MarkdownFile);
|
||||
watcher.EnableRaisingEvents = true;
|
||||
watcher.Changed += WatcherOnChanged;
|
||||
watcher.DisposeWith(d);
|
||||
|
||||
LoadMarkdown().DisposeWith(d);
|
||||
});
|
||||
}
|
||||
|
||||
public string? MarkdownText
|
||||
@@ -24,6 +35,25 @@ public class MarkdownPluginHelpPageViewModel : ActivatableViewModelBase, IPlugin
|
||||
set => RaiseAndSetIfChanged(ref _markdownText, value);
|
||||
}
|
||||
|
||||
private async void WatcherOnChanged(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
await LoadMarkdown();
|
||||
}
|
||||
|
||||
private async Task LoadMarkdown()
|
||||
{
|
||||
try
|
||||
{
|
||||
await using FileStream stream = new(_helpPage.MarkdownFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
using StreamReader reader = new(stream);
|
||||
MarkdownText = await reader.ReadToEndAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MarkdownText = e.Message;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Plugin Plugin => _helpPage.Plugin;
|
||||
|
||||
@@ -32,9 +62,4 @@ public class MarkdownPluginHelpPageViewModel : ActivatableViewModelBase, IPlugin
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Id => _helpPage.Id;
|
||||
|
||||
private async Task Load()
|
||||
{
|
||||
MarkdownText ??= await File.ReadAllTextAsync(_helpPage.MarkdownFile);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
x:DataType="help:PluginHelpWindowViewModel"
|
||||
Icon="/Assets/Images/Logo/application.ico"
|
||||
Title="{CompiledBinding DisplayName}"
|
||||
Width="800"
|
||||
Width="1200"
|
||||
Height="800"
|
||||
WindowStartupLocation="CenterOwner">
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<ListBox Items="{CompiledBinding HelpPages}" SelectedItem="{CompiledBinding SelectedHelpPage}" Grid.Column="0" Margin="10">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="core:IPluginHelpPage">
|
||||
<TextBlock Text="{CompiledBinding Title}"/>
|
||||
<TextBlock Text="{CompiledBinding Title}" VerticalAlignment="Center" />
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
@@ -28,4 +28,4 @@
|
||||
|
||||
<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Classes="notification-container" Name="NotificationContainer" VerticalAlignment="Bottom" HorizontalAlignment="Right" />
|
||||
</Grid>
|
||||
</Window>
|
||||
</Window>
|
||||
@@ -1,10 +1,11 @@
|
||||
using Artemis.UI.Shared;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Artemis.UI.Screens.Plugins.Help;
|
||||
|
||||
public partial class PluginHelpWindowView : Window
|
||||
public partial class PluginHelpWindowView : ReactiveAppWindow<PluginHelpWindowViewModel>
|
||||
{
|
||||
public PluginHelpWindowView()
|
||||
{
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
IsVisible="{CompiledBinding HasHelpPages}"
|
||||
Command="{CompiledBinding OpenHelp}"
|
||||
ToolTip.Tip="View help pages">
|
||||
<avalonia:MaterialIcon Kind="Help" />
|
||||
<avalonia:MaterialIcon Kind="HelpCircle" />
|
||||
</controls:HyperlinkButton>
|
||||
<controls:HyperlinkButton Classes="icon-button icon-button-large"
|
||||
IsVisible="{CompiledBinding Plugin.Info.Website, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
||||
|
||||
@@ -230,9 +230,6 @@ public class PluginViewModel : ActivatableViewModelBase
|
||||
|
||||
private void ExecuteOpenHelp()
|
||||
{
|
||||
if (Plugin.ConfigurationDialog == null)
|
||||
return;
|
||||
|
||||
if (_helpWindow != null)
|
||||
{
|
||||
_helpWindow.WindowState = WindowState.Normal;
|
||||
|
||||
Reference in new issue
Block a user