Skip to content

Commit

Permalink
Merge pull request #35 from JKamsker/PathGeometry
Browse files Browse the repository at this point in the history
Add "copy as PathGeometry"
  • Loading branch information
punker76 authored Jun 6, 2024
2 parents e470240 + eda0e82 commit 94066f5
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,4 @@ MigrationBackup/

# XamlStyler
!XamlStyler/
/.nuke/temp
5 changes: 3 additions & 2 deletions src/IconPacks.Browser/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@
</Style>

<Style BasedOn="{StaticResource MahApps.Styles.MetroHeader}" TargetType="mah:MetroHeader">
<Setter Property="Padding" Value="2 0 2 5" />
<Setter Property="mah:HeaderedControlHelper.HeaderFontSize" Value="{DynamicResource MahApps.Sizes.Font.Content}" />
<Setter Property="Padding" Value="2 0 2 4" />
<Setter Property="mah:HeaderedControlHelper.HeaderMargin" Value="2 2 2 4" />
<Setter Property="mah:HeaderedControlHelper.HeaderFontSize" Value="{DynamicResource MahApps.Font.Size.Content}" />
</Style>

<Style BasedOn="{StaticResource MahApps.Styles.ColorPicker}" TargetType="mah:ColorPicker">
Expand Down
70 changes: 37 additions & 33 deletions src/IconPacks.Browser/Controls/SideBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="300" MinHeight="50" />
<RowDefinition Height="250" MinHeight="50" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
Expand Down Expand Up @@ -83,8 +83,7 @@

<Expander Margin="0 2 0 0" Header="Icon Information">
<StackPanel>
<mah:MetroHeader Padding="2 0"
DataContext="{Binding SelectedIcon}"
<mah:MetroHeader DataContext="{Binding SelectedIcon}"
Header="IconPackName and IconKind">
<ctrls:CopyToClipboardTextBox>
<ctrls:CopyToClipboardTextBox.TextToCopy>
Expand All @@ -108,8 +107,7 @@
</Expander>

<Expander Margin="0 5 0 0"
Header="Preview options"
IsExpanded="True">
Header="Preview options">
<StackPanel>
<mah:MetroHeader Header="Iconsize ">
<ComboBox x:Name="ComboBoxIconPreviewSize"
Expand Down Expand Up @@ -145,44 +143,52 @@
<mah:MetroHeader>
<mah:MetroHeader.Header>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconEvaIcons Width="20"
Height="10"
VerticalAlignment="Center"
Kind="Code" />
<TextBlock VerticalAlignment="Center" Text="Copy icon as WPF-Control" />
</StackPanel>
<iconPacks:PackIconPhosphorIcons Width="12"
Height="12"
VerticalAlignment="Center"
Kind="BracketsAngle" />
<Label VerticalAlignment="Center" Margin ="4 0" Padding="0" Content="Copy as WPF-Control" />
</StackPanel>
</mah:MetroHeader.Header>
<ctrls:CopyToClipboardTextBox FontFamily="Consolas" TextToCopy="{Binding CopyToClipboardText}" />
</mah:MetroHeader>

<mah:MetroHeader>
<mah:MetroHeader.Header>
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconPhosphorIcons Width="12"
Height="12"
VerticalAlignment="Center"
Kind="Polygon" />
<Label VerticalAlignment="Center" Margin ="4 0" Padding="0" Content="Copy as WPF-PathGeometry" />
</StackPanel>
</mah:MetroHeader.Header>
<ctrls:CopyToClipboardTextBox FontFamily="Consolas" TextToCopy="{Binding CopyToClipboardWpfGeometry}" />
</mah:MetroHeader>

<!-- Content Markup -->
<mah:MetroHeader>
<mah:MetroHeader.Header>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Width="20"
Height="10"
VerticalAlignment="Center"
Kind="CodeBraces" />
<TextBlock VerticalAlignment="Center" Text="Copy icon as content" />
</StackPanel>
<iconPacks:PackIconPhosphorIcons Width="12"
Height="12"
VerticalAlignment="Center"
Kind="BracketsCurly" />
<Label VerticalAlignment="Center" Margin ="4 0" Padding="0" Content="Copy as content extension" />
</StackPanel>
</mah:MetroHeader.Header>
<ctrls:CopyToClipboardTextBox FontFamily="Consolas" TextToCopy="{Binding CopyToClipboardAsContentText}" />
</mah:MetroHeader>

<!-- Copy as UWP Control -->
<mah:MetroHeader>
<mah:MetroHeader.Header>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconFontAwesome Width="20"
Height="10"
VerticalAlignment="Center"
Kind="DrawPolygonSolid" />
<TextBlock VerticalAlignment="Center" Text="Copy icon as UWP-Control" />
</StackPanel>
<iconPacks:PackIconPhosphorIcons Width="12"
Height="12"
VerticalAlignment="Center"
Kind="BracketsAngle" />
<Label VerticalAlignment="Center" Margin ="4 0" Padding="0" Content="Copy as UWP-Control" />
</StackPanel>
</mah:MetroHeader.Header>
<ctrls:CopyToClipboardTextBox FontFamily="Consolas" TextToCopy="{Binding CopyToClipboardAsPathIconText}" />
Expand All @@ -191,13 +197,11 @@
<mah:MetroHeader>
<mah:MetroHeader.Header>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconMaterial Width="20"
Height="10"
VerticalAlignment="Center"
Kind="Draw" />
<TextBlock VerticalAlignment="Center" Text="Copy path data" />
</StackPanel>
<iconPacks:PackIconPhosphorIcons Width="12"
Height="12"
VerticalAlignment="Center"
Kind="Polygon" />
<Label VerticalAlignment="Center" Margin ="4 0" Padding="0" Content="Copy path data" />
</StackPanel>
</mah:MetroHeader.Header>
<ctrls:CopyToClipboardTextBox FontFamily="Consolas" TextToCopy="{Binding CopyToClipboardAsGeometryText}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<PathGeometry x:Key="@IconKind">@PathData</PathGeometry>
3 changes: 3 additions & 0 deletions src/IconPacks.Browser/IconPacks.Browser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@

