Skip to content

Commit

Permalink
wip: binding for model generation
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzzerd committed Sep 27, 2019
1 parent 7a2c3fd commit 517d5f8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 21 deletions.
2 changes: 1 addition & 1 deletion SharpFM.App/LayoutClipPicker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
SecondaryButtonClick="ContentDialog_SecondaryButtonClick">

<Grid>
<ComboBox x:Name="LayoutPickerCombo" HorizontalAlignment="Stretch" Margin="0,0,10,0" ItemsSource="{Binding Layouts}" DisplayMemberPath="Name" />
<ComboBox x:Name="LayoutPickerCombo" HorizontalAlignment="Stretch" ItemsSource="{Binding Layouts}" DisplayMemberPath="Name" Height="45" VerticalAlignment="Center" />
</Grid>
</ContentDialog>
49 changes: 41 additions & 8 deletions SharpFM.App/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<Grid DataContext="{Binding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="350" />
</Grid.ColumnDefinitions>

<controls:MasterDetailsView ItemsSource="{Binding Keys}"
NoSelectionContent="No Clip Selected"
CompactModeThresholdWidth="720"
x:Name="mdv" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<controls:MasterDetailsView
x:Name="mdv"
Grid.Column="0"
ItemsSource="{Binding Keys}"
SelectedItem="{Binding Path=SelectedClip}"
AllowFocusOnInteraction="True"
NoSelectionContent="No Clip Selected"
CompactModeThresholdWidth="720"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">

<controls:MasterDetailsView.ItemTemplate>
<DataTemplate>
Expand All @@ -37,9 +47,12 @@

<controls:MasterDetailsView.DetailsTemplate>
<DataTemplate>
<monaco:CodeEditor x:Name="XamlCodeRenderer"
CodeLanguage="xml"
Text="{ Binding XmlData, Mode=TwoWay}" />


<monaco:CodeEditor x:Name="XamlCodeRenderer"
CodeLanguage="xml"
Text="{ Binding XmlData, Mode=TwoWay}" />

</DataTemplate>
</controls:MasterDetailsView.DetailsTemplate>

Expand Down Expand Up @@ -88,5 +101,25 @@

</controls:MasterDetailsView>

<StackPanel Grid.Column="1" Width="350" Height="Auto" DataContext="{Binding}">
<ComboBox x:Name="LayoutPickerComboBox"
HorizontalAlignment="Stretch"
ItemsSource="{Binding Layouts}"
SelectedItem="{Binding SelectedLayout}"
DisplayMemberPath="Name"
Height="45"
VerticalAlignment="Center" />

<TextBlock>
<Run Text="Clip Name: " />
<Run Text="{Binding Path=SelectedLayout.Name}" />
</TextBlock>


<!--<monaco:CodeEditor x:Name="XamlCodeRendererCsharp"
CodeLanguage="csharp"
Text="{ Binding SelectedClip.XmlData, Mode=OneWay}" />-->
</StackPanel>

</Grid>
</Page>
36 changes: 26 additions & 10 deletions SharpFM.App/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;

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

Expand All @@ -22,19 +24,29 @@ namespace SharpFM.App
public sealed partial class MainPage : Page
{
public ObservableCollection<FileMakerClip> Keys { get; }
public ObservableCollection<FileMakerClip> Layouts
{
get
{
return new ObservableCollection<FileMakerClip>(Keys.Where(k => FileMakerClip.ClipTypes[k.ClipboardFormat] == "Layout"));
}
}

public ObservableCollection<FileMakerClip> Layouts { get; }

public FileMakerClip SelectedLayout { get; set; }
public FileMakerClip SelectedClip { get; set; }

public string SelectedClipAsCsharp { get; set; }

public MainPage()
{
InitializeComponent();

Keys = new ObservableCollection<FileMakerClip>();
Layouts = new ObservableCollection<FileMakerClip>();

Keys.CollectionChanged += (sender, e) =>
{
Layouts.Clear();
foreach (var layout in Keys.Where(k => FileMakerClip.ClipTypes[k.ClipboardFormat] == "Layout"))
{
Layouts.Add(layout);
}
};

Clipboard.ContentChanged += Clipboard_ContentChanged;
}
Expand Down Expand Up @@ -120,12 +132,11 @@ private void masterNewScript_Click(object sender, RoutedEventArgs e)
private async void asModelAppBarButton_Click(object sender, RoutedEventArgs e)
{
// TODO: improve the UX of this whole thing. This works as a hack for proving the concept, but it could be so much better.

var data = mdv.SelectedItem as FileMakerClip;

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

var result = await md.ShowAsync();
}

//private void LayoutPickerComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
//{
// SelectedLayout = ((ComboBox)sender).SelectedItem as FileMakerClip;
//}
}
}
2 changes: 0 additions & 2 deletions SharpFM.Core/FileMakerClip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ public byte[] RawData
/// </summary>
public string XmlData { get; set; }



/// <summary>
/// The fields exposed through this FileMaker Clip (if its a table or a layout).
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions SharpFM.Core/FileMakerClipExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public static class FileMakerClipExtensions
/// </summary>
public static string CreateClass(this FileMakerClip _clip, FileMakerClip fieldProjectionLayout = null)
{
if(_clip == null) { return string.Empty; }

var fieldProjectionList = new List<string>();
if (fieldProjectionLayout != null && FileMakerClip.ClipTypes[fieldProjectionLayout.ClipboardFormat] == "Layout")
{
Expand Down

0 comments on commit 517d5f8

Please sign in to comment.