Skip to content

Commit cc7518f

Browse files
committed
switch data binding to custom type vs. dictionary
1 parent 4f8b15e commit cc7518f

3 files changed

Lines changed: 27 additions & 16 deletions

File tree

SharpFM.App/MainWindow.axaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@
4040
<TextBox Text="{Binding Name, Mode=TwoWay}" Margin="0" />
4141
<ComboBox
4242
ItemsSource="{Binding ClipTypes}"
43-
SelectedValue="{Binding ClipboardFormat, Mode=TwoWay}">
43+
SelectedValue="{Binding ClipboardFormat, Mode=TwoWay}"
44+
SelectedValueBinding="{Binding KeyId}"
45+
DisplayMemberBinding="{Binding DisplayName}"
46+
>
4447
</ComboBox>
45-
<TextBlock Text="{Binding ClipboardFormat}"
46-
MaxLines="1" />
48+
<TextBlock Text="{Binding ClipboardFormat}" MaxLines="1" />
4749
</StackPanel>
4850
</DataTemplate>
4951
</ListBox.ItemTemplate>

SharpFM.Core/FileMakerClip.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
34
using System.IO;
45
using System.Linq;
56
using System.Text;
@@ -11,14 +12,20 @@ namespace SharpFM.Core;
1112

1213
public class FileMakerClip
1314
{
14-
public static Dictionary<string, string> ClipTypes { get; set; } = new Dictionary<string, string>
15-
{
16-
{ "Mac-XMSS", "ScriptSteps" },
17-
{ "Mac-XML2", "Layout" },
18-
{ "Mac-XMTB", "Table" },
19-
{ "Mac-XMFD", "Field" },
20-
{ "Mac-XMSC", "Script" }
21-
};
15+
public class ClipFormat
16+
{
17+
public string KeyId { get; set; } = string.Empty;
18+
public string DisplayName { get; set; } = string.Empty;
19+
}
20+
21+
public static List<ClipFormat> ClipTypes { get; set; } = new List<ClipFormat>
22+
{
23+
new ClipFormat() { KeyId = "Mac-XMSS", DisplayName = "ScriptSteps" },
24+
new ClipFormat() { KeyId = "Mac-XML2", DisplayName = "Layout" },
25+
new ClipFormat() { KeyId = "Mac-XMTB", DisplayName = "Table" },
26+
new ClipFormat() { KeyId = "Mac-XMFD", DisplayName = "Field" },
27+
new ClipFormat() { KeyId = "Mac-XMSC", DisplayName = "Script" }
28+
};
2229

2330
/// <summary>
2431
/// Constructor taking in the raw data byte array.
@@ -83,7 +90,9 @@ public IEnumerable<FileMakerField> Fields
8390
{
8491
var xdoc = XDocument.Parse(XmlData);
8592

86-
switch (ClipTypes[ClipboardFormat])
93+
var clipType = ClipTypes.SingleOrDefault(ct => ct.KeyId == ClipboardFormat);
94+
95+
switch (clipType.DisplayName)
8796
{
8897
case "Table": // When we have a table, we can get rich metadata from the clipboard data.
8998
return xdoc

SharpFM.Core/FileMakerClipExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public static class FileMakerClipExtensions
1515
/// </summary>
1616
public static string CreateClass(this FileMakerClip _clip, FileMakerClip? fieldProjectionLayout = null)
1717
{
18-
if(_clip == null) { return string.Empty; }
18+
if (_clip == null) { return string.Empty; }
1919

2020
var fieldProjectionList = new List<string>();
21-
if (fieldProjectionLayout != null && FileMakerClip.ClipTypes[fieldProjectionLayout.ClipboardFormat] == "Layout")
21+
if (fieldProjectionLayout != null && FileMakerClip.ClipTypes.Single(ct => ct.KeyId == fieldProjectionLayout.ClipboardFormat).DisplayName == "Layout")
2222
{
2323
// a clip that is of type layout, only has name attribute (since the rest isn't available)
2424
// and we only need the name to skip it down below
@@ -55,7 +55,7 @@ public static string CreateClass(this FileMakerClip _clip, IEnumerable<string> f
5555
classDeclaration = classDeclaration.AddAttributeLists(SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(dataContractAttribute)));
5656

5757
// add each field from the underling _clip as a public property with the data member attribute
58-
List <PropertyDeclarationSyntax> fieldsToBeAddedAsProperties = new List<PropertyDeclarationSyntax>(_clip.Fields.Count());
58+
List<PropertyDeclarationSyntax> fieldsToBeAddedAsProperties = new List<PropertyDeclarationSyntax>(_clip.Fields.Count());
5959
// include the field projection
6060
foreach (var field in _clip.Fields.Where(fmF => fieldProjectionList.Contains(fmF.Name)))
6161
{
@@ -87,7 +87,7 @@ public static string CreateClass(this FileMakerClip _clip, IEnumerable<string> f
8787
break;
8888
}
8989

90-
if(field.NotEmpty == false && propertyTypeCSharp != "string")
90+
if (field.NotEmpty == false && propertyTypeCSharp != "string")
9191
{
9292
propertyTypeCSharp += "?";
9393
}

0 commit comments

Comments
 (0)