mirror of
https://github.com/Stone-Red-Code/Markdowser.git
synced 2026-09-04 00:56:13 +02:00
Add basic content processing structure
This commit is contained in:
@@ -7,4 +7,5 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
|
|
||||||
[assembly: SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "<Pending>")]
|
[assembly: SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "<Pending>")]
|
||||||
[assembly: SuppressMessage("Minor Code Smell", "CS0067:The event 'ChangeThemeCommand.CanExecuteChanged' is never used", Justification = "<Pending>", Scope = "member", Target = "~N:Markdowser.Commands")]
|
[assembly: SuppressMessage("Minor Code Smell", "CS0067:The event 'ChangeThemeCommand.CanExecuteChanged' is never used", Justification = "<Pending>", Scope = "member", Target = "~N:Markdowser.Commands")]
|
||||||
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>")]
|
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>")]
|
||||||
|
[assembly: SuppressMessage("Minor Code Smell", "S3267:Loops should be simplified with \"LINQ\" expressions", Justification = "<Pending>", Scope = "member", Target = "~M:Markdowser.Processing.ContentProcessorManager.ProcessContent(System.Net.HttpWebResponse,System.IProgress{Markdowser.Processing.ProcessingProgress})~Markdowser.ViewModels.ContentViewModelBase")]
|
||||||
@@ -37,4 +37,9 @@
|
|||||||
<PackageReference Include="ReverseMarkdown" Version="4.3.0" />
|
<PackageReference Include="ReverseMarkdown" Version="4.3.0" />
|
||||||
<PackageReference Include="Semi.Avalonia" Version="11.0.7.1" />
|
<PackageReference Include="Semi.Avalonia" Version="11.0.7.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Processing\Processors\" />
|
||||||
|
<Folder Include="Views\Content\" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using Markdowser.ViewModels;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Markdowser.Processing;
|
||||||
|
|
||||||
|
internal class ContentProcessorManager
|
||||||
|
{
|
||||||
|
private readonly List<IContentProcessor> processors = [];
|
||||||
|
|
||||||
|
public void RegisterProcessor(IContentProcessor processor)
|
||||||
|
{
|
||||||
|
processors.Add(processor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<ContentViewModelBase> ProcessContent(HttpWebResponse response, IProgress<ProcessingProgress> progress)
|
||||||
|
{
|
||||||
|
IContentProcessor? processor = processors.Find(processor => processor.CanProcess(response)) ?? throw new InvalidOperationException("No processor found for the given response.");
|
||||||
|
return processor.Process(response, progress);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using Markdowser.ViewModels;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Markdowser.Processing;
|
||||||
|
|
||||||
|
internal interface IContentProcessor
|
||||||
|
{
|
||||||
|
bool CanProcess(HttpWebResponse response);
|
||||||
|
|
||||||
|
Task<ContentViewModelBase> Process(HttpWebResponse response, IProgress<ProcessingProgress> progress);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Markdowser.Processing;
|
||||||
|
|
||||||
|
public readonly struct ProcessingProgress(int current, int total)
|
||||||
|
{
|
||||||
|
public int Current { get; } = current;
|
||||||
|
public int Total { get; } = total;
|
||||||
|
|
||||||
|
public double Percentage => (double)Current / Total * 100;
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@ internal static class ColumnDefinition
|
|||||||
}
|
}
|
||||||
else if (!visibility)
|
else if (!visibility)
|
||||||
{
|
{
|
||||||
_ = element.SetValue(LastWidthProperty, element.GetValue(Avalonia.Controls.ColumnDefinition.WidthProperty));
|
_ = element.SetValue(LastWidthProperty!, element.GetValue(Avalonia.Controls.ColumnDefinition.WidthProperty));
|
||||||
_ = element.SetValue(Avalonia.Controls.ColumnDefinition.WidthProperty, ZeroWidth);
|
_ = element.SetValue(Avalonia.Controls.ColumnDefinition.WidthProperty, ZeroWidth);
|
||||||
}
|
}
|
||||||
return visibility;
|
return visibility;
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Markdowser.ViewModels.Content;
|
||||||
|
|
||||||
|
public class MarkdownContentViewModel(string title, string markdown) : ContentViewModelBase(title)
|
||||||
|
{
|
||||||
|
public string Markdown { get; } = markdown;
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Markdowser.ViewModels;
|
||||||
|
|
||||||
|
public abstract class ContentViewModelBase(string title)
|
||||||
|
{
|
||||||
|
public string Title { get; } = title;
|
||||||
|
}
|
||||||
@@ -35,7 +35,6 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||||||
private bool isBusy;
|
private bool isBusy;
|
||||||
private int progress;
|
private int progress;
|
||||||
public ObservableCollection<TabItem> Tabs => GlobalState.Tabs;
|
public ObservableCollection<TabItem> Tabs => GlobalState.Tabs;
|
||||||
public string Title => $"{nameof(Markdowser)} - {Assembly.GetExecutingAssembly().GetName().Version?.ToString()}";
|
|
||||||
|
|
||||||
public TabItem CurrentTab
|
public TabItem CurrentTab
|
||||||
{
|
{
|
||||||
@@ -178,6 +177,8 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||||||
|
|
||||||
GlobalState.ContentReload += (sender, _) =>
|
GlobalState.ContentReload += (sender, _) =>
|
||||||
{
|
{
|
||||||
|
// Updatre icon when dark mode changes
|
||||||
|
this.RaisePropertyChanged(nameof(Icon));
|
||||||
this.RaisePropertyChanged(nameof(Content));
|
this.RaisePropertyChanged(nameof(Content));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,17 @@
|
|||||||
using ReactiveUI;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Platform;
|
||||||
|
|
||||||
|
using Markdowser.Models;
|
||||||
|
|
||||||
|
using ReactiveUI;
|
||||||
|
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Markdowser.ViewModels;
|
namespace Markdowser.ViewModels;
|
||||||
|
|
||||||
public class ViewModelBase : ReactiveObject
|
public class ViewModelBase : ReactiveObject
|
||||||
{
|
{
|
||||||
}
|
public string Title => $"{nameof(Markdowser)} - {Assembly.GetExecutingAssembly().GetName().Version?.ToString()}";
|
||||||
|
|
||||||
|
public WindowIcon Icon => Settings.Current.DarkMode ? new WindowIcon(AssetLoader.Open(new("avares://Markdowser/Assets/Markdowser-Dark-Transparent.ico"))) : new WindowIcon(AssetLoader.Open(new("avares://Markdowser/Assets/Markdowser-Light-Transparent.ico")));
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Markdowser.Views.MainWindow"
|
x:Class="Markdowser.Views.MainWindow"
|
||||||
x:DataType="vm:MainWindowViewModel"
|
x:DataType="vm:MainWindowViewModel"
|
||||||
Icon="/Assets/Markdowser-Light-Transparent.ico"
|
Icon="{Binding Icon}"
|
||||||
Title="{Binding Title}">
|
Title="{Binding Title}">
|
||||||
|
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
|
|||||||
Reference in New Issue
Block a user