<ItemGroup>
<_SettingsFiles Remove="Properties\Settings.settings" />
<None Update="ExportTemplates\Clipboard.WPF.Geometry.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="ExportTemplates\Clipboard.Content.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
16 changes: 8 additions & 8 deletions src/IconPacks.Browser/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
Height="22"
HorizontalAlignment="Center"
BorderThickness="0"
Command="{x:Static viewModels:MainViewModel.CopyTextToClipboardCommand}"
CommandParameter="{Binding CopyToClipboardText}"
Command="{x:Static viewModels:MainViewModel.CopyToClipboardTextCommand}"
CommandParameter="{Binding}"
Focusable="False"
IsTabStop="False"
Style="{StaticResource CustomMetroCircleButtonStyle}">
Expand All @@ -91,8 +91,8 @@
<Button Width="22"
Height="22"
BorderThickness="0"
Command="{x:Static viewModels:MainViewModel.CopyTextToClipboardCommand}"
CommandParameter="{Binding CopyToClipboardAsContentText}"
Command="{x:Static viewModels:MainViewModel.CopyToClipboardAsContentTextCommand}"
CommandParameter="{Binding}"
Focusable="False"
IsTabStop="False"
Style="{StaticResource CustomMetroCircleButtonStyle}">
Expand All @@ -106,8 +106,8 @@
<Button Width="22"
Height="22"
BorderThickness="0"
Command="{x:Static viewModels:MainViewModel.CopyTextToClipboardCommand}"
CommandParameter="{Binding CopyToClipboardAsPathIconText}"
Command="{x:Static viewModels:MainViewModel.CopyToClipboardAsPathIconTextCommand}"
CommandParameter="{Binding}"
Focusable="False"
IsTabStop="False"
Style="{StaticResource CustomMetroCircleButtonStyle}">
Expand All @@ -121,8 +121,8 @@
<Button Width="22"
Height="22"
BorderThickness="0"
Command="{x:Static viewModels:MainViewModel.CopyTextToClipboardCommand}"
CommandParameter="{Binding CopyToClipboardAsGeometryText}"
Command="{x:Static viewModels:MainViewModel.CopyToClipboardAsGeometryTextCommand}"
CommandParameter="{Binding}"
Focusable="False"
IsTabStop="False"
Style="{StaticResource CustomMetroCircleButtonStyle}">
Expand Down
31 changes: 29 additions & 2 deletions src/IconPacks.Browser/Model/ExportHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,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)
Expand All @@ -45,7 +57,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<string>
.Replace("@FillColor", parameters.FillColor)
.Replace("@Background", parameters.Background)
.Replace("@StrokeColor", parameters.StrokeColor)
Expand All @@ -71,7 +83,7 @@ internal static string LoadTemplateString(string fileName)
internal struct ExportParameters
{
/// <summary>
/// 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.
/// </summary>
/// <param name="icon"></param>
internal ExportParameters(IIconViewModel icon)
Expand All @@ -93,6 +105,8 @@ internal ExportParameters(IIconViewModel icon)

this.IconPackHomepage = metaData?.ProjectUrl;
this.IconPackLicense = metaData?.LicenseUrl;

this.PathData = (icon as IconViewModel)?.GetPackIconControlBase().Data;
}

internal string IconKind { get; set; }
Expand All @@ -110,4 +124,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<string> newValue)
{
if (input.Contains(oldValue))
{
return input.Replace(oldValue, newValue());
}

return input;
}
}
}
5 changes: 4 additions & 1 deletion src/IconPacks.Browser/ViewModels/IconPackViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ public interface IIconViewModel
object Value { get; set; }
MetaDataAttribute MetaData { get; set; }
string CopyToClipboardText { get; }
string CopyToClipboardWpfGeometry { get; }
string CopyToClipboardAsContentText { get; }
string CopyToClipboardAsPathIconText { get; }
string CopyToClipboardAsGeometryText { get; }
Expand All @@ -491,12 +492,13 @@ public IconViewModel(Type enumType, Type packType, Enum k, MetaDataAttribute met
}

public string CopyToClipboardText => ExportHelper.FillTemplate(ExportHelper.ClipboardWpf, new ExportParameters(this)); // $"<iconPacks:{IconPackType.Name} Kind=\"{Name}\" />";
public string CopyToClipboardWpfGeometry => ExportHelper.FillTemplate(ExportHelper.ClipboardWpfGeometry, new ExportParameters(this)); // $"<iconPacks:{IconPackType.Name} Kind=\"{Name}\" />";

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)); // $"<iconPacks:{IconPackType.Name.Replace("PackIcon", "PathIcon")} Kind=\"{Name}\" />";

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; }

Expand All @@ -515,6 +517,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);
Expand Down
Loading

0 comments on commit 94066f5

Please sign in to comment.