Skip to content

Commit

Permalink
fix: path data generation
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Jun 6, 2024
1 parent c47c609 commit eda0e82
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 66 deletions.
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
71 changes: 30 additions & 41 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="150" MinHeight="50" />
<RowDefinition Height="250" MinHeight="50" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
Expand Down Expand Up @@ -81,10 +81,9 @@

<StackPanel Grid.Row="2">

<Expander Margin="0 2 0 0" Header="Icon Information" IsExpanded="False">
<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="False">
Header="Preview options">
<StackPanel>
<mah:MetroHeader Header="Iconsize ">
<ComboBox x:Name="ComboBoxIconPreviewSize"
Expand Down Expand Up @@ -145,13 +143,11 @@
<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}" />
Expand All @@ -160,13 +156,11 @@
<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-PathGeometry" />
</StackPanel>
<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}" />
Expand All @@ -176,28 +170,25 @@
<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 @@ -206,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
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
17 changes: 3 additions & 14 deletions src/IconPacks.Browser/Model/ExportHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Globalization;
using System.IO;
using System.Windows.Media;

using IconPacks.Browser.Properties;
using IconPacks.Browser.ViewModels;

Expand All @@ -29,7 +28,7 @@ internal class ExportHelper
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;

Expand Down Expand Up @@ -107,26 +106,16 @@ internal ExportParameters(IIconViewModel icon)
this.IconPackHomepage = metaData?.ProjectUrl;
this.IconPackLicense = metaData?.LicenseUrl;

//this.PathData = (icon as IconViewModel)?.GetPackIconControlBase().Data;
_pathDataLazy = new Lazy<string>(() => (icon as IconViewModel)?.GetPackIconControlBase().Data);
this.PathData = (icon as IconViewModel)?.GetPackIconControlBase().Data;
}

private Lazy<string> _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 => _pathData ?? _pathDataLazy.Value;
set => _pathData = value;
}

internal string PathData { get; set; }
internal string FillColor { get; set; }
internal string Background { get; set; }
internal string StrokeColor { get; set; }
Expand Down
1 change: 1 addition & 0 deletions 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 Down
35 changes: 34 additions & 1 deletion src/IconPacks.Browser/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,46 @@ private void ApplyFilterText(string filterText)
}
}

private static void DoCopyTextToClipboard(string text)
{
Application.Current.Dispatcher.BeginInvoke(new Action(() => { Clipboard.SetDataObject(text); }));
}

public static ICommand CopyTextToClipboardCommand { get; } =
new SimpleCommand
{
CanExecuteDelegate = x => (x is string),
ExecuteDelegate = x => Application.Current.Dispatcher.BeginInvoke(new Action(() => { Clipboard.SetDataObject(x as string); }))
ExecuteDelegate = x => DoCopyTextToClipboard((string)x)
};

public static ICommand CopyToClipboardTextCommand { get; } =
new SimpleCommand
{
CanExecuteDelegate = x => (x is IIconViewModel),
ExecuteDelegate = x => DoCopyTextToClipboard(((IIconViewModel)x).CopyToClipboardText)
};

public static ICommand CopyToClipboardAsContentTextCommand { get; } =
new SimpleCommand
{
CanExecuteDelegate = x => (x is IIconViewModel),
ExecuteDelegate = x => DoCopyTextToClipboard(((IIconViewModel)x).CopyToClipboardAsContentText)
};

public static ICommand CopyToClipboardAsPathIconTextCommand { get; } =
new SimpleCommand
{
CanExecuteDelegate = x => (x is IIconViewModel),
ExecuteDelegate = x => DoCopyTextToClipboard(((IIconViewModel)x).CopyToClipboardAsPathIconText)
};

public static ICommand CopyToClipboardAsGeometryTextCommand { get; } =
new SimpleCommand
{
CanExecuteDelegate = x => (x is IIconViewModel),
ExecuteDelegate = x => DoCopyTextToClipboard(((IIconViewModel)x).CopyToClipboardAsGeometryText)
};

public SettingsViewModel Settings { get; }
}
}

0 comments on commit eda0e82

Please sign in to comment.