From c47c609963fe082c11c24ce9e67adc87e65fff95 Mon Sep 17 00:00:00 2001 From: JKamsker Date: Thu, 16 Nov 2023 18:36:01 +0100 Subject: [PATCH 1/2] Add "copy as PathGeometry" --- .gitignore | 1 + src/IconPacks.Browser/Controls/SideBar.xaml | 21 +++++++-- .../Clipboard.WPF.Geometry.xml | 1 + .../IconPacks.Browser.csproj | 3 ++ src/IconPacks.Browser/Model/ExportHelper.cs | 44 +++++++++++++++++-- .../ViewModels/IconPackViewModel.cs | 4 +- 6 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 src/IconPacks.Browser/ExportTemplates/Clipboard.WPF.Geometry.xml diff --git a/.gitignore b/.gitignore index c0002c0..7f65b67 100644 --- a/.gitignore +++ b/.gitignore @@ -358,3 +358,4 @@ MigrationBackup/ # XamlStyler !XamlStyler/ +/.nuke/temp diff --git a/src/IconPacks.Browser/Controls/SideBar.xaml b/src/IconPacks.Browser/Controls/SideBar.xaml index 15ca57c..3918bd3 100644 --- a/src/IconPacks.Browser/Controls/SideBar.xaml +++ b/src/IconPacks.Browser/Controls/SideBar.xaml @@ -19,7 +19,7 @@ - + @@ -81,7 +81,7 @@ - + + IsExpanded="False"> + + + + + + + + + + + + diff --git a/src/IconPacks.Browser/ExportTemplates/Clipboard.WPF.Geometry.xml b/src/IconPacks.Browser/ExportTemplates/Clipboard.WPF.Geometry.xml new file mode 100644 index 0000000..585a0d0 --- /dev/null +++ b/src/IconPacks.Browser/ExportTemplates/Clipboard.WPF.Geometry.xml @@ -0,0 +1 @@ +@PathData \ No newline at end of file diff --git a/src/IconPacks.Browser/IconPacks.Browser.csproj b/src/IconPacks.Browser/IconPacks.Browser.csproj index 1c1cba3..9761df2 100644 --- a/src/IconPacks.Browser/IconPacks.Browser.csproj +++ b/src/IconPacks.Browser/IconPacks.Browser.csproj @@ -41,6 +41,9 @@ <_SettingsFiles Remove="Properties\Settings.settings" /> + + PreserveNewest + PreserveNewest diff --git a/src/IconPacks.Browser/Model/ExportHelper.cs b/src/IconPacks.Browser/Model/ExportHelper.cs index 91761d4..8856695 100644 --- a/src/IconPacks.Browser/Model/ExportHelper.cs +++ b/src/IconPacks.Browser/Model/ExportHelper.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.IO; using System.Windows.Media; + using IconPacks.Browser.Properties; using IconPacks.Browser.ViewModels; @@ -11,30 +12,42 @@ internal class ExportHelper { // SVG-File private static string _SvgFileTemplate; + internal static string SvgFileTemplate => _SvgFileTemplate ??= LoadTemplateString("SVG.xml"); // XAML-File (WPF) private static string _WpfFileTemplate; + internal static string WpfFileTemplate => _WpfFileTemplate ??= LoadTemplateString("WPF.xml"); // XAML-File (WPF) private static string _UwpFileTemplate; + internal static string UwpFileTemplate => _UwpFileTemplate ??= LoadTemplateString("WPF.xml"); // Clipboard - WPF private static string _ClipboardWpf; + internal static string ClipboardWpf => _ClipboardWpf ??= File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExportTemplates", "Clipboard.WPF.xml")); + + // Clipboard - WPF + private static string _ClipboardWpfGeometry; + + internal static string ClipboardWpfGeometry => _ClipboardWpfGeometry ??= File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExportTemplates", "Clipboard.WPF.Geometry.xml")); // Clipboard - UWP private static string _ClipboardUwp; + internal static string ClipboardUwp => _ClipboardUwp ??= File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExportTemplates", "Clipboard.UWP.xml")); // Clipboard - Content private static string _ClipboardContent; + internal static string ClipboardContent => _ClipboardContent ??= File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExportTemplates", "Clipboard.Content.xml")); // Clipboard - PathData private static string _ClipboardData; + internal static string ClipboardData => _ClipboardData ??= File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExportTemplates", "Clipboard.PathData.xml")); internal static string FillTemplate(string template, ExportParameters parameters) @@ -45,7 +58,7 @@ internal static string FillTemplate(string template, ExportParameters parameters .Replace("@IconPackLicense", parameters.IconPackLicense) .Replace("@PageWidth", parameters.PageWidth) .Replace("@PageHeight", parameters.PageHeight) - .Replace("@PathData", parameters.PathData) + .CheckedReplace("@PathData", () => parameters.PathData) // avoid allocation of Lazy .Replace("@FillColor", parameters.FillColor) .Replace("@Background", parameters.Background) .Replace("@StrokeColor", parameters.StrokeColor) @@ -71,7 +84,7 @@ internal static string LoadTemplateString(string fileName) internal struct ExportParameters { /// - /// Provides a default set of Export parameters. You should edit this to your needs. + /// Provides a default set of Export parameters. You should edit this to your needs. /// /// internal ExportParameters(IIconViewModel icon) @@ -93,15 +106,27 @@ internal ExportParameters(IIconViewModel icon) this.IconPackHomepage = metaData?.ProjectUrl; this.IconPackLicense = metaData?.LicenseUrl; + + //this.PathData = (icon as IconViewModel)?.GetPackIconControlBase().Data; + _pathDataLazy = new Lazy(() => (icon as IconViewModel)?.GetPackIconControlBase().Data); } + private Lazy _pathDataLazy; + private string _pathData; + internal string IconKind { get; set; } internal string IconPackName { get; set; } internal string IconPackHomepage { get; set; } internal string IconPackLicense { get; set; } internal string PageWidth { get; set; } internal string PageHeight { get; set; } - internal string PathData { get; set; } + + internal string PathData + { + get => _pathData ?? _pathDataLazy.Value; + set => _pathData = value; + } + internal string FillColor { get; set; } internal string Background { get; set; } internal string StrokeColor { get; set; } @@ -110,4 +135,17 @@ internal ExportParameters(IIconViewModel icon) internal string StrokeLineJoin { get; set; } internal string TransformMatrix { get; set; } } + + internal static class ExportHelperExtensions + { + internal static string CheckedReplace(this string input, string oldValue, Func newValue) + { + if (input.Contains(oldValue)) + { + return input.Replace(oldValue, newValue()); + } + + return input; + } + } } \ No newline at end of file diff --git a/src/IconPacks.Browser/ViewModels/IconPackViewModel.cs b/src/IconPacks.Browser/ViewModels/IconPackViewModel.cs index 7f43dd8..2dceb25 100644 --- a/src/IconPacks.Browser/ViewModels/IconPackViewModel.cs +++ b/src/IconPacks.Browser/ViewModels/IconPackViewModel.cs @@ -491,12 +491,13 @@ public IconViewModel(Type enumType, Type packType, Enum k, MetaDataAttribute met } public string CopyToClipboardText => ExportHelper.FillTemplate(ExportHelper.ClipboardWpf, new ExportParameters(this)); // $""; + public string CopyToClipboardWpfGeometry => ExportHelper.FillTemplate(ExportHelper.ClipboardWpfGeometry, new ExportParameters(this)); // $""; public string CopyToClipboardAsContentText => ExportHelper.FillTemplate(ExportHelper.ClipboardContent, new ExportParameters(this)); // $"{{iconPacks:{IconPackType.Name.Replace("PackIcon", "")} Kind={Name}}}"; public string CopyToClipboardAsPathIconText => ExportHelper.FillTemplate(ExportHelper.ClipboardUwp, new ExportParameters(this)); // $""; - public string CopyToClipboardAsGeometryText => ExportHelper.FillTemplate(ExportHelper.ClipboardData, new ExportParameters(this) { PathData = GetPackIconControlBase().Data }); // GetPackIconControlBase().Data; + public string CopyToClipboardAsGeometryText => ExportHelper.FillTemplate(ExportHelper.ClipboardData, new ExportParameters(this)); // GetPackIconControlBase().Data; public string Name { get; set; } @@ -515,6 +516,7 @@ public IconViewModel(Type enumType, Type packType, Enum k, MetaDataAttribute met internal PackIconControlBase GetPackIconControlBase() { if (Activator.CreateInstance(IconPackType) is not PackIconControlBase iconPack) return null; + var kindProperty = IconPackType.GetProperty("Kind"); if (kindProperty == null) return null; kindProperty.SetValue(iconPack, Value); From eda0e82f5324e7da0c61c6699f2d8ef15b1a7ebe Mon Sep 17 00:00:00 2001 From: punker76 Date: Thu, 6 Jun 2024 17:18:57 +0200 Subject: [PATCH 2/2] fix: path data generation --- src/IconPacks.Browser/App.xaml | 5 +- src/IconPacks.Browser/Controls/SideBar.xaml | 71 ++++++++----------- src/IconPacks.Browser/MainWindow.xaml | 16 ++--- src/IconPacks.Browser/Model/ExportHelper.cs | 17 +---- .../ViewModels/IconPackViewModel.cs | 1 + .../ViewModels/MainViewModel.cs | 35 ++++++++- 6 files changed, 79 insertions(+), 66 deletions(-) diff --git a/src/IconPacks.Browser/App.xaml b/src/IconPacks.Browser/App.xaml index d4ff6d0..eab3c0b 100644 --- a/src/IconPacks.Browser/App.xaml +++ b/src/IconPacks.Browser/App.xaml @@ -97,8 +97,9 @@