Skip to content

Commit

Permalink
layout projection
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzzerd committed Sep 27, 2019
1 parent adc3c32 commit 7a2c3fd
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 19 deletions.
12 changes: 1 addition & 11 deletions SharpFM.App/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace SharpFM.App
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Application
public sealed partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
Expand Down
18 changes: 18 additions & 0 deletions SharpFM.App/LayoutClipPicker.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<ContentDialog
x:Class="SharpFM.App.LayoutClipPicker"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SharpFM.App"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="TITLE"
PrimaryButtonText="Select"
SecondaryButtonText="Cancel"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
SecondaryButtonClick="ContentDialog_SecondaryButtonClick">

<Grid>
<ComboBox x:Name="LayoutPickerCombo" HorizontalAlignment="Stretch" Margin="0,0,10,0" ItemsSource="{Binding Layouts}" DisplayMemberPath="Name" />
</Grid>
</ContentDialog>
39 changes: 39 additions & 0 deletions SharpFM.App/LayoutClipPicker.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using SharpFM.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Content Dialog item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace SharpFM.App
{
public sealed partial class LayoutClipPicker : ContentDialog
{
public FileMakerClip DialogResult { get; private set; }

public LayoutClipPicker()
{
this.InitializeComponent();
}

private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
DialogResult = LayoutPickerCombo.SelectedItem as FileMakerClip;
}

private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
}
}
}
49 changes: 43 additions & 6 deletions SharpFM.App/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage.Streams;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

Expand All @@ -20,6 +22,13 @@ 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 MainPage()
{
Expand Down Expand Up @@ -108,15 +117,43 @@ private void masterNewScript_Click(object sender, RoutedEventArgs e)
Keys.Add(new FileMakerClip("", "Mac-XMSS", Array.Empty<byte>()));
}

private void asModelAppBarButton_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 classString = data.CreateClass();

var dp = new DataPackage();
dp.SetText(classString);
Clipboard.SetContent(dp);
Clipboard.Flush();
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 =>
{
var picker = new LayoutClipPicker
{
DataContext = this.DataContext
};
var pickerResult = await picker.ShowAsync(ContentDialogPlacement.InPlace);
if (pickerResult == ContentDialogResult.Primary)
{
// regenerate using the layout picker
var classString = data.CreateClass(picker.DialogResult);
var dp = new DataPackage();
dp.SetText(classString);
Clipboard.SetContent(dp);
Clipboard.Flush();
}
})));

// setup the command that will generate the full model
md.Commands.Add(new UICommand("No Projection", new UICommandInvokedHandler(uic =>
{
var classString = data.CreateClass();
var dp = new DataPackage();
dp.SetText(classString);
Clipboard.SetContent(dp);
Clipboard.Flush();
})));

var result = await md.ShowAsync();
}
}
}
7 changes: 7 additions & 0 deletions SharpFM.App/SharpFM.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="LayoutClipPicker.xaml.cs">
<DependentUpon>LayoutClipPicker.xaml</DependentUpon>
</Compile>
<Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
Expand All @@ -127,6 +130,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="LayoutClipPicker.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
3 changes: 2 additions & 1 deletion SharpFM.Core/FileMakerClip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;

Expand Down Expand Up @@ -110,7 +111,7 @@ public IEnumerable<FileMakerField> Fields
.Where(x => x.Attribute("type").Value == "Field")
.Descendants("FieldObj")
.Elements("Name")
.Select(x => new FileMakerField { Name = x.Value });
.Select(x => new FileMakerField { Name = Regex.Split(x.Value, "::")[1]});
}

// return emptyl ist of we don't have a matching type
Expand Down
2 changes: 1 addition & 1 deletion SharpFM.Core/FileMakerClipExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class FileMakerClipExtensions
public static string CreateClass(this FileMakerClip _clip, FileMakerClip fieldProjectionLayout = null)
{
var fieldProjectionList = new List<string>();
if (fieldProjectionLayout != null && fieldProjectionLayout.ClipboardFormat == "Layout")
if (fieldProjectionLayout != null && FileMakerClip.ClipTypes[fieldProjectionLayout.ClipboardFormat] == "Layout")
{
// a clip that is of type layout, only has name attribute (since the rest isn't available)
// and we only need the name to skip it down below
Expand Down

0 comments on commit 7a2c3fd

Please sign in to comment.