Skip to content

Commit 517d5f8

Browse files
committed
wip: binding for model generation
1 parent 7a2c3fd commit 517d5f8

5 files changed

Lines changed: 70 additions & 21 deletions

File tree

SharpFM.App/LayoutClipPicker.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
SecondaryButtonClick="ContentDialog_SecondaryButtonClick">
1414

1515
<Grid>
16-
<ComboBox x:Name="LayoutPickerCombo" HorizontalAlignment="Stretch" Margin="0,0,10,0" ItemsSource="{Binding Layouts}" DisplayMemberPath="Name" />
16+
<ComboBox x:Name="LayoutPickerCombo" HorizontalAlignment="Stretch" ItemsSource="{Binding Layouts}" DisplayMemberPath="Name" Height="45" VerticalAlignment="Center" />
1717
</Grid>
1818
</ContentDialog>

SharpFM.App/MainPage.xaml

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@
1212
DataContext="{Binding RelativeSource={RelativeSource Self}}"
1313
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
1414

15-
<Grid>
15+
<Grid DataContext="{Binding}">
16+
<Grid.ColumnDefinitions>
17+
<ColumnDefinition Width="*" />
18+
<ColumnDefinition Width="350" />
19+
</Grid.ColumnDefinitions>
1620

17-
<controls:MasterDetailsView ItemsSource="{Binding Keys}"
18-
NoSelectionContent="No Clip Selected"
19-
CompactModeThresholdWidth="720"
20-
x:Name="mdv" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
21+
<controls:MasterDetailsView
22+
x:Name="mdv"
23+
Grid.Column="0"
24+
ItemsSource="{Binding Keys}"
25+
SelectedItem="{Binding Path=SelectedClip}"
26+
AllowFocusOnInteraction="True"
27+
NoSelectionContent="No Clip Selected"
28+
CompactModeThresholdWidth="720"
29+
HorizontalAlignment="Stretch"
30+
VerticalAlignment="Stretch">
2131

2232
<controls:MasterDetailsView.ItemTemplate>
2333
<DataTemplate>
@@ -37,9 +47,12 @@
3747

3848
<controls:MasterDetailsView.DetailsTemplate>
3949
<DataTemplate>
40-
<monaco:CodeEditor x:Name="XamlCodeRenderer"
41-
CodeLanguage="xml"
42-
Text="{ Binding XmlData, Mode=TwoWay}" />
50+
51+
52+
<monaco:CodeEditor x:Name="XamlCodeRenderer"
53+
CodeLanguage="xml"
54+
Text="{ Binding XmlData, Mode=TwoWay}" />
55+
4356
</DataTemplate>
4457
</controls:MasterDetailsView.DetailsTemplate>
4558

@@ -88,5 +101,25 @@
88101

89102
</controls:MasterDetailsView>
90103

104+
<StackPanel Grid.Column="1" Width="350" Height="Auto" DataContext="{Binding}">
105+
<ComboBox x:Name="LayoutPickerComboBox"
106+
HorizontalAlignment="Stretch"
107+
ItemsSource="{Binding Layouts}"
108+
SelectedItem="{Binding SelectedLayout}"
109+
DisplayMemberPath="Name"
110+
Height="45"
111+
VerticalAlignment="Center" />
112+
113+
<TextBlock>
114+
<Run Text="Clip Name: " />
115+
<Run Text="{Binding Path=SelectedLayout.Name}" />
116+
</TextBlock>
117+
118+
119+
<!--<monaco:CodeEditor x:Name="XamlCodeRendererCsharp"
120+
CodeLanguage="csharp"
121+
Text="{ Binding SelectedClip.XmlData, Mode=OneWay}" />-->
122+
</StackPanel>
123+
91124
</Grid>
92125
</Page>

SharpFM.App/MainPage.xaml.cs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
using Windows.UI.Popups;
1212
using Windows.UI.Xaml;
1313
using Windows.UI.Xaml.Controls;
14+
using Windows.UI.Xaml.Controls.Primitives;
15+
using Windows.UI.Xaml.Data;
1416

