diff --git a/.all-contributorsrc b/.all-contributorsrc index 6212305f9b..b8a34941ef 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -14,7 +14,7 @@ "login": "neon-nyan", "name": "Kemal Setya Adhi", "avatar_url": "https://avatars.githubusercontent.com/u/30566970?v=4", - "profile": "https://prophost.ironmaid.xyz", + "profile": "https://github.com/neon-nyan", "contributions": [ "code", "design", @@ -208,10 +208,10 @@ ] }, { - "login": "kujou-kju", - "name": "kujou", + "login": "puyomi2k", + "name": "puyomi", "avatar_url": "https://avatars.githubusercontent.com/u/23724383?v=4", - "profile": "https://github.com/kujou-kju", + "profile": "https://github.com/puyomi2k", "contributions": [ "translation" ] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 58d696013a..91742fc5e1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,6 @@ on: push: branches: - 'main' - - '1.83.x-staging' paths-ignore: - '**.md' - 'Hi3Helper.Core/Lang/**.json' @@ -29,12 +28,12 @@ env: jobs: build: - runs-on: windows-latest + runs-on: windows-2025-vs2026 strategy: matrix: configuration: [Debug] # No need to distribute Debug builds platform: [x64] - framework: [net9.0-windows10.0.26100.0] + framework: [net10.0-windows10.0.26100.0] env: Configuration: ${{ matrix.configuration }} @@ -85,12 +84,12 @@ jobs: dotnet build CollapseLauncher -c Publish --verbosity quiet --no-restore build-nativeaot: - runs-on: windows-latest + runs-on: windows-2025-vs2026 strategy: matrix: configuration: [Debug] platform: [x64] - framework: [net9.0-windows10.0.26100.0] + framework: [net10.0-windows10.0.26100.0] env: Configuration: ${{ matrix.configuration }} diff --git a/.github/workflows/release-winget.yml b/.github/workflows/release-winget.yml index fc32f81f50..b2ef5138cc 100644 --- a/.github/workflows/release-winget.yml +++ b/.github/workflows/release-winget.yml @@ -1,36 +1,63 @@ name: Publish Stable & Preview builds to WinGet on: release: - types: [released] + types: [released, prereleased] + workflow_dispatch: + inputs: + version: + description: 'Version to publish (e.g. 1.2.3)' + required: true + type: string + channel: + description: 'Release channel' + required: true + type: choice + options: + - Stable + - Preview + release-tag: + description: 'Release tag to fetch installers from (e.g. CL-1.2.3)' + required: true + type: string jobs: determine_channel: runs-on: ubuntu-latest outputs: channel: ${{ steps.check.outputs.channel }} version: ${{ steps.check.outputs.version }} + release-tag: ${{ steps.check.outputs.release-tag }} steps: - name: Check Release Name and Extract Version id: check # Find X.Y.Z version, then check for "Preview" after it for regex run: | - RELEASE_NAME="${{ github.event.release.name }}" - if [[ "$RELEASE_NAME" =~ (\d+\.\d+\.\d+) ]]; then - VERSION="${BASH_REMATCH[1]}" + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + VERSION="${{ inputs.version }}" + CHANNEL="${{ inputs.channel }}" + RELEASE_TAG="${{ inputs.release-tag }}" else - echo "Error: Could not find X.Y.Z version in release name." - exit 1 - fi + RELEASE_NAME="${{ github.event.release.name }}" + RELEASE_TAG="${{ github.event.release.tag_name }}" + if [[ "$RELEASE_NAME" =~ (\d+\.\d+\.\d+) ]]; then + VERSION="${BASH_REMATCH[1]}" + else + echo "Error: Could not find X.Y.Z version in release name." + exit 1 + fi - if [[ "$RELEASE_NAME" == *"Preview"* ]]; then - CHANNEL="Preview" - else - CHANNEL="Stable" + if [[ "$RELEASE_NAME" == *"Preview"* ]]; then + CHANNEL="Preview" + else + CHANNEL="Stable" + fi fi echo "Detected Channel: $CHANNEL" echo "Detected Version: $VERSION" + echo "Detected Release Tag: $RELEASE_TAG" echo "channel=$CHANNEL" >> $GITHUB_OUTPUT echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "release-tag=$RELEASE_TAG" >> $GITHUB_OUTPUT publish_stable: needs: determine_channel @@ -42,6 +69,7 @@ jobs: with: identifier: CollapseLauncher.Collapse version: ${{ needs.determine_channel.outputs.version }} + release-tag: ${{ needs.determine_channel.outputs.release-tag }} installers-regex: '\.exe$' token: ${{ secrets.WINGET_TOKEN }} @@ -55,5 +83,6 @@ jobs: with: identifier: CollapseLauncher.Collapse.Preview version: ${{ needs.determine_channel.outputs.version }} + release-tag: ${{ needs.determine_channel.outputs.release-tag }} installers-regex: '\.exe$' token: ${{ secrets.WINGET_TOKEN }} diff --git a/.gitignore b/.gitignore index 9801964fd6..ab26cb877f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,15 @@ .vs/* *.user packages/* +msbuild.binlog CollapseLauncher/Deps/* +CollapseLauncher/StaticLib/buildScript/waifu2x-ncnn-vulkan +CollapseLauncher/StaticLib/buildScript/zlib +CollapseLauncher/StaticLib/buildScript/zstd +CollapseLauncher/StaticLib/buildScript/dav1d +CollapseLauncher/StaticLib/buildScript/llvm-project +CollapseLauncher/StaticLib/buildScript/lib* CollapseLauncher/StaticLib/*.lib CollapseLauncher/StaticLib/**/*.lib CollapseLauncher/StaticLib/*.pdb diff --git a/ClearCache.bat b/ClearCache.bat index c427227604..8c75a50f9d 100644 --- a/ClearCache.bat +++ b/ClearCache.bat @@ -1,33 +1,31 @@ @echo off -echo Clearing Collapse cache +echo Clearing Collapse cache rmdir /S /Q CollapseLauncher\bin && rmdir /S /Q CollapseLauncher\obj -echo Clearing ColorThief cache +echo Clearing ColorThief cache rmdir /S /Q ColorThief\ColorThief\bin && rmdir /S /Q ColorThief\ColorThief\obj -echo Clearing CommunityToolkit.ImageCropper cache +echo Clearing CommunityToolkit.ImageCropper cache rmdir /S /Q Hi3Helper.CommunityToolkit\ImageCropper\bin && rmdir /S /Q Hi3Helper.CommunityToolkit\ImageCropper\obj -echo Clearing CommunityToolkit.SettingsControls cache +echo Clearing CommunityToolkit.SettingsControls cache rmdir /S /Q Hi3Helper.CommunityToolkit\SettingsControls\bin && rmdir /S /Q Hi3Helper.CommunityToolkit\SettingsControls\obj -echo Clearing Core cache +echo Clearing Core cache rmdir /S /Q Hi3Helper.Core\bin && rmdir /S /Q Hi3Helper.Core\obj -echo Clearing EncTool cache +echo Clearing EncTool cache rmdir /S /Q Hi3Helper.EncTool\bin && rmdir /S /Q Hi3Helper.EncTool\obj -echo Clearing EncTool tester cache -rmdir /S /Q Hi3Helper.EncTool.Test\bin && rmdir /S /Q Hi3Helper.EncTool.Test\obj -echo Clearing Http cache +echo Clearing Http cache rmdir /S /Q Hi3Helper.Http\bin && rmdir /S /Q Hi3Helper.Http\obj -echo Clearing Http tester cache -rmdir /S /Q Hi3Helper.Http\Test\bin && rmdir /S /Q Hi3Helper.Http\Test\obj -echo Clearing TaskScheduler cache +echo Clearing TaskScheduler cache rmdir /S /Q Hi3Helper.TaskScheduler\bin && rmdir /S /Q Hi3Helper.TaskScheduler\obj -echo Clearing HDiff cache -rmdir /S /Q Hi3Helper.SharpHDiffPatch\Hi3Helper.SharpHDiffPatch\bin && rmdir /S /Q Hi3Helper.SharpHDiffPatch\Hi3Helper.SharpHDiffPatch\obj -echo Clearing 2nd HDiff cache -rmdir /S /Q Hi3Helper.SharpHDiffPatch\SharpHDiffPatch\bin && rmdir /S /Q Hi3Helper.SharpHDiffPatch\SharpHDiffPatch\obj -echo Clearing InnoSetupHelper cache +echo Clearing InnoSetupHelper cache rmdir /S /Q InnoSetupHelper\bin && rmdir /S /Q InnoSetupHelper\obj -echo Clearing ImageEx cache +echo Clearing ImageEx cache rmdir /S /Q ImageEx\ImageEx\bin && rmdir /S /Q ImageEx\ImageEx\obj -echo Clearing 7z cache -rmdir /S /Q Hi3Helper.Core\Classes\Data\Tools\SevenZipTool\SevenZipExtractor\SevenZipExtractor\bin && rmdir /S /Q Hi3Helper.Core\Classes\Data\Tools\SevenZipTool\SevenZipExtractor\SevenZipExtractor\obj -echo Clearing SharpDiscordRPC cache -rmdir /S /Q Hi3Helper.SharpDiscordRPC\DiscordRPC\bin && rmdir /S /Q Hi3Helper.SharpDiscordRPC\DiscordRPC\obj \ No newline at end of file +echo Clearing 7z cache +rmdir /S /Q SevenZipExtractor\SevenZipExtractor\bin && rmdir /S /Q SevenZipExtractor\SevenZipExtractor\obj +echo Clearing SharpDiscordRPC cache +rmdir /S /Q Hi3Helper.SharpDiscordRPC\DiscordRPC\bin && rmdir /S /Q Hi3Helper.SharpDiscordRPC\DiscordRPC\obj +echo Clearing Hi3Helper.SourceGen cache +rmdir /S /Q Hi3Helper.SourceGen\bin && rmdir /S /Q Hi3Helper.SourceGen\obj +echo Clearing Hi3Helper.LocaleSourceGen cache +rmdir /S /Q Hi3Helper.LocaleSourceGen\bin && rmdir /S /Q Hi3Helper.LocaleSourceGen\obj +echo Clearing Hi3Helper.Plugin.Core cache +rmdir /S /Q Hi3Helper.Plugin.Core\bin && rmdir /S /Q Hi3Helper.Plugin.Core\obj \ No newline at end of file diff --git a/CollapseLauncher.slnx b/CollapseLauncher.slnx index 0d3547d0fe..b9c1c02b68 100644 --- a/CollapseLauncher.slnx +++ b/CollapseLauncher.slnx @@ -50,6 +50,9 @@ + + + @@ -66,6 +69,9 @@ + + + @@ -90,4 +96,10 @@ + + + + + + diff --git a/CollapseLauncher/App.xaml b/CollapseLauncher/App.xaml index 066e3cad22..71c8a5ea4d 100644 --- a/CollapseLauncher/App.xaml +++ b/CollapseLauncher/App.xaml @@ -1,5154 +1,27 @@ - + - - - - + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> - + - - - - - - - - - - - - - - - - - ms-appx:///Assets/CollapseLauncherLogo.png - ms-appx:///Assets/CollapseLauncherLogoOutlineLight.png - - #ffd52a - #ffd52a - #ffd52a - #ffd52a - #ffd52a - #ffd52a - #00ffd52a - - - - - - - - - - - - - - - - - #ffd52a - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ms-appx:///Assets/CollapseLauncherLogo.png - ms-appx:///Assets/CollapseLauncherLogoOutlineDark.png - - #693758 - #693758 - #693758 - #693758 - #693758 - #693758 - #00693758 - - - - - - - - - - - - - - - - - #693758 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0,47,0,0 - - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/CollapseLauncher/XAMLs/Theme/Button/AcrylicButton.xaml b/CollapseLauncher/XAMLs/Theme/Button/AcrylicButton.xaml new file mode 100644 index 0000000000..efed2b3302 --- /dev/null +++ b/CollapseLauncher/XAMLs/Theme/Button/AcrylicButton.xaml @@ -0,0 +1,123 @@ + + + + \ No newline at end of file diff --git a/CollapseLauncher/XAMLs/Theme/Button/AcrylicSemiButton.xaml b/CollapseLauncher/XAMLs/Theme/Button/AcrylicSemiButton.xaml new file mode 100644 index 0000000000..b59851fe24 --- /dev/null +++ b/CollapseLauncher/XAMLs/Theme/Button/AcrylicSemiButton.xaml @@ -0,0 +1,123 @@ + + + + \ No newline at end of file diff --git a/CollapseLauncher/XAMLs/Theme/Button/DefaultButton.xaml b/CollapseLauncher/XAMLs/Theme/Button/DefaultButton.xaml new file mode 100644 index 0000000000..0a9389ed83 --- /dev/null +++ b/CollapseLauncher/XAMLs/Theme/Button/DefaultButton.xaml @@ -0,0 +1,117 @@ + + + + \ No newline at end of file diff --git a/CollapseLauncher/XAMLs/Theme/Button/DraftButton.xaml b/CollapseLauncher/XAMLs/Theme/Button/DraftButton.xaml new file mode 100644 index 0000000000..1314f48bb2 --- /dev/null +++ b/CollapseLauncher/XAMLs/Theme/Button/DraftButton.xaml @@ -0,0 +1,79 @@ + + + + \ No newline at end of file diff --git a/CollapseLauncher/XAMLs/Theme/Button/NewAccentButton.xaml b/CollapseLauncher/XAMLs/Theme/Button/NewAccentButton.xaml new file mode 100644 index 0000000000..35bfa6b155 --- /dev/null +++ b/CollapseLauncher/XAMLs/Theme/Button/NewAccentButton.xaml @@ -0,0 +1,122 @@ + + + + \ No newline at end of file diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/SocMedIconButton/SocMedIconButton.xaml b/CollapseLauncher/XAMLs/Theme/Button/SocMedIconButton.xaml similarity index 73% rename from CollapseLauncher/XAMLs/Theme/CustomControls/SocMedIconButton/SocMedIconButton.xaml rename to CollapseLauncher/XAMLs/Theme/Button/SocMedIconButton.xaml index b17efab881..0d0ba1aa02 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/SocMedIconButton/SocMedIconButton.xaml +++ b/CollapseLauncher/XAMLs/Theme/Button/SocMedIconButton.xaml @@ -1,12 +1,9 @@ - + + + xmlns:pages="using:CollapseLauncher.Pages"> - + + \ No newline at end of file diff --git a/CollapseLauncher/XAMLs/Theme/Button/WindowsCaptionButton.xaml b/CollapseLauncher/XAMLs/Theme/Button/WindowsCaptionButton.xaml new file mode 100644 index 0000000000..1f3d567038 --- /dev/null +++ b/CollapseLauncher/XAMLs/Theme/Button/WindowsCaptionButton.xaml @@ -0,0 +1,95 @@ + + + \ No newline at end of file diff --git a/CollapseLauncher/XAMLs/Theme/ChangedStructItemArgs.cs b/CollapseLauncher/XAMLs/Theme/ChangedStructItemArgs.cs new file mode 100644 index 0000000000..4291b89ba9 --- /dev/null +++ b/CollapseLauncher/XAMLs/Theme/ChangedStructItemArgs.cs @@ -0,0 +1,16 @@ +namespace CollapseLauncher.XAMLs.Theme; + +#nullable enable +public readonly struct ChangedStructItemArgs(TItem oldItem, TItem newItem) + where TItem : struct +{ + public TItem OldItem { get; private init; } = oldItem; + public TItem NewItem { get; private init; } = newItem; +} + +public class ChangedObjectItemArgs(TItem? oldItem, TItem? newItem) + where TItem : class +{ + public TItem? OldItem { get; private init; } = oldItem; + public TItem? NewItem { get; private init; } = newItem; +} \ No newline at end of file diff --git a/CollapseLauncher/XAMLs/Theme/ComboBox/AcrylicComboBox.xaml b/CollapseLauncher/XAMLs/Theme/ComboBox/AcrylicComboBox.xaml new file mode 100644 index 0000000000..42fdbd3e4d --- /dev/null +++ b/CollapseLauncher/XAMLs/Theme/ComboBox/AcrylicComboBox.xaml @@ -0,0 +1,446 @@ + + + + + + + \ No newline at end of file diff --git a/CollapseLauncher/XAMLs/Theme/ComboBox/DefaultComboBox.xaml b/CollapseLauncher/XAMLs/Theme/ComboBox/DefaultComboBox.xaml new file mode 100644 index 0000000000..71d5fb4d7f --- /dev/null +++ b/CollapseLauncher/XAMLs/Theme/ComboBox/DefaultComboBox.xaml @@ -0,0 +1,448 @@ + + + + + + + \ No newline at end of file diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/CODE_OF_CONDUCT.md b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/CODE_OF_CONDUCT.md similarity index 100% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/CODE_OF_CONDUCT.md rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/CODE_OF_CONDUCT.md diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/CommitInfo b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/CommitInfo similarity index 100% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/CommitInfo rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/CommitInfo diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/Contributing.md b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/Contributing.md similarity index 100% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/Contributing.md rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/Contributing.md diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/DataTable/DataColumn.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/DataTable/DataColumn.cs similarity index 99% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/DataTable/DataColumn.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/DataTable/DataColumn.cs index 16cb5f4113..d4a264d823 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/DataTable/DataColumn.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/DataTable/DataColumn.cs @@ -8,6 +8,7 @@ using Microsoft.UI.Xaml.Input; using System; // ReSharper disable All +#pragma warning disable IDE0130 namespace CommunityToolkit.WinUI.Controls.Labs.DataTable; diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/DataTable/DataColumn.xaml b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/DataTable/DataColumn.xaml similarity index 98% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/DataTable/DataColumn.xaml rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/DataTable/DataColumn.xaml index 2ebfe2e795..07aefeef1d 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/DataTable/DataColumn.xaml +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/DataTable/DataColumn.xaml @@ -1,4 +1,5 @@  + Children.Any(static e => e is DataColumn { CurrentWidth.GridUnitType: GridUnitType.Auto }); // TODO: Check with Sergio if there's a better structure here, as I don't need a Dictionary like ConditionalWeakTable - internal HashSet Rows { get; private set; } = new(); + internal HashSet Rows { get; private set; } = []; internal void ColumnResized() { diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/License.md b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/License.md similarity index 100% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/License.md rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/License.md diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/DefaultSVGRenderer.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/DefaultSVGRenderer.cs similarity index 80% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/DefaultSVGRenderer.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/DefaultSVGRenderer.cs index bd2f5faf19..6c59c0930f 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/DefaultSVGRenderer.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/DefaultSVGRenderer.cs @@ -7,7 +7,10 @@ using System; using System.IO; using System.Threading.Tasks; +using Windows.Foundation; + // ReSharper disable InconsistentNaming +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock; @@ -15,11 +18,11 @@ internal class DefaultSVGRenderer : ISVGRenderer { public async Task SvgToImage(string svgString) { - SvgImageSource svgImageSource = new SvgImageSource(); - var image = new Image(); + SvgImageSource svgImageSource = new(); + Image image = new(); // Create a MemoryStream object and write the SVG string to it - using (var memoryStream = new MemoryStream()) - await using (var streamWriter = new StreamWriter(memoryStream)) + using (MemoryStream memoryStream = new()) + await using (StreamWriter streamWriter = new(memoryStream)) { await streamWriter.WriteAsync(svgString); await streamWriter.FlushAsync(); @@ -33,7 +36,7 @@ public async Task SvgToImage(string svgString) // Set the Source property of the Image control to the SvgImageSource object image.Source = svgImageSource; - var size = Extensions.GetSvgSize(svgString); + Size size = Extensions.GetSvgSize(svgString); if (size.Width != 0) { image.Width = size.Width; diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Extensions.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Extensions.cs similarity index 98% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Extensions.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Extensions.cs index c737f49196..e12ad079d8 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Extensions.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Extensions.cs @@ -23,6 +23,8 @@ // ReSharper disable UnusedMember.Global // ReSharper disable IdentifierTypo // ReSharper disable CommentTypo +// ReSharper disable StringLiteralTypo +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock; @@ -328,9 +330,9 @@ public static partial class Extensions public static string ToAlphabetical(this int index) { - string alphabetical = "abcdefghijklmnopqrstuvwxyz"; - int remainder = index; - StringBuilder stringBuilder = new StringBuilder(); + const string alphabetical = "abcdefghijklmnopqrstuvwxyz"; + int remainder = index; + StringBuilder stringBuilder = new(); while (remainder != 0) { if (remainder > 26) @@ -670,13 +672,13 @@ public static Size GetMarkdownImageSize(LinkInline link) public static SolidColorBrush GetAccentColorBrush() { // Create a UISettings object to get the accent color - UISettings uiSettings = new UISettings(); + UISettings uiSettings = new(); // Get the accent color as a Color value Color accentColor = uiSettings.GetColorValue(UIColorType.Accent); // Create a SolidColorBrush from the accent color - SolidColorBrush accentBrush = new SolidColorBrush(accentColor); + SolidColorBrush accentBrush = new(accentColor); return accentBrush; } diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/HtmlWriter.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/HtmlWriter.cs similarity index 89% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/HtmlWriter.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/HtmlWriter.cs index c83c8686fa..709026fe97 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/HtmlWriter.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/HtmlWriter.cs @@ -7,6 +7,7 @@ using CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements.Html; using HtmlAgilityPack; using System.Linq; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock; @@ -15,7 +16,7 @@ internal class HtmlWriter public static void WriteHtml(WinUIRenderer renderer, HtmlNodeCollection nodes) { if (nodes == null || nodes.Count == 0) return; - foreach (var node in nodes) + foreach (HtmlNode node in nodes) { if (node.NodeType == HtmlNodeType.Text) { @@ -24,7 +25,7 @@ public static void WriteHtml(WinUIRenderer renderer, HtmlNodeCollection nodes) else if (node.NodeType == HtmlNodeType.Element && node.Name.TagToType() == HtmlElementType.Inline) { // detect br here - var inlineTagName = node.Name.ToLower(); + string inlineTagName = node.Name.ToLower(); if (inlineTagName == "br") { renderer.WriteInline(new MyLineBreak()); @@ -46,12 +47,12 @@ public static void WriteHtml(WinUIRenderer renderer, HtmlNodeCollection nodes) } else if (inlineTagName == "img") { - var image = new MyImage(node, renderer.Config); + MyImage image = new(node, renderer.Config); renderer.WriteInline(image); } else { - var inline = new MyInline(); + MyInline inline = new(); renderer.Push(inline); WriteHtml(renderer, node.ChildNodes); renderer.Pop(); @@ -60,7 +61,7 @@ public static void WriteHtml(WinUIRenderer renderer, HtmlNodeCollection nodes) else if (node.NodeType == HtmlNodeType.Element && node.Name.TagToType() == HtmlElementType.Block) { IAddChild block; - var tag = node.Name.ToLower(); + string tag = node.Name.ToLower(); if (tag == "details") { block = new MyDetails(node); @@ -70,7 +71,7 @@ public static void WriteHtml(WinUIRenderer renderer, HtmlNodeCollection nodes) } else if (tag.IsHeading()) { - var heading = new MyHeading(node, renderer.Config); + MyHeading heading = new(node); renderer.Push(heading); WriteHtml(renderer, node.ChildNodes); } diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/IImageProvider.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/IImageProvider.cs similarity index 93% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/IImageProvider.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/IImageProvider.cs index 5e631f3158..1b9bcc8638 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/IImageProvider.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/IImageProvider.cs @@ -4,6 +4,7 @@ using Microsoft.UI.Xaml.Controls; using System.Threading.Tasks; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock; diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/ISVGRenderer.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/ISVGRenderer.cs similarity index 93% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/ISVGRenderer.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/ISVGRenderer.cs index 8793b55f75..a8ded60445 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/ISVGRenderer.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/ISVGRenderer.cs @@ -5,6 +5,7 @@ using Microsoft.UI.Xaml.Controls; using System.Threading.Tasks; // ReSharper disable InconsistentNaming +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock; diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownConfig.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownConfig.cs similarity index 100% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownConfig.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownConfig.cs diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownTextBlock.xaml b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownTextBlock.xaml similarity index 100% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownTextBlock.xaml rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownTextBlock.xaml diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownTextBlock.xaml.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownTextBlock.xaml.cs similarity index 88% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownTextBlock.xaml.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownTextBlock.xaml.cs index d7a9c6f191..471f626d43 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownTextBlock.xaml.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownTextBlock.xaml.cs @@ -8,6 +8,8 @@ using Markdig; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +#pragma warning disable IDE0130 +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock; // ReSharper disable All @@ -15,11 +17,11 @@ namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock; [TemplatePart(Name = MarkdownContainerName, Type = typeof(Grid))] public partial class MarkdownTextBlock : Control { - private const string MarkdownContainerName = "MarkdownContainer"; - private Grid? _container; - private MarkdownPipeline _pipeline; - private MyFlowDocument _document; - private WinUIRenderer? _renderer; + private const string MarkdownContainerName = "MarkdownContainer"; + private Grid? _container; + private readonly MarkdownPipeline _pipeline; + private readonly MyFlowDocument _document; + private WinUIRenderer? _renderer; private static readonly DependencyProperty ConfigProperty = DependencyProperty.Register( nameof(Config), @@ -106,10 +108,7 @@ private void ApplyText(string text, bool rerender) private void Build() { - if (_renderer == null) - { - _renderer = new WinUIRenderer(_document, Config); - } + _renderer ??= new WinUIRenderer(_document, Config); _pipeline.Setup(_renderer); ApplyText(Text, false); } diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownThemes.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownThemes.cs similarity index 98% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownThemes.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownThemes.cs index 55cacf83d5..281b0e42e0 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownThemes.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/MarkdownThemes.cs @@ -9,6 +9,7 @@ using FontWeights = Microsoft.UI.Text.FontWeights; // ReSharper disable PartialTypeWithSinglePart // ReSharper disable UnusedMember.Global +#pragma warning disable IDE0130 namespace CommunityToolkit.WinUI.Controls.MarkdownTextBlockRns; diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/CodeBlockRenderer.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/CodeBlockRenderer.cs similarity index 90% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/CodeBlockRenderer.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/CodeBlockRenderer.cs index 797abbdc57..9b06513b2a 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/CodeBlockRenderer.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/CodeBlockRenderer.cs @@ -5,6 +5,7 @@ using CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; using Markdig.Renderers; using Markdig.Syntax; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.Renderers.ObjectRenderers; @@ -12,7 +13,7 @@ internal class CodeBlockRenderer : MarkdownObjectRenderer 0) { @@ -50,7 +52,7 @@ protected override void Write(WinUIRenderer renderer, Table table) }; } - var myCell = new MyTableCell(cell, textAlignment, row.IsHeader, columnIndex, rowIndex); + MyTableCell myCell = new(cell, textAlignment, row.IsHeader, columnIndex, rowIndex); renderer.Push(myCell); renderer.Write(cell); diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Extensions/TaskListRenderer.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Extensions/TaskListRenderer.cs similarity index 90% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Extensions/TaskListRenderer.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Extensions/TaskListRenderer.cs index d840b422de..ac0a3e4384 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Extensions/TaskListRenderer.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Extensions/TaskListRenderer.cs @@ -6,6 +6,7 @@ using Markdig.Extensions.TaskLists; using Markdig.Renderers; using System; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.Renderers.ObjectRenderers.Extensions; @@ -16,7 +17,7 @@ protected override void Write(WinUIRenderer renderer, TaskList taskList) if (renderer == null) throw new ArgumentNullException(nameof(renderer)); if (taskList == null) throw new ArgumentNullException(nameof(taskList)); - var checkBox = new MyTaskListCheckBox(taskList); + MyTaskListCheckBox checkBox = new(taskList); renderer.WriteInline(checkBox); } } diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/HeadingRenderer.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/HeadingRenderer.cs similarity index 92% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/HeadingRenderer.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/HeadingRenderer.cs index 6347fba864..7cda09c9aa 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/HeadingRenderer.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/HeadingRenderer.cs @@ -6,6 +6,7 @@ using Markdig.Renderers; using Markdig.Syntax; using System; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.Renderers.ObjectRenderers; @@ -16,7 +17,7 @@ protected override void Write(WinUIRenderer renderer, HeadingBlock obj) if (renderer == null) throw new ArgumentNullException(nameof(renderer)); if (obj == null) throw new ArgumentNullException(nameof(obj)); - var paragraph = new MyHeading(obj, renderer.Config); + MyHeading paragraph = new(obj); renderer.Push(paragraph); renderer.WriteLeafInline(obj); renderer.Pop(); diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/HtmlBlockRenderer.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/HtmlBlockRenderer.cs similarity index 98% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/HtmlBlockRenderer.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/HtmlBlockRenderer.cs index 7c41bab4d2..266e4ab546 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/HtmlBlockRenderer.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/HtmlBlockRenderer.cs @@ -9,6 +9,7 @@ using System; using System.Text; using System.Text.RegularExpressions; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.Renderers.ObjectRenderers; diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/AutoLinkInlineRenderer.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/AutoLinkInlineRenderer.cs similarity index 90% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/AutoLinkInlineRenderer.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/AutoLinkInlineRenderer.cs index e873d7ebc4..de168d035c 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/AutoLinkInlineRenderer.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/AutoLinkInlineRenderer.cs @@ -6,6 +6,7 @@ using Markdig.Renderers; using Markdig.Syntax.Inlines; using System; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.Renderers.ObjectRenderers.Inlines; @@ -16,7 +17,7 @@ protected override void Write(WinUIRenderer renderer, AutolinkInline link) if (renderer == null) throw new ArgumentNullException(nameof(renderer)); if (link == null) throw new ArgumentNullException(nameof(link)); - var url = link.Url; + string url = link.Url; if (link.IsEmail) { url = "mailto:" + url; @@ -27,7 +28,7 @@ protected override void Write(WinUIRenderer renderer, AutolinkInline link) url = "#"; } - var autolink = new MyAutolinkInline(link); + MyAutolinkInline autolink = new(link); renderer.Push(autolink); diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/CodeInlineRenderer.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/CodeInlineRenderer.cs similarity index 90% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/CodeInlineRenderer.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/CodeInlineRenderer.cs index 8cff68fce4..36f8b38e59 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/CodeInlineRenderer.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/CodeInlineRenderer.cs @@ -6,6 +6,7 @@ using Markdig.Renderers; using Markdig.Syntax.Inlines; using System; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.Renderers.ObjectRenderers.Inlines; @@ -16,6 +17,6 @@ protected override void Write(WinUIRenderer renderer, CodeInline obj) if (renderer == null) throw new ArgumentNullException(nameof(renderer)); if (obj == null) throw new ArgumentNullException(nameof(obj)); - renderer.WriteInline(new MyInlineCode(obj, renderer.Config)); + renderer.WriteInline(new MyInlineCode(obj)); } } diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/ContainerInlineRenderer.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/ContainerInlineRenderer.cs similarity index 89% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/ContainerInlineRenderer.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/ContainerInlineRenderer.cs index 93dd1ba865..3c0700f5e8 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/ContainerInlineRenderer.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/Renderers/ObjectRenderers/Inlines/ContainerInlineRenderer.cs @@ -4,6 +4,7 @@ using Markdig.Renderers; using Markdig.Syntax.Inlines; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.Renderers.ObjectRenderers.Inlines; @@ -11,7 +12,7 @@ internal class ContainerInlineRenderer : MarkdownObjectRenderer _richTextBlocks; - public TextElement TextElement - { - get => _paragraph; - } + public TextElement TextElement => _paragraph; public MyBlock(HtmlNode block) { _htmlNode = block; - var align = _htmlNode.GetAttributeValue("align", "left"); + string align = _htmlNode.GetAttributeValue("align", "left"); _richTextBlocks = []; _paragraph = new Paragraph { @@ -46,8 +44,8 @@ public void AddChild(IAddChild child) if (child.TextElement is Block blockChild) { _paragraph.Inlines.Add(new LineBreak()); - var inlineUIContainer = new InlineUIContainer(); - var richTextBlock = new RichTextBlock(); + InlineUIContainer inlineUIContainer = new(); + RichTextBlock richTextBlock = new(); richTextBlock.Blocks.Add(blockChild); inlineUIContainer.Child = richTextBlock; _richTextBlocks.Add(richTextBlock); @@ -66,7 +64,7 @@ private void StyleBlock() { case "address": _paragraph.FontStyle = FontStyle.Italic; - foreach (var richTextBlock in _richTextBlocks) + foreach (RichTextBlock richTextBlock in _richTextBlocks) { richTextBlock.FontStyle = FontStyle.Italic; } diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/Html/MyDetails.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/Html/MyDetails.cs similarity index 66% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/Html/MyDetails.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/Html/MyDetails.cs index b94d20a205..1553f9508d 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/Html/MyDetails.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/Html/MyDetails.cs @@ -7,6 +7,7 @@ using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Documents; using System.Linq; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements.Html; @@ -16,32 +17,27 @@ internal class MyDetails : IAddChild private readonly MyFlowDocument _flowDocument; private readonly Paragraph _paragraph; - public TextElement TextElement - { - get => _paragraph; - } + public TextElement TextElement => _paragraph; public MyDetails(HtmlNode details) { - var header = details.ChildNodes - .FirstOrDefault( - x => x.Name == "summary" || - x.Name == "header"); + HtmlNode header = details.ChildNodes + .FirstOrDefault(x => x.Name is "summary" or "header"); - InlineUIContainer inlineUIContainer = new InlineUIContainer(); - Expander expander = new Expander + InlineUIContainer inlineUIContainer = new(); + Expander expander = new() { HorizontalAlignment = HorizontalAlignment.Stretch }; - _flowDocument = new MyFlowDocument + _flowDocument = new MyFlowDocument { RichTextBlock = { HorizontalAlignment = HorizontalAlignment.Stretch } }; - expander.Content = _flowDocument.RichTextBlock; - var headerBlock = new TextBlock + expander.Content = _flowDocument.RichTextBlock; + TextBlock headerBlock = new() { Text = header?.InnerText, HorizontalAlignment = HorizontalAlignment.Stretch diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/Html/MyInline.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/Html/MyInline.cs similarity index 92% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/Html/MyInline.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/Html/MyInline.cs index d6dca2f9c4..b2bb311966 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/Html/MyInline.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/Html/MyInline.cs @@ -5,6 +5,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Documents; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements.Html; @@ -13,16 +14,13 @@ internal class MyInline : IAddChild private readonly Paragraph _paragraph; private readonly InlineUIContainer _inlineUIContainer; - public TextElement TextElement - { - get => _inlineUIContainer; - } + public TextElement TextElement => _inlineUIContainer; public MyInline() { _paragraph = new Paragraph(); _inlineUIContainer = new InlineUIContainer(); - RichTextBlock richTextBlock = new RichTextBlock(); + RichTextBlock richTextBlock = new(); richTextBlock.Blocks.Add(_paragraph); richTextBlock.HorizontalAlignment = HorizontalAlignment.Stretch; diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/HtmlElementType.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/HtmlElementType.cs similarity index 91% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/HtmlElementType.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/HtmlElementType.cs index 3e362145ae..98091f73e3 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/HtmlElementType.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/HtmlElementType.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/IAddChild.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/IAddChild.cs similarity index 92% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/IAddChild.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/IAddChild.cs index 7d81f740bf..65c71fd2c0 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/IAddChild.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/IAddChild.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using Microsoft.UI.Xaml.Documents; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyAutolinkInline.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyAutolinkInline.cs similarity index 90% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyAutolinkInline.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyAutolinkInline.cs index 10a8c1b5a2..4785c30347 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyAutolinkInline.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyAutolinkInline.cs @@ -5,6 +5,7 @@ using Markdig.Syntax.Inlines; using Microsoft.UI.Xaml.Documents; using System; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -20,7 +21,7 @@ public void AddChild(IAddChild child) { try { - var text = (MyInlineText)child; + MyInlineText text = (MyInlineText)child; ((Hyperlink)TextElement).Inlines.Add((Run)text.TextElement); } catch (Exception ex) diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyBlockContainer.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyBlockContainer.cs similarity index 84% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyBlockContainer.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyBlockContainer.cs index e7a4f41882..1536b39cdc 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyBlockContainer.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyBlockContainer.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using Microsoft.UI.Xaml.Documents; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -11,14 +12,11 @@ internal class MyBlockContainer : IAddChild private readonly MyFlowDocument _flowDocument; private readonly Paragraph _paragraph; - public TextElement TextElement - { - get => _paragraph; - } + public TextElement TextElement => _paragraph; public MyBlockContainer() { - InlineUIContainer inlineUIContainer = new InlineUIContainer(); + InlineUIContainer inlineUIContainer = new(); _flowDocument = new MyFlowDocument(); inlineUIContainer.Child = _flowDocument.RichTextBlock; _paragraph = new Paragraph(); diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyCodeBlock.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyCodeBlock.cs similarity index 81% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyCodeBlock.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyCodeBlock.cs index 1a7111ee91..2f920c5b41 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyCodeBlock.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyCodeBlock.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Text; // ReSharper disable CommentTypo +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -18,23 +19,20 @@ internal class MyCodeBlock : IAddChild { private readonly Paragraph _paragraph; - public TextElement TextElement - { - get => _paragraph; - } + public TextElement TextElement => _paragraph; - public MyCodeBlock(CodeBlock codeBlock, MarkdownConfig config) + public MyCodeBlock(CodeBlock codeBlock) { _paragraph = new Paragraph(); - var container = new InlineUIContainer(); - var border = new Border + InlineUIContainer container = new(); + Border border = new() { Background = (Brush)Application.Current.Resources["ExpanderHeaderBackground"], Padding = MarkdownConfig.Themes.Padding, Margin = MarkdownConfig.Themes.InternalMargin, CornerRadius = MarkdownConfig.Themes.CornerRadius }; - var richTextBlock = new RichTextBlock(); + RichTextBlock richTextBlock = new(); if (codeBlock is FencedCodeBlock fencedCodeBlock) { @@ -43,17 +41,17 @@ public MyCodeBlock(CodeBlock codeBlock, MarkdownConfig config) //#else // var formatter = new ColorCode.RichTextBlockFormatter(Extensions.GetOneDarkProStyle()); //#endif - var stringBuilder = new StringBuilder(); + StringBuilder stringBuilder = new(); // go through all the lines backwards and only add the lines to a stack if we have encountered the first non-empty line StringLine[] lines = fencedCodeBlock.Lines.Lines; Stack stack = new(); - var encounteredFirstNonEmptyLine = false; + bool encounteredFirstNonEmptyLine = false; if (lines.Length != 0) { - for (var i = lines.Length - 1; i >= 0; i--) + for (int i = lines.Length - 1; i >= 0; i--) { - var line = lines[i]; + StringLine line = lines[i]; if (string.IsNullOrWhiteSpace(line.ToString()) && !encounteredFirstNonEmptyLine) { continue; @@ -74,10 +72,10 @@ public MyCodeBlock(CodeBlock codeBlock, MarkdownConfig config) } else { - foreach (var line in codeBlock.Lines.Lines) + foreach (StringLine line in codeBlock.Lines.Lines) { - var paragraph = new Paragraph(); - var lineString = line.ToString(); + Paragraph paragraph = new(); + string lineString = line.ToString(); if (!string.IsNullOrWhiteSpace(lineString)) { paragraph.Inlines.Add(new Run { Text = lineString }); diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyEmphasisInline.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyEmphasisInline.cs similarity index 96% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyEmphasisInline.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyEmphasisInline.cs index 40d6f95e7e..d190e3d5d0 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyEmphasisInline.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyEmphasisInline.cs @@ -7,6 +7,7 @@ using Microsoft.UI.Xaml.Documents; using System; using Windows.UI.Text; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -18,10 +19,7 @@ internal class MyEmphasisInline : IAddChild private bool _isItalic; private bool _isStrikeThrough; - public TextElement TextElement - { - get => _span; - } + public TextElement TextElement => _span; public void AddChild(IAddChild child) { diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyFlowDocument.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyFlowDocument.cs similarity index 57% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyFlowDocument.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyFlowDocument.cs index 67f909ca54..cb07f7460b 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyFlowDocument.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyFlowDocument.cs @@ -7,38 +7,31 @@ using Microsoft.UI.Xaml.Documents; using Block = Microsoft.UI.Xaml.Documents.Block; using Inline = Microsoft.UI.Xaml.Documents.Inline; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; public class MyFlowDocument : IAddChild { - private RichTextBlock _richTextBlock = new(); - // useless property public TextElement TextElement { get; set; } = new Run(); // - public RichTextBlock RichTextBlock - { - get => _richTextBlock; - set => _richTextBlock = value; - } + public RichTextBlock RichTextBlock { get; set; } = new(); public void AddChild(IAddChild child) { TextElement element = child.TextElement; - if (element != null) + if (element == null) return; + if (element is Block block) + { + RichTextBlock.Blocks.Add(block); + } + else if (element is Inline inline) { - if (element is Block block) - { - _richTextBlock.Blocks.Add(block); - } - else if (element is Inline inline) - { - var paragraph = new Paragraph(); - paragraph.Inlines.Add(inline); - _richTextBlock.Blocks.Add(paragraph); - } + Paragraph paragraph = new(); + paragraph.Inlines.Add(inline); + RichTextBlock.Blocks.Add(paragraph); } } } diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHeading.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHeading.cs similarity index 89% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHeading.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHeading.cs index 6293c86c7d..d44524a115 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHeading.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHeading.cs @@ -8,6 +8,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Documents; // ReSharper disable UnusedMember.Global +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -18,16 +19,13 @@ internal class MyHeading : IAddChild public bool IsHtml => _htmlNode != null; - public TextElement TextElement - { - get => _paragraph; - } + public TextElement TextElement => _paragraph; - public MyHeading(HeadingBlock headingBlock, MarkdownConfig config) + public MyHeading(HeadingBlock headingBlock) { _paragraph = new Paragraph(); - var level = headingBlock.Level; + int level = headingBlock.Level; _paragraph.FontSize = level switch { 1 => MarkdownConfig.Themes.H1FontSize, @@ -56,12 +54,12 @@ public MyHeading(HeadingBlock headingBlock, MarkdownConfig config) }); } - public MyHeading(HtmlNode htmlNode, MarkdownConfig config) + public MyHeading(HtmlNode htmlNode) { _htmlNode = htmlNode; _paragraph = new Paragraph(); - var align = _htmlNode?.GetAttributeValue("align", "left"); + string? align = _htmlNode?.GetAttributeValue("align", "left"); _paragraph.TextAlignment = align switch { "left" => TextAlignment.Left, @@ -71,7 +69,7 @@ public MyHeading(HtmlNode htmlNode, MarkdownConfig config) _ => TextAlignment.Left }; - var level = int.Parse(htmlNode.Name.Substring(1)); + int level = int.Parse(htmlNode.Name.Substring(1)); _paragraph.FontSize = level switch { 1 => MarkdownConfig.Themes.H1FontSize, diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHyperlink.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHyperlink.cs similarity index 61% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHyperlink.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHyperlink.cs index 5564eff419..980ea52af8 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHyperlink.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHyperlink.cs @@ -9,6 +9,7 @@ using Microsoft.UI.Xaml.Documents; using System; using Inline = Microsoft.UI.Xaml.Documents.Inline; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -16,14 +17,11 @@ internal class MyHyperlink : IAddChild { private readonly Hyperlink _hyperlink; - public TextElement TextElement - { - get => _hyperlink; - } + public TextElement TextElement => _hyperlink; public MyHyperlink(LinkInline linkInline, string? baseUrl) { - var url = linkInline.GetDynamicUrl != null ? linkInline.GetDynamicUrl() : linkInline.Url; + string? url = linkInline.GetDynamicUrl != null ? linkInline.GetDynamicUrl() : linkInline.Url; _hyperlink = new Hyperlink { NavigateUri = Extensions.GetUri(url, baseUrl) @@ -32,7 +30,7 @@ public MyHyperlink(LinkInline linkInline, string? baseUrl) public MyHyperlink(HtmlNode htmlNode, string? baseUrl) { - var url = htmlNode.GetAttributeValue("href", "#"); + string url = htmlNode.GetAttributeValue("href", "#"); _hyperlink = new Hyperlink { NavigateUri = Extensions.GetUri(url, baseUrl) @@ -41,17 +39,15 @@ public MyHyperlink(HtmlNode htmlNode, string? baseUrl) public void AddChild(IAddChild child) { - if (child.TextElement is Inline inlineChild) + if (child.TextElement is not Inline inlineChild) return; + try + { + _hyperlink.Inlines.Add(inlineChild); + // TODO: Add support for click handler + } + catch (Exception ex) { - try - { - _hyperlink.Inlines.Add(inlineChild); - // TODO: Add support for click handler - } - catch (Exception ex) - { - Logger.LogWriteLine($"[MyHyperlink::AddChild()] Failed while adding inlines\r\n{ex}", LogType.Error, true); - } + Logger.LogWriteLine($"[MyHyperlink::AddChild()] Failed while adding inlines\r\n{ex}", LogType.Error, true); } } } diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHyperlinkButton.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHyperlinkButton.cs similarity index 81% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHyperlinkButton.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHyperlinkButton.cs index cacc447547..ca7e9ed8a1 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHyperlinkButton.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyHyperlinkButton.cs @@ -8,6 +8,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Documents; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -21,14 +22,11 @@ internal class MyHyperlinkButton : IAddChild public bool IsHtml => _htmlNode != null; - public TextElement TextElement - { - get => _inlineUIContainer; - } + public TextElement TextElement => _inlineUIContainer; public MyHyperlinkButton(LinkInline linkInline, string? baseUrl) { - var url = linkInline.GetDynamicUrl != null ? linkInline.GetDynamicUrl() : linkInline.Url; + string? url = linkInline.GetDynamicUrl != null ? linkInline.GetDynamicUrl() : linkInline.Url; _linkInline = linkInline; Init(url, baseUrl); } @@ -36,7 +34,7 @@ public MyHyperlinkButton(LinkInline linkInline, string? baseUrl) public MyHyperlinkButton(HtmlNode htmlNode, string? baseUrl) { _htmlNode = htmlNode; - var url = htmlNode.GetAttributeValue("href", "#"); + string url = htmlNode.GetAttributeValue("href", "#"); Init(url, baseUrl); } @@ -48,14 +46,11 @@ private void Init(string? url, string? baseUrl) Padding = new Thickness(0), Margin = new Thickness(0) }; - if (IsHtml && _htmlNode != null) - { - _flowDoc = new MyFlowDocument(); - } - else if (_linkInline != null) + if ((IsHtml && _htmlNode != null) || _linkInline != null) { _flowDoc = new MyFlowDocument(); } + _inlineUIContainer.Child = _hyperLinkButton; _hyperLinkButton.Content = _flowDoc?.RichTextBlock; } diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyImage.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyImage.cs similarity index 93% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyImage.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyImage.cs index 6de75e0410..07094f2021 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyImage.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyImage.cs @@ -15,8 +15,10 @@ using System.Globalization; using System.Net.Http; using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; using Windows.Storage.Streams; // ReSharper disable AsyncVoidMethod +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -32,10 +34,7 @@ internal class MyImage : IAddChild private readonly double _precedentHeight; private bool _loaded; - public TextElement TextElement - { - get => _container; - } + public TextElement TextElement => _container; public MyImage(LinkInline linkInline, Uri uri, MarkdownConfig config) { @@ -43,7 +42,7 @@ public MyImage(LinkInline linkInline, Uri uri, MarkdownConfig config) _imageProvider = config.ImageProvider; _svgRenderer = config.SVGRenderer ?? new DefaultSVGRenderer(); Init(); - var size = Extensions.GetMarkdownImageSize(linkInline); + Size size = Extensions.GetMarkdownImageSize(linkInline); if (size.Width != 0) { _precedentWidth = size.Width; @@ -64,13 +63,13 @@ public MyImage(HtmlNode htmlNode, MarkdownConfig? config) htmlNode.GetAttributeValue("width", "0"), NumberStyles.Integer, CultureInfo.InvariantCulture, - out var width + out int width ); int.TryParse( htmlNode.GetAttributeValue("height", "0"), NumberStyles.Integer, CultureInfo.InvariantCulture, - out var height + out int height ); if (width > 0) { @@ -115,7 +114,7 @@ private async void LoadImage(object sender, RoutedEventArgs e) if (contentType == "image/svg+xml") { string svgString = await response.Content.ReadAsStringAsync(); - var resImage = await _svgRenderer.SvgToImage(svgString); + Image? resImage = await _svgRenderer.SvgToImage(svgString); if (resImage != null) { _image = resImage; @@ -126,8 +125,8 @@ private async void LoadImage(object sender, RoutedEventArgs e) { byte[] data = await response.Content.ReadAsByteArrayAsync(); // Create a BitmapImage for other supported formats - BitmapImage bitmap = new BitmapImage(); - using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream()) + BitmapImage bitmap = new(); + using (InMemoryRandomAccessStream stream = new()) { // Write the data to the stream await stream.WriteAsync(data.AsBuffer()); diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyInlineCode.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyInlineCode.cs similarity index 84% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyInlineCode.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyInlineCode.cs index 7c3796fbb5..98e27eeb1d 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyInlineCode.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyInlineCode.cs @@ -8,6 +8,7 @@ using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Documents; using Microsoft.UI.Xaml.Media.Media3D; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -15,15 +16,12 @@ internal class MyInlineCode : IAddChild { private readonly InlineUIContainer _inlineContainer; - public TextElement TextElement - { - get => _inlineContainer; - } + public TextElement TextElement => _inlineContainer; - public MyInlineCode(CodeInline codeInline, MarkdownConfig config) + public MyInlineCode(CodeInline codeInline) { _inlineContainer = new InlineUIContainer(); - var border = new Border + Border border = new() { VerticalAlignment = VerticalAlignment.Bottom, Background = MarkdownConfig.Themes.InlineCodeBackground, @@ -32,12 +30,12 @@ public MyInlineCode(CodeInline codeInline, MarkdownConfig config) CornerRadius = MarkdownConfig.Themes.InlineCodeCornerRadius, Padding = MarkdownConfig.Themes.InlineCodePadding }; - CompositeTransform3D transform = new CompositeTransform3D + CompositeTransform3D transform = new() { TranslateY = 4 }; border.Transform3D = transform; - var textBlock = new TextBlock + TextBlock textBlock = new() { FontFamily = MarkdownConfig.Themes.InlineCodeFontFamily, FontSize = MarkdownConfig.Themes.InlineCodeFontSize, diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyInlineText.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyInlineText.cs similarity index 86% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyInlineText.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyInlineText.cs index 6119923b60..e17820a053 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyInlineText.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyInlineText.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using Microsoft.UI.Xaml.Documents; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -13,10 +14,7 @@ internal class MyInlineText(string text) : IAddChild Text = text }; - public TextElement TextElement - { - get => _run; - } + public TextElement TextElement => _run; public void AddChild(IAddChild child) { } } diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyLineBreak.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyLineBreak.cs similarity index 84% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyLineBreak.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyLineBreak.cs index 8a627c919d..21c7368b4b 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyLineBreak.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyLineBreak.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using Microsoft.UI.Xaml.Documents; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -10,10 +11,7 @@ internal class MyLineBreak : IAddChild { private readonly LineBreak _lineBreak = new(); - public TextElement TextElement - { - get => _lineBreak; - } + public TextElement TextElement => _lineBreak; public void AddChild(IAddChild child) { } } diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyList.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyList.cs similarity index 93% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyList.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyList.cs index 065c5c77b7..bb50ce4ecb 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyList.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyList.cs @@ -8,6 +8,7 @@ using Microsoft.UI.Xaml.Documents; using RomanNumerals; using System.Globalization; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -20,15 +21,12 @@ internal class MyList : IAddChild private int _index = 1; private const string Dot = "• "; - public TextElement TextElement - { - get => _paragraph; - } + public TextElement TextElement => _paragraph; public MyList(ListBlock listBlock) { _paragraph = new Paragraph(); - InlineUIContainer container = new InlineUIContainer(); + InlineUIContainer container = new(); _stackPanel = new StackPanel(); if (listBlock.IsOrdered) @@ -50,7 +48,7 @@ public MyList(ListBlock listBlock) public void AddChild(IAddChild child) { - var grid = new Grid(); + Grid grid = new(); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); string bullet; @@ -71,14 +69,14 @@ public void AddChild(IAddChild child) { bullet = Dot; } - var textBlock = new TextBlock + TextBlock textBlock = new() { Text = bullet }; textBlock.SetValue(Grid.ColumnProperty, 0); textBlock.VerticalAlignment = VerticalAlignment.Top; grid.Children.Add(textBlock); - var flowDoc = new MyFlowDocument(); + MyFlowDocument flowDoc = new(); flowDoc.AddChild(child); flowDoc.RichTextBlock.SetValue(Grid.ColumnProperty, 1); diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyParagraph.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyParagraph.cs similarity index 83% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyParagraph.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyParagraph.cs index 3b64c16405..9ffd157e0d 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyParagraph.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyParagraph.cs @@ -5,6 +5,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Documents; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -12,10 +13,7 @@ internal class MyParagraph : IAddChild { private readonly Paragraph _paragraph = new(); - public TextElement TextElement - { - get => _paragraph; - } + public TextElement TextElement => _paragraph; public void AddChild(IAddChild child) { @@ -25,8 +23,8 @@ public void AddChild(IAddChild child) } else if (child.TextElement is Block blockChild) { - var inlineUIContainer = new InlineUIContainer(); - var richTextBlock = new RichTextBlock + InlineUIContainer inlineUIContainer = new(); + RichTextBlock richTextBlock = new() { TextWrapping = TextWrapping.Wrap }; diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyQuote.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyQuote.cs similarity index 88% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyQuote.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyQuote.cs index c4cdff1d91..47ba53ccee 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyQuote.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyQuote.cs @@ -7,6 +7,7 @@ using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Documents; using Microsoft.UI.Xaml.Media; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -15,23 +16,20 @@ internal class MyQuote : IAddChild private readonly Paragraph _paragraph; private readonly MyFlowDocument _flowDocument; - public TextElement TextElement - { - get => _paragraph; - } + public TextElement TextElement => _paragraph; public MyQuote() { _paragraph = new Paragraph(); _flowDocument = new MyFlowDocument(); - var inlineUIContainer = new InlineUIContainer(); + InlineUIContainer inlineUIContainer = new(); - var grid = new Grid(); + Grid grid = new(); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); - var bar = new Grid + Grid bar = new() { Width = 4, Background = new SolidColorBrush(Colors.Gray) @@ -41,7 +39,7 @@ public MyQuote() bar.Margin = new Thickness(0, 0, 4, 0); grid.Children.Add(bar); - var rightGrid = new Grid + Grid rightGrid = new() { Padding = new Thickness(4) }; diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTable.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTable.cs similarity index 64% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTable.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTable.cs index 4740ef55b8..10536e79d0 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTable.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTable.cs @@ -8,6 +8,7 @@ using Microsoft.UI.Xaml.Documents; using Microsoft.UI.Xaml.Media; using System.Linq; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -16,15 +17,12 @@ internal class MyTable : IAddChild private readonly Paragraph _paragraph; private readonly MyTableUIElement _tableElement; - public TextElement TextElement - { - get => _paragraph; - } + public TextElement TextElement => _paragraph; public MyTable(Table table) { _paragraph = new Paragraph(); - var column = table.FirstOrDefault() is not TableRow row ? 0 : row.Count; + int column = table.FirstOrDefault() is not TableRow row ? 0 : row.Count; _tableElement = new MyTableUIElement ( @@ -34,7 +32,7 @@ public MyTable(Table table) new SolidColorBrush(Colors.Gray) ); - var inlineUIContainer = new InlineUIContainer + InlineUIContainer inlineUIContainer = new() { Child = _tableElement }; @@ -43,16 +41,14 @@ public MyTable(Table table) public void AddChild(IAddChild child) { - if (child is MyTableCell cellChild) - { - var cell = cellChild.Container; + if (child is not MyTableCell cellChild) return; + Grid cell = cellChild.Container; - Grid.SetColumn(cell, cellChild.ColumnIndex); - Grid.SetRow(cell, cellChild.RowIndex); - Grid.SetColumnSpan(cell, cellChild.ColumnSpan); - Grid.SetRowSpan(cell, cellChild.RowSpan); + Grid.SetColumn(cell, cellChild.ColumnIndex); + Grid.SetRow(cell, cellChild.RowIndex); + Grid.SetColumnSpan(cell, cellChild.ColumnSpan); + Grid.SetRowSpan(cell, cellChild.RowSpan); - _tableElement.Children.Add(cell); - } + _tableElement.Children.Add(cell); } } diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableCell.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableCell.cs similarity index 88% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableCell.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableCell.cs index 7de24bcbce..55e41ce2c6 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableCell.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableCell.cs @@ -7,6 +7,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Documents; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -16,22 +17,13 @@ internal class MyTableCell : IAddChild private readonly Paragraph _paragraph = new(); private readonly MyFlowDocument _flowDocument; - public TextElement TextElement - { - get => _paragraph; - } + public TextElement TextElement => _paragraph; public Grid Container { get; } - public int ColumnSpan - { - get => _tableCell.ColumnSpan; - } + public int ColumnSpan => _tableCell.ColumnSpan; - public int RowSpan - { - get => _tableCell.RowSpan; - } + public int RowSpan => _tableCell.RowSpan; public int ColumnIndex { get; } @@ -44,7 +36,7 @@ public MyTableCell(TableCell tableCell, TextAlignment textAlignment, bool isHead RowIndex = rowIndex; Container = new Grid(); - _flowDocument = new MyFlowDocument + _flowDocument = new MyFlowDocument { RichTextBlock = { diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableRow.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableRow.cs similarity index 73% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableRow.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableRow.cs index 0dbac0abcd..7a976643da 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableRow.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableRow.cs @@ -7,14 +7,15 @@ using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Documents; // ReSharper disable All +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.MarkdownTextBlock.TextElements; internal class MyTableRow : IAddChild { - private TableRow _tableRow; - private StackPanel _stackPanel; - private Paragraph _paragraph; + private TableRow _tableRow; + private readonly StackPanel _stackPanel; + private readonly Paragraph _paragraph; public TextElement TextElement { @@ -26,10 +27,14 @@ public MyTableRow(TableRow tableRow) _tableRow = tableRow; _paragraph = new Paragraph(); - _stackPanel = new StackPanel(); - _stackPanel.Orientation = Orientation.Horizontal; - var inlineUIContainer = new InlineUIContainer(); - inlineUIContainer.Child = _stackPanel; + _stackPanel = new StackPanel + { + Orientation = Orientation.Horizontal + }; + var inlineUIContainer = new InlineUIContainer + { + Child = _stackPanel + }; _paragraph.Inlines.Add(inlineUIContainer); } diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableUIElement.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableUIElement.cs similarity index 99% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableUIElement.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableUIElement.cs index 61d8d4f5b5..db4bf34035 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableUIElement.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTableUIElement.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Linq; using Windows.Foundation; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; // ReSharper disable All diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTaskListCheckBox.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTaskListCheckBox.cs similarity index 87% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTaskListCheckBox.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTaskListCheckBox.cs index c2812ac9a5..9b5b530f77 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTaskListCheckBox.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyTaskListCheckBox.cs @@ -9,6 +9,7 @@ using Microsoft.UI.Xaml.Documents; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Media.Media3D; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -18,8 +19,8 @@ internal class MyTaskListCheckBox : IAddChild public MyTaskListCheckBox(TaskList taskList) { - var grid = new Grid(); - CompositeTransform3D transform = new CompositeTransform3D + Grid grid = new(); + CompositeTransform3D transform = new() { TranslateY = 2 }; @@ -29,7 +30,7 @@ public MyTaskListCheckBox(TaskList taskList) grid.Margin = new Thickness(2, 0, 2, 0); grid.BorderThickness = new Thickness(1); grid.BorderBrush = new SolidColorBrush(Colors.Gray); - FontIcon icon = new FontIcon + FontIcon icon = new() { FontSize = 16, HorizontalAlignment = HorizontalAlignment.Center, @@ -39,7 +40,7 @@ public MyTaskListCheckBox(TaskList taskList) grid.Children.Add(taskList.Checked ? icon : new TextBlock()); grid.Padding = new Thickness(0); grid.CornerRadius = new CornerRadius(2); - var inlineUIContainer = new InlineUIContainer + InlineUIContainer inlineUIContainer = new() { Child = grid }; diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyThematicBreak.cs b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyThematicBreak.cs similarity index 85% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyThematicBreak.cs rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyThematicBreak.cs index 7cb6c9a149..9508a7b373 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyThematicBreak.cs +++ b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/MarkdownTextBlock/TextElements/MyThematicBreak.cs @@ -7,6 +7,7 @@ using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Documents; using Microsoft.UI.Xaml.Media; +#pragma warning disable IDE0130 namespace CommunityToolkit.Labs.WinUI.Labs.MarkdownTextBlock.TextElements; @@ -14,17 +15,14 @@ internal class MyThematicBreak : IAddChild { private readonly Paragraph _paragraph; - public TextElement TextElement - { - get => _paragraph; - } + public TextElement TextElement => _paragraph; public MyThematicBreak() { _paragraph = new Paragraph(); - var inlineUIContainer = new InlineUIContainer(); - var border = new Border + InlineUIContainer inlineUIContainer = new(); + Border border = new() { Width = 500, BorderThickness = new Thickness(1), diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/ReadMe.md b/CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/ReadMe.md similarity index 100% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CommunityToolkit.Labs/ReadMe.md rename to CollapseLauncher/XAMLs/Theme/CommunityToolkit.Labs/ReadMe.md diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/CompressedTextBlock.cs b/CollapseLauncher/XAMLs/Theme/CompressedTextBlock.cs similarity index 99% rename from CollapseLauncher/XAMLs/Theme/CustomControls/CompressedTextBlock.cs rename to CollapseLauncher/XAMLs/Theme/CompressedTextBlock.cs index 246963073b..a6077c8174 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/CompressedTextBlock.cs +++ b/CollapseLauncher/XAMLs/Theme/CompressedTextBlock.cs @@ -5,9 +5,10 @@ using System.Collections.Generic; using System.Numerics; using Windows.Foundation; + // ReSharper disable PartialTypeWithSinglePart -namespace CollapseLauncher.CustomControls +namespace CollapseLauncher.XAMLs.Theme { public partial class CompressedTextBlock : Grid { diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/ContentDialogCollapse.cs b/CollapseLauncher/XAMLs/Theme/ContentDialog/ContentDialogCollapse.cs similarity index 91% rename from CollapseLauncher/XAMLs/Theme/CustomControls/ContentDialogCollapse.cs rename to CollapseLauncher/XAMLs/Theme/ContentDialog/ContentDialogCollapse.cs index 87de1e1982..5026ad5043 100644 --- a/CollapseLauncher/XAMLs/Theme/CustomControls/ContentDialogCollapse.cs +++ b/CollapseLauncher/XAMLs/Theme/ContentDialog/ContentDialogCollapse.cs @@ -1,17 +1,15 @@ -// using Hi3Helper.Shared.ClassStruct; - -using CollapseLauncher.Extension; +using CollapseLauncher.Extension; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media; using Windows.Foundation; using NColor = Windows.UI.Color; // ReSharper disable PartialTypeWithSinglePart -namespace CollapseLauncher.CustomControls +namespace CollapseLauncher.XAMLs.Theme.ContentDialog { public enum ContentDialogTheme { Informational, Warning, Error, Success } - public partial class ContentDialogCollapse : ContentDialog + public partial class ContentDialogCollapse : Microsoft.UI.Xaml.Controls.ContentDialog { private string ThemeTitleGlyph { get; } private ContentDialogTheme Theme { get; } @@ -44,6 +42,7 @@ public ContentDialogCollapse(ContentDialogTheme theme = ContentDialogTheme.Warni => ShowAsync(ContentDialogPlacement.Popup); private new IAsyncOperation ShowAsync( + // ReSharper disable once UnusedParameter.Local ContentDialogPlacement placement) { if (Title is not string titleString || Theme == ContentDialogTheme.Informational) diff --git a/CollapseLauncher/XAMLs/Theme/ContentDialogCollapse.xaml b/CollapseLauncher/XAMLs/Theme/ContentDialog/ContentDialogCollapse.xaml similarity index 98% rename from CollapseLauncher/XAMLs/Theme/ContentDialogCollapse.xaml rename to CollapseLauncher/XAMLs/Theme/ContentDialog/ContentDialogCollapse.xaml index 689b3b5a61..ff29d2aa38 100644 --- a/CollapseLauncher/XAMLs/Theme/ContentDialogCollapse.xaml +++ b/CollapseLauncher/XAMLs/Theme/ContentDialog/ContentDialogCollapse.xaml @@ -1,9 +1,7 @@ - + - - + xmlns:contentDialog="using:CollapseLauncher.XAMLs.Theme.ContentDialog"> + \ No newline at end of file diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/LayeredBackgroundImageExtensions.cs b/CollapseLauncher/XAMLs/Theme/CustomControls/LayeredBackgroundImageExtensions.cs new file mode 100644 index 0000000000..255ae24d2c --- /dev/null +++ b/CollapseLauncher/XAMLs/Theme/CustomControls/LayeredBackgroundImageExtensions.cs @@ -0,0 +1,442 @@ +using Hi3Helper.Win32.WinRT.WindowsStream; +using Microsoft.UI; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media.Imaging; +using PhotoSauce.MagicScaler; +using PhotoSauce.MagicScaler.Transforms; +using System; +using System.IO; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using Windows.Storage.Streams; +// ReSharper disable GrammarMistakeInComment + +// ReSharper disable SwitchStatementHandlesSomeKnownEnumValuesWithDefault +// ReSharper disable ConvertIfStatementToSwitchStatement + +#nullable enable +namespace CollapseLauncher.XAMLs.Theme.CustomControls; + +internal static class LayeredBackgroundImageExtensions +{ + private static readonly HttpClient Client; + + static LayeredBackgroundImageExtensions() + { + Client = CreateHttpClient(); + } + + private static HttpClient CreateHttpClient() + { + SocketsHttpHandler handler = new() + { + AllowAutoRedirect = true, + MaxConnectionsPerServer = Environment.ProcessorCount * 2 + }; + return new HttpClient(handler, false); + } + + internal static async ValueTask LoadImageAsync( + this Image image, + Uri? sourceFromPath, + Stream? sourceFromStream, + LayeredBackgroundImage instance, + DependencyProperty useCacheProperty, + IPixelTransform? pixelTransform = null) + { + IMediaCacheHandler? cacheHandler = instance.MediaCacheHandler; + bool isDisposeStream = sourceFromStream == null; + bool forceUseInternalDecoder = false; + + // Try get cached source from cache handler + if (cacheHandler != null) + { + object? source = sourceFromPath; + source ??= sourceFromStream; + MediaCacheResult cacheResult = await cacheHandler.LoadCachedSource(source); + + forceUseInternalDecoder = cacheResult.ForceUseInternalDecoder; + isDisposeStream = cacheResult.DisposeStream; + + if (cacheResult.CachedSource is Uri sourceAsPath) + { + sourceFromPath = sourceAsPath; + sourceFromStream = null; + } + else if (cacheResult.CachedSource is Stream sourceAsStream) + { + sourceFromPath = null; + sourceFromStream = sourceAsStream; + } + else + { + return false; + } + } + + try + { + if (sourceFromPath != null) + { + return await image.LoadImageFromUriPathSourceAsync(sourceFromPath, + forceUseInternalDecoder, + instance, + useCacheProperty, + pixelTransform); + } + + if (sourceFromStream != null) + { + return await image.LoadImageFromStreamSourceAsync(sourceFromStream, + forceUseInternalDecoder, + instance, + useCacheProperty, + pixelTransform); + } + + return false; + } + finally + { + if (isDisposeStream && sourceFromStream != null) + { + await sourceFromStream.DisposeAsync(); + } + } + } + + private static async ValueTask LoadImageFromUriPathSourceAsync( + this Image image, + Uri sourceFromPath, + bool forceUseInternalDecoder, + LayeredBackgroundImage instance, + DependencyProperty useCacheProperty, + IPixelTransform? pixelTransform = null) + { + string extension = Path.GetExtension(sourceFromPath.ToString()); + bool isInternalFormat = LayeredBackgroundImage + .SupportedImageBitmapExtensionsLookup + .Contains(extension); + bool isSvgFormat = LayeredBackgroundImage + .SupportedImageVectorExtensionsLookup + .Contains(extension); + + if ((forceUseInternalDecoder || + isInternalFormat || + isSvgFormat) && pixelTransform == null) + { + if (isSvgFormat) + { + image.Source = new SvgImageSource(sourceFromPath); + return true; + } + + image.Source = new BitmapImage(sourceFromPath) + { + CreateOptions = (bool)instance.GetValue(useCacheProperty) + ? BitmapCreateOptions.None + : BitmapCreateOptions.IgnoreImageCache + }; + return true; + } + + await using FileStream? fileStream = await TryGetStreamFromPathAsync(sourceFromPath, instance.MediaSourceCacheDir); + if (fileStream == null) + { + return false; + } + + // Borrow loading process from stream source loader. + // We gonna ignore internal decoder enforcement here because, uh... idk. + return await image + .LoadImageFromStreamSourceAsync(fileStream, + false, + instance, + useCacheProperty, + pixelTransform); + } + + private static async ValueTask LoadImageFromStreamSourceAsync( + this Image image, + Stream sourceFromStream, + bool forceUseInternalDecoder, + LayeredBackgroundImage instance, + DependencyProperty useCacheProperty, + IPixelTransform? pixelTransform = null) + { + (Stream? stream, bool isTemporaryStream) = + await sourceFromStream.GetNativeOrCopiedStreamIfNotSeekable(CancellationToken.None); + + if (stream == null) + { + return false; + } + + try + { + // Reset position + stream.Position = 0; + + // Guess codec type + ImageExternalCodecType codecType = await stream.GuessImageFormatFromStreamAsync(); + if (codecType == ImageExternalCodecType.NotSupported) + { + return false; + } + + // Reset position after format guessing + stream.Position = 0; + + if ((forceUseInternalDecoder || + codecType == ImageExternalCodecType.Default) && + pixelTransform != null) + { + using IRandomAccessStream sourceRandomStream = stream.AsRandomAccessStream(true); + BitmapImage bitmapImage = new() + { + CreateOptions = (bool)instance.GetValue(useCacheProperty) + ? BitmapCreateOptions.None + : BitmapCreateOptions.IgnoreImageCache + }; + await bitmapImage.SetSourceAsync(sourceRandomStream); + image.Source = bitmapImage; + return true; + } + + if (codecType == ImageExternalCodecType.Svg) + { + using IRandomAccessStream sourceRandomStream = stream.AsRandomAccessStream(true); + SvgImageSource svgImageSource = new(); + await svgImageSource.SetSourceAsync(sourceRandomStream); + image.Source = svgImageSource; + return true; + } + + FileStream? tempStream = null; + + try + { + string? userDefinedCacheDir = instance.MediaSourceCacheDir; + bool requireConversion = true; + + if (!string.IsNullOrEmpty(userDefinedCacheDir) && stream is FileStream sourceAsFileStream) + { + Directory.CreateDirectory(userDefinedCacheDir); + + string cachedFilename = $"decoded_{Path.GetFileNameWithoutExtension(sourceAsFileStream.Name)}.png"; + string decodedFilepath = Path.Combine(userDefinedCacheDir, cachedFilename); + FileInfo decodedFileInfo = new(decodedFilepath); + + if (decodedFileInfo is { Exists: true, Length: > 256 }) + { + requireConversion = false; + } + + tempStream = decodedFileInfo.Open(FileMode.OpenOrCreate, + FileAccess.ReadWrite, + FileShare.ReadWrite); + } + + tempStream ??= CreateTemporaryStream(); + + if (requireConversion) + { + // Use MagicScaler for external codec types + await Task.Run(() => + { + ProcessImageSettings settings = new(); + settings.TrySetEncoderFormat(ImageMimeTypes.Png); + + using ProcessingPipeline pipeline = MagicImageProcessor.BuildPipeline(stream, settings); + if (pixelTransform != null) + { + pipeline.AddTransform(pixelTransform); + } + + pipeline.WriteOutput(tempStream); + }); + } + + tempStream.Position = 0; + using IRandomAccessStream tempRandomStream = tempStream.AsRandomAccessStream(true); + BitmapImage tempBitmapImage = new() + { + CreateOptions = (bool)instance.GetValue(useCacheProperty) + ? BitmapCreateOptions.None + : BitmapCreateOptions.IgnoreImageCache + }; + await tempBitmapImage.SetSourceAsync(tempRandomStream); + image.Source = tempBitmapImage; + return true; + } + finally + { + if (tempStream != null) + { + await tempStream.DisposeAsync(); + } + } + } + finally + { + if (isTemporaryStream) + { + await stream.DisposeAsync(); + } + } + } + + private static async Task TryGetStreamFromPathAsync(Uri? url, string? userDefinedTempDir) + { + if (url == null) + { + return null; + } + + if (url.IsFile) + { + return File.Open(url.LocalPath, FileMode.Open, FileAccess.Read, FileShare.Read); + } + + if (await GetFileLengthFromUrl(Client, url) is var fileLength && + fileLength == 0) + { + return null; + } + + HttpRequestMessage requestMessage = new(HttpMethod.Get, url); + HttpResponseMessage responseMessage = + await Client.SendAsync(requestMessage, + HttpCompletionOption.ResponseHeadersRead); + + if (!responseMessage.IsSuccessStatusCode) + { + responseMessage.Dispose(); + requestMessage.Dispose(); + return null; + } + + FileStream tempStream = url.CreateTemporaryStreamFromUrl(userDefinedTempDir); + if (tempStream.Length == fileLength) + { + return tempStream; + } + + try + { + tempStream.SetLength(0); // Reset length. + + await using Stream networkStream = await responseMessage.Content.ReadAsStreamAsync(); + await networkStream.CopyToAsync(tempStream); + return tempStream; + } + catch (Exception e) + { + Console.WriteLine(e); + await tempStream.DisposeAsync(); + } + + return null; + } + + private static async Task GetFileLengthFromUrl(HttpClient client, Uri url) + { + HttpRequestMessage requestMessage = new(HttpMethod.Head, url); + HttpResponseMessage responseMessage = + await client.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead); + + if (responseMessage.IsSuccessStatusCode) + { + return responseMessage.Content.Headers.ContentLength ?? 0; + } + + responseMessage.Dispose(); + requestMessage.Dispose(); + return 0; + } + + internal static double GetClampedVolume(this double thisVolume) + { + if (double.IsNaN(thisVolume) || + double.IsInfinity(thisVolume)) + { + thisVolume = 0; + } + + return Math.Clamp(thisVolume, 0, 100d) / 100d; + } + + private static async ValueTask<(Stream? Stream, bool IsTemporaryStream)> + GetNativeOrCopiedStreamIfNotSeekable( + this T stream, + CancellationToken token) + where T : Stream + { + // If it's seekable, then just return it + if (stream.CanSeek) + { + return (stream, false); + } + + // Copy over + FileStream tempStream = CreateTemporaryStream(); + try + { + await stream.CopyToAsync(tempStream, token); + return (tempStream, true); + } + catch + { + await tempStream.DisposeAsync(); + return (null, false); + } + } + + private static FileStream CreateTemporaryStreamFromUrl(this Uri url, string? userDefinedTempDir) + { + string path; + if (string.IsNullOrEmpty(userDefinedTempDir)) + { + string extension = Path.GetExtension(url.AbsolutePath); + path = Path.Combine(Path.GetTempPath(), Path.GetTempFileName() + extension); + } + else + { + Directory.CreateDirectory(userDefinedTempDir); + path = Path.Combine(userDefinedTempDir, Path.GetFileName(url.AbsolutePath)); + } + + return File.Open(path, + new FileStreamOptions + { + Mode = FileMode.Create, + Access = FileAccess.ReadWrite, + Share = FileShare.ReadWrite, + Options = string.IsNullOrEmpty(userDefinedTempDir) ? + FileOptions.None : + FileOptions.DeleteOnClose + }); + } + + private static FileStream CreateTemporaryStream() + { + string path = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()); + return File.Open(path, + new FileStreamOptions + { + Mode = FileMode.Create, + Access = FileAccess.ReadWrite, + Share = FileShare.ReadWrite, + Options = FileOptions.DeleteOnClose + }); + } + + internal static WindowId GetElementWindowId(this LayeredBackgroundImage element) + { + XamlRoot root = element.XamlRoot; + WindowId windowId = root.ContentIslandEnvironment.AppWindowId; + return windowId; + } +} diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/LayeredBackgroundImage_themeresources.xaml b/CollapseLauncher/XAMLs/Theme/CustomControls/LayeredBackgroundImage_themeresources.xaml new file mode 100644 index 0000000000..9a74e74828 --- /dev/null +++ b/CollapseLauncher/XAMLs/Theme/CustomControls/LayeredBackgroundImage_themeresources.xaml @@ -0,0 +1,19 @@ + + + + + + + + + + \ No newline at end of file diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/NewPipsPager.Converters.cs b/CollapseLauncher/XAMLs/Theme/CustomControls/NewPipsPager.Converters.cs new file mode 100644 index 0000000000..99b318e126 --- /dev/null +++ b/CollapseLauncher/XAMLs/Theme/CustomControls/NewPipsPager.Converters.cs @@ -0,0 +1,23 @@ +#nullable enable +using Microsoft.UI.Xaml.Data; +using System; + +namespace CollapseLauncher.XAMLs.Theme.CustomControls; + +internal partial class IndexAddOneConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, string language) + { + if (value is int asInt) + { + return asInt + 1; + } + + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, string language) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/NewPipsPager.Enums.cs b/CollapseLauncher/XAMLs/Theme/CustomControls/NewPipsPager.Enums.cs new file mode 100644 index 0000000000..dda2d379c7 --- /dev/null +++ b/CollapseLauncher/XAMLs/Theme/CustomControls/NewPipsPager.Enums.cs @@ -0,0 +1,14 @@ +namespace CollapseLauncher.XAMLs.Theme.CustomControls; + +public enum NewPipsPagerNavigationMode +{ + Auto, + Hidden, + Visible +} + +public enum NewPipsPagerSelectionMode +{ + Click, + Hover +} \ No newline at end of file diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/NewPipsPager.Events.cs b/CollapseLauncher/XAMLs/Theme/CustomControls/NewPipsPager.Events.cs new file mode 100644 index 0000000000..fcdcb79cc0 --- /dev/null +++ b/CollapseLauncher/XAMLs/Theme/CustomControls/NewPipsPager.Events.cs @@ -0,0 +1,390 @@ +#nullable enable +using Microsoft.UI.Input; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Input; +using System; +using System.Linq; +using System.Numerics; +using Windows.Foundation; +using Windows.System; + +namespace CollapseLauncher.XAMLs.Theme.CustomControls; + +public partial class NewPipsPager +{ + #region Size Measure Override + + protected override Size MeasureOverride(Size parentSize) + { + Orientation orientation = Orientation; + Vector2 pipsButtonSize = PipButtonSize; + + Vector2 repeaterSize = _pipsPagerItemsRepeater.ActualSize; + double repeaterWidth = repeaterSize.X; + double repeaterHeight = repeaterSize.Y; + + GetNavigationButtonTotalSize(PreviousNavigationButtonMode, _previousPageButton, out double navPrevBtnWidth, out double navPrevBtnHeight); + GetNavigationButtonTotalSize(NextNavigationButtonMode, _nextPageButton, out double navNextBtnWidth, out double navNextBtnHeight); + + Size availableSpace = base.MeasureOverride(parentSize); + + double calculatedWidth = availableSpace.Width; + double calculatedHeight = availableSpace.Height; + + if (orientation == Orientation.Horizontal) + { + calculatedWidth = CalculateElementSize(parentSize.Width, + repeaterWidth, + navPrevBtnWidth, + navNextBtnWidth, + pipsButtonSize.X, + out double repeaterFinalWidth); + + calculatedHeight = GetMaxElementOtherSize(navPrevBtnHeight, navNextBtnHeight, calculatedHeight, repeaterHeight); + _pipsPagerScrollViewer.MaxWidth = repeaterFinalWidth; + } + else + { + calculatedHeight = CalculateElementSize(parentSize.Height, + repeaterHeight, + navPrevBtnHeight, + navNextBtnHeight, + pipsButtonSize.Y, + out double repeaterFinalHeight); + + calculatedWidth = GetMaxElementOtherSize(navPrevBtnWidth, navNextBtnWidth, calculatedWidth, repeaterWidth); + _pipsPagerScrollViewer.MaxHeight = repeaterFinalHeight; + } + + return new Size(calculatedWidth, calculatedHeight); + } + + private static double CalculateElementSize( + double parentSize, + double repeaterSize, + double navPrevBtnSize, + double navNextBtnSize, + double pipBtnSize, + out double repeaterFinalSize) + { + double remainedSize = parentSize - navPrevBtnSize - navNextBtnSize; + repeaterFinalSize = remainedSize >= repeaterSize + ? repeaterSize + : GetClampedRepeaterSize(remainedSize, pipBtnSize); + + return navPrevBtnSize + navNextBtnSize + repeaterFinalSize; + } + + private static double GetMaxElementOtherSize( + double navPrevBtnSize, + double navNextBtnSize, + double calculatedSize, + double repeaterSize) + { + double elementMaxSize = Math.Max(navPrevBtnSize, + Math.Max(navNextBtnSize, repeaterSize)); + + if (calculatedSize > elementMaxSize) + { + calculatedSize = elementMaxSize; + } + + return calculatedSize; + } + + private static void GetNavigationButtonTotalSize( + NewPipsPagerNavigationMode mode, + Button element, + out double width, + out double height) + { + bool isVisible = mode != NewPipsPagerNavigationMode.Hidden; + Vector2 size = isVisible ? element.ActualSize : Vector2.Zero; + Thickness margin = isVisible ? element.Margin : default; + width = size.X + margin.Left + margin.Right; + height = size.Y + margin.Top + margin.Bottom; + } + + private static double GetClampedRepeaterSize( + double remainedAvailSpace, + double buttonSize) + { + if (remainedAvailSpace < buttonSize || + !double.IsFinite(remainedAvailSpace) || + buttonSize <= 0) + { + return 0; + } + + double itemCountDisplay = Math.Round(remainedAvailSpace / buttonSize); + double itemCountDisplayClamp = itemCountDisplay % 2 == 0 ? itemCountDisplay - 1 : itemCountDisplay; + + return itemCountDisplayClamp * buttonSize; + } + + #endregion + + #region UI Events - Navigation Buttons + + private void PreviousPageButton_OnClick(object sender, RoutedEventArgs e) => ItemIndex--; + + private void NextPageButton_OnClick(object sender, RoutedEventArgs e) => ItemIndex++; + + private void KeyboardKeys_Pressed(object sender, KeyRoutedEventArgs e) + { + switch (e.Key) + { + case VirtualKey.Left: + case VirtualKey.Up: + PreviousPageButton_OnClick(sender, e); + break; + case VirtualKey.Right: + case VirtualKey.Down: + NextPageButton_OnClick(sender, e); + break; + } + } + + #endregion + + #region UI Events - Orientation + + private static void Orientation_OnChange(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + NewPipsPager pager = (NewPipsPager)d; + Orientation orientation = (Orientation)e.NewValue; + + Orientation_OnChange(pager, orientation); + } + + private static void Orientation_OnChange(NewPipsPager pager, Orientation orientation) + { + string state = orientation == Orientation.Vertical + ? "VerticalOrientationView" + : "HorizontalOrientationView"; + VisualStateManager.GoToState(pager, state, true); + } + + #endregion + + #region Property Changes + + private static void ItemsCount_OnChange(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is not NewPipsPager pager) + { + return; + } + + object obj = e.NewValue; + int value = 0; + if (obj is int asInt) + { + value = asInt; + } + + pager.ItemsCount_OnChange(value); + } + + private void ItemsCount_OnChange(int value) + { + if (!_isTemplateLoaded) + { + return; + } + + if (value < 0) + { + throw new IndexOutOfRangeException("ItemsCount cannot be negative!"); + } + + int oldItemsCount = _itemsDummy.Length; + + using (_atomicLock.EnterScope()) + { + try + { + + if (value == 0) + { + _itemsDummy = []; + return; + } + + _itemsDummy = Enumerable.Range(0, value).ToArray(); + } + finally + { + // Update ItemsSource if already assigned + _pipsPagerItemsRepeater.ItemsSource = _itemsDummy; + _pipsPagerItemsRepeater.UpdateLayout(); + + // Update index only if the count is invalid + int currentIndex = ItemIndex; + if (currentIndex > value || + (value != 0 && currentIndex < 0)) + { + ItemIndex = 0; + } + + ItemsCountChanged?.Invoke(this, new ChangedStructItemArgs(oldItemsCount, value)); + } + } + } + + private static void ItemIndex_OnChange(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + // Ignore if the old and new index are equal + if (e is not { NewValue: int asNewIndex, OldValue: int asOldIndex } || + asNewIndex == asOldIndex) + { + return; + } + + NewPipsPager pager = (NewPipsPager)d; + if (!pager.IsLoaded) + { + return; + } + + // Update navigation buttons state + UpdatePreviousButtonVisualState(pager); + UpdateNextButtonVisualState(pager); + + // Update pip buttons state + UpdateAndBringSelectedPipToView(pager, asNewIndex, asOldIndex); + + // Update pager layout + pager.UpdateLayout(); + } + + #endregion + + #region ItemsRepeater + + private void ItemsRepeater_ElementPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args) + { + if (args.Element is not Button asButton) + { + return; + } + + AssignPipButtonStyle(asButton, args.Index != ItemIndex + ? NormalPipButtonStyle + : SelectedPipButtonStyle); + + if (asButton.Tag is true) + { + return; + } + + // Store Tag as true so the event won't be subscribed more than once. + asButton.Tag = true; + asButton.Loaded += ItemsRepeaterPipButton_LoadedEvent; + asButton.Unloaded += ItemsRepeaterPipButton_UnloadedEvent; + } + + private void ItemsRepeater_OnSizeChanged(object sender, SizeChangedEventArgs e) => InvalidateMeasure(); + + private void ItemsRepeaterPipButton_UnloadedEvent(object sender, RoutedEventArgs e) + { + Button button = (Button)sender; + if (SelectionMode == NewPipsPagerSelectionMode.Click) + { + button.Click -= ItemsRepeaterPipButton_OnClick; + } + else + { + button.PointerEntered -= ItemsRepeaterPipButton_OnClick; + } + } + + private void ItemsRepeaterPipButton_LoadedEvent(object sender, RoutedEventArgs e) + { + Button button = (Button)sender; + if (SelectionMode == NewPipsPagerSelectionMode.Click) + { + button.Click += ItemsRepeaterPipButton_OnClick; + } + else + { + button.PointerEntered += ItemsRepeaterPipButton_OnClick; + } + } + + private void ItemsRepeaterPipButton_OnClick(object sender, RoutedEventArgs args) + { + if (sender is not Button asButton) + { + return; + } + + int index = _pipsPagerItemsRepeater.GetElementIndex(asButton); + if (index < 0 || + ItemsCount <= index) + { + return; + } + + ItemIndex = index; + } + + #endregion + + #region ScrollViewer + + private void ScrollViewer_OnPointerWheelChanged(object sender, PointerRoutedEventArgs e) + { + if (!e.Pointer.IsInRange || + sender is not UIElement element) + { + return; + } + + Orientation layoutOrientation = Orientation; + double pipsButtonSize = layoutOrientation == Orientation.Horizontal ? PipButtonSize.X : PipButtonSize.Y; + + PointerPoint pointer = e.GetCurrentPoint(element); + int orientation = pointer.Properties.MouseWheelDelta; + bool isHorizontal = layoutOrientation == Orientation.Horizontal; + double delta = pipsButtonSize * (orientation / 120d); + + double toOffset = (isHorizontal + ? _pipsPagerScrollViewer.HorizontalOffset + : _pipsPagerScrollViewer.VerticalOffset) + -delta; + toOffset = Math.Round(toOffset / pipsButtonSize) * pipsButtonSize; + + if (isHorizontal) + { + toOffset = Math.Clamp(toOffset, 0, _pipsPagerScrollViewer.ExtentWidth); + _pipsPagerScrollViewer.ChangeView(toOffset, _pipsPagerScrollViewer.VerticalOffset, _pipsPagerScrollViewer.ZoomFactor); + } + else + { + toOffset = Math.Clamp(toOffset, 0, _pipsPagerScrollViewer.ExtentHeight); + _pipsPagerScrollViewer.ChangeView(_pipsPagerScrollViewer.HorizontalOffset, toOffset, _pipsPagerScrollViewer.ZoomFactor); + } + } + + #endregion + + #region Loaded and Unloaded + + private void NewPipsPager_Unloaded(object sender, RoutedEventArgs e) + { + _pipsPagerItemsRepeater.ItemsSource = null; + } + + private void NewPipsPager_Loaded(object sender, RoutedEventArgs e) + { + ItemsCount_OnChange(ItemsCount); + UpdateAndBringSelectedPipToView(this, ItemIndex, -1); + + // Update navigation buttons state + UpdatePreviousButtonVisualState(this); + UpdateNextButtonVisualState(this); + } + + #endregion +} diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/NewPipsPager.Properties.cs b/CollapseLauncher/XAMLs/Theme/CustomControls/NewPipsPager.Properties.cs new file mode 100644 index 0000000000..67a208a7a1 --- /dev/null +++ b/CollapseLauncher/XAMLs/Theme/CustomControls/NewPipsPager.Properties.cs @@ -0,0 +1,310 @@ +#nullable enable +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using System.Numerics; +using System.Threading; +using Windows.Foundation; + +namespace CollapseLauncher.XAMLs.Theme.CustomControls; + +public partial class NewPipsPager +{ + #region Events + + public event TypedEventHandler>? ItemsCountChanged; + public event TypedEventHandler>? ItemIndexChanged; + + #endregion + + #region Properties + + public Orientation Orientation + { + get => (Orientation)GetValue(OrientationProperty); + set => SetValue(OrientationProperty, value); + } + + public int ItemsCount + { + get => (int)GetValue(ItemsCountProperty); + set => SetValue(ItemsCountProperty, value); + } + + public int ItemIndex + { + get => (int)GetValue(ItemIndexProperty); + set + { + using (_atomicLock.EnterScope()) + { + int itemsCount = ItemsCount; + if (itemsCount == 0) + { + return; + } + + if (value < 0) + { + value = itemsCount - 1; + } + + if (value >= itemsCount) + { + value = 0; + } + + SetValue(ItemIndexProperty, value); + } + } + } + + public NewPipsPagerSelectionMode SelectionMode + { + get => (NewPipsPagerSelectionMode)GetValue(SelectionModeProperty); + set => SetValue(SelectionModeProperty, value); + } + + public NewPipsPagerNavigationMode PreviousNavigationButtonMode + { + get => (NewPipsPagerNavigationMode)GetValue(PreviousNavigationButtonModeProperty); + set => SetValue(PreviousNavigationButtonModeProperty, value); + } + + public NewPipsPagerNavigationMode NextNavigationButtonMode + { + get => (NewPipsPagerNavigationMode)GetValue(NextNavigationButtonModeProperty); + set => SetValue(NextNavigationButtonModeProperty, value); + } + + public Style PreviousButtonStyle + { + get => (Style)GetValue(PreviousButtonStyleProperty); + set => SetValue(PreviousButtonStyleProperty, value); + } + + public Style NextButtonStyle + { + get => (Style)GetValue(NextButtonStyleProperty); + set => SetValue(NextButtonStyleProperty, value); + } + + public Style NormalPipButtonStyle + { + get => (Style)GetValue(NormalPipButtonStyleProperty); + set => SetValue(NormalPipButtonStyleProperty, value); + } + + public Style SelectedPipButtonStyle + { + get => (Style)GetValue(SelectedPipButtonStyleProperty); + set => SetValue(SelectedPipButtonStyleProperty, value); + } + + public Vector2 PipButtonSize => _pipsPagerItemsRepeater.TryGetElement(ItemIndex) is not { } button ? default : button.ActualSize; + +#endregion + + #region Fields + + private readonly Lock _atomicLock = new(); + + private int[] _itemsDummy = []; + + #endregion + + #region Dependency Change Methods + + private static void UpdatePreviousButtonVisualState(NewPipsPager pager) + { + UpdateButtonVisualState(pager, + pager._previousPageButton, + pager.ItemIndex > 0, + NavButtonStatePreviousPageButtonCollapsed, + NavButtonStatePreviousPageButtonVisible, + NavButtonStatePreviousPageButtonHidden, + pager.PreviousNavigationButtonMode); + } + + private static void UpdateNextButtonVisualState(NewPipsPager pager) + { + UpdateButtonVisualState(pager, + pager._nextPageButton, + pager.ItemIndex + 1 < pager.ItemsCount, + NavButtonStateNextPageButtonCollapsed, + NavButtonStateNextPageButtonVisible, + NavButtonStateNextPageButtonHidden, + pager.NextNavigationButtonMode); + } + + private static void UpdateButtonVisualState( + NewPipsPager instance, + Button? button, + bool conditionForAutoVisible, + string stateNameForCollapsed, + string stateNameForVisible, + string stateNameForHidden, + NewPipsPagerNavigationMode mode) + { + if (button == null) + { + return; + } + + if (mode == NewPipsPagerNavigationMode.Hidden) + { + VisualStateManager.GoToState(instance, stateNameForCollapsed, true); + return; + } + + VisualStateManager.GoToState(instance, stateNameForVisible, true); + button.IsEnabled = true; + if (mode == NewPipsPagerNavigationMode.Visible) + { + return; + } + + if (conditionForAutoVisible) + { + return; + } + + button.IsEnabled = false; + VisualStateManager.GoToState(instance, stateNameForHidden, true); + } + + private static void UpdateAndBringSelectedPipToView(NewPipsPager pager, int newIndex, int oldIndex) + { + if (pager.UpdateSelectedPipStyle(newIndex, oldIndex) is not { } asButton) + { + return; + } + + BringElementIntoCenterView(asButton, pager.Orientation); + } + + private static void BringElementIntoCenterView(UIElement element, Orientation orientation) + { + BringIntoViewOptions options = new() + { + AnimationDesired = true + }; + if (orientation == Orientation.Horizontal) + { + options.HorizontalAlignmentRatio = 0.5d; + } + else + { + options.VerticalAlignmentRatio = 0.5d; + } + element.StartBringIntoView(options); + } + + public void BringCurrentPipButtonIntoView() + { + if (_pipsPagerItemsRepeater.TryGetElement(ItemIndex) is not { } element) + { + return; + } + + BringElementIntoCenterView(element, Orientation); + } + + private Button? UpdateSelectedPipStyle(int newIndex, int oldIndex) + { + ItemsRepeater repeater = _pipsPagerItemsRepeater; + if (repeater == null!) + { + return null; + } + + try + { + if (!_isTemplateLoaded || + repeater.ItemsSourceView == null) + { + return null; + } + + int childCount = repeater.ItemsSourceView.Count; + bool isUpdateNewChild = newIndex >= 0 && newIndex < childCount; + bool isUpdateOldChild = oldIndex >= 0 && oldIndex < childCount; + + if (ItemsCount == 0) + { + return null; + } + + Button? newIndexPipButton = repeater.GetOrCreateElement(newIndex) as Button; + Button? oldIndexPipButton = repeater.TryGetElement(oldIndex) as Button; + + try + { + if (isUpdateOldChild) + { + AssignPipButtonStyle(oldIndexPipButton, NormalPipButtonStyle); + } + + if (isUpdateNewChild) + { + return AssignPipButtonStyle(newIndexPipButton, SelectedPipButtonStyle); + } + + return newIndexPipButton; + } + finally + { + if (newIndex != oldIndex) + { + ItemIndexChanged?.Invoke(this, new ChangedStructItemArgs(oldIndex, newIndex)); + } + } + } + catch + { + // ignored + } + + return null; + } + + private static Button? AssignPipButtonStyle(Button? button, Style? style) + { + if (button is null) + { + return button; + } + + button.Style = style; + button.UpdateLayout(); + VisualStateManager.GoToState(button, PipButtonStateNormal, true); + return button; + } + + private static void PreviousNavigationButtonMode_OnChange(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + UpdatePreviousButtonVisualState((NewPipsPager)d); + } + + private static void NextNavigationButtonMode_OnChange(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + UpdateNextButtonVisualState((NewPipsPager)d); + } + + #endregion + + #region Dependency Properties + + public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register(nameof(Orientation), typeof(Orientation), typeof(NewPipsPager), new PropertyMetadata(Orientation.Vertical, Orientation_OnChange)); + public static readonly DependencyProperty ItemsCountProperty = DependencyProperty.Register(nameof(ItemsCount), typeof(int), typeof(NewPipsPager), new PropertyMetadata(0, ItemsCount_OnChange)); + public static readonly DependencyProperty ItemIndexProperty = DependencyProperty.Register(nameof(ItemIndex), typeof(int), typeof(NewPipsPager), new PropertyMetadata(-1, ItemIndex_OnChange)); + public static readonly DependencyProperty SelectionModeProperty = DependencyProperty.Register(nameof(SelectionMode), typeof(bool), typeof(NewPipsPager), new PropertyMetadata(NewPipsPagerSelectionMode.Click)); + public static readonly DependencyProperty PreviousNavigationButtonModeProperty = DependencyProperty.Register(nameof(PreviousNavigationButtonMode), typeof(NewPipsPagerNavigationMode), typeof(NewPipsPager), new PropertyMetadata(NewPipsPagerNavigationMode.Auto, PreviousNavigationButtonMode_OnChange)); + public static readonly DependencyProperty NextNavigationButtonModeProperty = DependencyProperty.Register(nameof(NextNavigationButtonMode), typeof(NewPipsPagerNavigationMode), typeof(NewPipsPager), new PropertyMetadata(NewPipsPagerNavigationMode.Auto, NextNavigationButtonMode_OnChange)); + + public static readonly DependencyProperty PreviousButtonStyleProperty = DependencyProperty.Register(nameof(PreviousButtonStyle), typeof(Style), typeof(NewPipsPager), new PropertyMetadata(null!)); + public static readonly DependencyProperty NextButtonStyleProperty = DependencyProperty.Register(nameof(NextButtonStyle), typeof(Style), typeof(NewPipsPager), new PropertyMetadata(null!)); + public static readonly DependencyProperty NormalPipButtonStyleProperty = DependencyProperty.Register(nameof(NormalPipButtonStyle), typeof(Style), typeof(NewPipsPager), new PropertyMetadata(null!)); + public static readonly DependencyProperty SelectedPipButtonStyleProperty = DependencyProperty.Register(nameof(SelectedPipButtonStyle), typeof(Style), typeof(NewPipsPager), new PropertyMetadata(null!)); + + #endregion +} diff --git a/CollapseLauncher/XAMLs/Theme/CustomControls/NewPipsPager.Templates.cs b/CollapseLauncher/XAMLs/Theme/CustomControls/NewPipsPager.Templates.cs new file mode 100644 index 0000000000..91a4b5e8c1 --- /dev/null +++ b/CollapseLauncher/XAMLs/Theme/CustomControls/NewPipsPager.Templates.cs @@ -0,0 +1,124 @@ +#nullable enable +using CollapseLauncher.Extension; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using System.Threading; + +namespace CollapseLauncher.XAMLs.Theme.CustomControls; + +[TemplatePart(Name = TemplateNamePreviousPageButton, Type = typeof(Button))] +[TemplatePart(Name = TemplateNameNextPageButton, Type = typeof(Button))] +[TemplatePart(Name = TemplateNamePipsPagerScrollViewer, Type = typeof(ScrollViewer))] +[TemplatePart(Name = TemplateNamePipsPagerItemsRepeater, Type = typeof(ItemsRepeater))] +public partial class NewPipsPager +{ + #region Constants + + private const string TemplateNamePreviousPageButton = "PreviousPageButton"; + private const string TemplateNameNextPageButton = "NextPageButton"; + private const string TemplateNamePipsPagerScrollViewer = "PipsPagerScrollViewer"; + private const string TemplateNamePipsPagerItemsRepeater = "PipsPagerItemsRepeater"; + + private const string PipButtonStateNormal = "Normal"; + + private const string NavButtonStatePreviousPageButtonCollapsed = "PreviousPageButtonCollapsed"; + private const string NavButtonStatePreviousPageButtonVisible = "PreviousPageButtonVisible"; + private const string NavButtonStatePreviousPageButtonHidden = "PreviousPageButtonHidden"; + private const string NavButtonStateNextPageButtonCollapsed = "NextPageButtonCollapsed"; + private const string NavButtonStateNextPageButtonVisible = "NextPageButtonVisible"; + private const string NavButtonStateNextPageButtonHidden = "NextPageButtonHidden"; + + #endregion + + #region Fields + + private Button _previousPageButton = null!; + private Button _nextPageButton = null!; + private ScrollViewer _pipsPagerScrollViewer = null!; + private ItemsRepeater _pipsPagerItemsRepeater = null!; + + private bool _isTemplateLoaded; + + #endregion + + #region Apply Template Methods + + protected override void OnApplyTemplate() + { + if (Interlocked.Exchange(ref _isTemplateLoaded, true)) + { + return; + } + + base.OnApplyTemplate(); + + _previousPageButton = this.GetTemplateChild