1517
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
1618

@@ -22,19 +24,29 @@ namespace SharpFM.App
2224
public sealed partial class MainPage : Page
2325
{
2426
public ObservableCollection<FileMakerClip> Keys { get; }
25-
public ObservableCollection<FileMakerClip> Layouts
26-
{
27-
get
28-
{
29-
return new ObservableCollection<FileMakerClip>(Keys.Where(k => FileMakerClip.ClipTypes[k.ClipboardFormat] == "Layout"));
30-
}
31-
}
27+
28+
public ObservableCollection<FileMakerClip> Layouts { get; }
29+
30+
public FileMakerClip SelectedLayout { get; set; }
31+
public FileMakerClip SelectedClip { get; set; }
32+
33+
public string SelectedClipAsCsharp { get; set; }
3234

3335
public MainPage()
3436
{
3537
InitializeComponent();
3638

3739
Keys = new ObservableCollection<FileMakerClip>();
40+
Layouts = new ObservableCollection<FileMakerClip>();
41+
42+
Keys.CollectionChanged += (sender, e) =>
43+
{
44+
Layouts.Clear();
45+
foreach (var layout in Keys.Where(k => FileMakerClip.ClipTypes[k.ClipboardFormat] == "Layout"))
46+
{
47+
Layouts.Add(layout);
48+
}
49+
};
3850

3951
Clipboard.ContentChanged += Clipboard_ContentChanged;
4052
}
@@ -120,12 +132,11 @@ private void masterNewScript_Click(object sender, RoutedEventArgs e)
120132
private async void asModelAppBarButton_Click(object sender, RoutedEventArgs e)
121133
{
122134
// TODO: improve the UX of this whole thing. This works as a hack for proving the concept, but it could be so much better.
123-
124135
var data = mdv.SelectedItem as FileMakerClip;
125136

126137
var md = new MessageDialog("Do you want to use a layout to limit the number of fields in the generated model?", "Use Layout Projection?");
127138
// setup the command that will show the Layout picker and generate content that way
128-
md.Commands.Add(new UICommand("Pick a Layout", new UICommandInvokedHandler(async uic =>
139+
md.Commands.Add(new UICommand("Use Layout", new UICommandInvokedHandler(async uic =>
129140
{
130141
var picker = new LayoutClipPicker
131142
{
@@ -135,7 +146,7 @@ private async void asModelAppBarButton_Click(object sender, RoutedEventArgs e)
135146
if (pickerResult == ContentDialogResult.Primary)
136147
{
137148
// regenerate using the layout picker
138-
var classString = data.CreateClass(picker.DialogResult);
149+
var classString = data.CreateClass(SelectedLayout);
139150
var dp = new DataPackage();
140151
dp.SetText(classString);
141152
Clipboard.SetContent(dp);
@@ -155,5 +166,10 @@ private async void asModelAppBarButton_Click(object sender, RoutedEventArgs e)
155166

156167
var result = await md.ShowAsync();
157168
}
169+
170+
//private void LayoutPickerComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
171+
//{
172+
// SelectedLayout = ((ComboBox)sender).SelectedItem as FileMakerClip;
173+
//}
158174
}
159175
}

SharpFM.Core/FileMakerClip.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ public byte[] RawData
7777
/// </summary>
7878
public string XmlData { get; set; }
7979

80-
81-
8280
/// <summary>
8381
/// The fields exposed through this FileMaker Clip (if its a table or a layout).
8482
/// </summary>

SharpFM.Core/FileMakerClipExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public static class FileMakerClipExtensions
1414
/// </summary>
1515
public static string CreateClass(this FileMakerClip _clip, FileMakerClip fieldProjectionLayout = null)
1616
{
17+
if(_clip == null) { return string.Empty; }
18+
1719
var fieldProjectionList = new List<string>();
1820
if (fieldProjectionLayout != null && FileMakerClip.ClipTypes[fieldProjectionLayout.ClipboardFormat] == "Layout")
1921
{

0 commit comments

Comments
 (0)