Skip to content

Commit 11dd3d7

Browse files
committed
Merge pull request #4 from ScottIsAFool/feature/manifest
Feature manifest
2 parents 6556a9f + f26db38 commit 11dd3d7

16 files changed

+641
-40
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,5 @@ pip-log.txt
178178
.DS_Store
179179

180180
lib
181+
*.msi
182+
*.exe
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<UserControl x:Class="LiveWriterPluginManager.Controls.CreatePackageControl"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:viewModel="clr-namespace:LiveWriterPluginManager.ViewModel"
7+
mc:Ignorable="d"
8+
d:DesignHeight="300"
9+
d:DesignWidth="300"
10+
DataContext="{Binding CreatePackage, Source={StaticResource Locator}}">
11+
12+
<UserControl.Resources>
13+
<DataTemplate DataType="{x:Type viewModel:FileViewModel}">
14+
<Border BorderBrush="{StaticResource LiveWriterPurpleBrush}"
15+
BorderThickness="0,0,0,1"
16+
Padding="10">
17+
<Grid>
18+
<Grid.ColumnDefinitions>
19+
<ColumnDefinition Width="*" />
20+
<ColumnDefinition Width="Auto" />
21+
<ColumnDefinition Width="Auto" />
22+
</Grid.ColumnDefinitions>
23+
24+
<TextBlock Text="{Binding Name}"
25+
VerticalAlignment="Center" />
26+
27+
<Button Content="This is the plugin"
28+
Grid.Column="1"
29+
Command="{Binding SetPluginFileCommand}"
30+
Margin="10,0">
31+
<Button.Style>
32+
<Style TargetType="{x:Type Button}"
33+
BasedOn="{StaticResource {x:Type Button}}">
34+
<!-- This would be the default visibility -->
35+
<Setter Property="Visibility"
36+
Value="Visible" />
37+
<Style.Triggers>
38+
<DataTrigger Binding="{Binding IsPluginFile, UpdateSourceTrigger=PropertyChanged}"
39+
Value="True">
40+
<Setter Property="Visibility"
41+
Value="Hidden" />
42+
</DataTrigger>
43+
</Style.Triggers>
44+
</Style>
45+
</Button.Style>
46+
</Button>
47+
48+
<Button Grid.Column="2"
49+
Style="{StaticResource MaterialDesignFloatingActionMiniAccentButton}"
50+
Height="30"
51+
Width="30"
52+
Command="{Binding RemoveFileCommand}">
53+
<Viewbox Stretch="Uniform"
54+
StretchDirection="DownOnly"
55+
Width="20"
56+
Height="20"
57+
HorizontalAlignment="Center"
58+
VerticalAlignment="Center">
59+
<Path Height="15"
60+
Width="10"
61+
Stretch="Fill"
62+
Fill="White"
63+
Data="M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z" />
64+
</Viewbox>
65+
</Button>
66+
</Grid>
67+
</Border>
68+
</DataTemplate>
69+
</UserControl.Resources>
70+
<Border Background="Transparent"
71+
AllowDrop="True"
72+
Drop="UIElement_OnDrop">
73+
<Grid>
74+
<Grid.RowDefinitions>
75+
<RowDefinition Height="Auto" />
76+
<RowDefinition Height="*" />
77+
<RowDefinition Height="Auto" />
78+
</Grid.RowDefinitions>
79+
80+
<StackPanel>
81+
<TextBlock Text="Please choose the files that you would like to add to your package."
82+
TextWrapping="WrapWithOverflow"
83+
Margin="10" />
84+
<StackPanel Orientation="Horizontal">
85+
<Button Content="Add files"
86+
HorizontalAlignment="Left"
87+
Margin="10,0,10,10"
88+
Command="{Binding AddFilesCommand}" />
89+
<Button Content="Edit metadata"
90+
Margin="10,0,10,10"
91+
Command="{Binding EditMetadataCommand}" />
92+
<Button Content="Open package"
93+
Margin="10,0,10,10"
94+
Command="{Binding OpenPackageCommand}" />
95+
</StackPanel>
96+
</StackPanel>
97+
98+
<ListView ItemsSource="{Binding Files}"
99+
Grid.Row="1" />
100+
101+
<Button Content="Create package"
102+
Grid.Row="2"
103+
HorizontalAlignment="Right"
104+
Margin="10"
105+
IsEnabled="{Binding IsValidPackage}"
106+
Command="{Binding CreatePackageCommand}"
107+
AllowDrop="True"
108+
Drop="UIElement_OnDrop" />
109+
110+
111+
</Grid>
112+
</Border>
113+
</UserControl>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Linq;
2+
using System.Windows;
3+
using System.Windows.Controls;
4+
using LiveWriterPluginManager.Model;
5+
using LiveWriterPluginManager.ViewModel;
6+
7+
namespace LiveWriterPluginManager.Controls
8+
{
9+
/// <summary>
10+
/// Interaction logic for CreatePluginControl.xaml
11+
/// </summary>
12+
public partial class CreatePackageControl : UserControl
13+
{
14+
public CreatePackageControl()
15+
{
16+
InitializeComponent();
17+
}
18+
19+
private async void UIElement_OnDrop(object sender, DragEventArgs e)
20+
{
21+
if (e.Data.GetDataPresent(DataFormats.FileDrop))
22+
{
23+
var files = (string[])e.Data.GetData(DataFormats.FileDrop);
24+
var fileVms = files.Select(x => new FileViewModel(x));
25+
var packageFile = fileVms.FirstOrDefault(x => x.Extension == ".olwpkg");
26+
var vm = DataContext as CreatePackageViewModel;
27+
28+
if (packageFile != null)
29+
{
30+
await vm?.OpenPackage(packageFile.Path);
31+
}
32+
else
33+
{
34+
vm?.AddFiles(files);
35+
}
36+
}
37+
}
38+
}
39+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<UserControl x:Class="LiveWriterPluginManager.Controls.MetadataControl"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:wpf="http://materialdesigninxaml.net/winfx/xaml/themes"
7+
mc:Ignorable="d"
8+
d:DesignHeight="300"
9+
d:DesignWidth="300"
10+
MinWidth="300"
11+
DataContext="{Binding CreatePackage.ManifestViewModel, Source={StaticResource Locator}}">
12+
13+
<UserControl.Resources>
14+
<Style TargetType="TextBox"
15+
BasedOn="{StaticResource MaterialDesignFloatingHintTextBox}">
16+
<Setter Property="Margin"
17+
Value="0,5"/>
18+
</Style>
19+
</UserControl.Resources>
20+
21+
<Grid>
22+
<ScrollViewer VerticalScrollBarVisibility="Auto">
23+
<StackPanel Orientation="Vertical"
24+
Margin="10">
25+
<TextBox x:Name="Name"
26+
Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
27+
wpf:TextFieldAssist.Hint="Plugin name"/>
28+
<TextBox x:Name="Author"
29+
Text="{Binding Author, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
30+
wpf:TextFieldAssist.Hint="Author"/>
31+
<TextBox x:Name="ProjectUrl"
32+
Text="{Binding ProjectUrl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
33+
wpf:TextFieldAssist.Hint="Project Url" />
34+
<TextBox x:Name="TermsUrl"
35+
Text="{Binding TermsUrl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
36+
wpf:TextFieldAssist.Hint="Terms Url" />
37+
<TextBox x:Name="Version"
38+
Text="{Binding Version, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
39+
wpf:TextFieldAssist.Hint="Version" />
40+
<TextBox x:Name="WriterVersion"
41+
Text="{Binding TargetWriterVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
42+
wpf:TextFieldAssist.Hint="Target Writer version" />
43+
44+
<Button Content="Save"
45+
Margin="10"
46+
Command="{x:Static wpf:DialogHost.CloseDialogCommand}"/>
47+
</StackPanel>
48+
</ScrollViewer>
49+
</Grid>
50+
</UserControl>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace LiveWriterPluginManager.Controls
2+
{
3+
/// <summary>
4+
/// Interaction logic for MetadataControl.xaml
5+
/// </summary>
6+
public partial class MetadataControl
7+
{
8+
public MetadataControl()
9+
{
10+
InitializeComponent();
11+
}
12+
}
13+
}

LiveWriterPluginManager/Helpers/AppHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ namespace LiveWriterPluginManager.Helpers
1212
{
1313
public static class AppHelper
1414
{
15+
public const string SetPluginFileMsg = "SetPluginFileMsg";
1516
public const string RemovePluginMsg = "RemovePluginMsg";
17+
public const string RemoveFileMsg = "RemoveFileMsg";
1618

1719
static AppHelper()
1820
{

LiveWriterPluginManager/LiveWriterPluginManager.csproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@
115115
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
116116
<Private>True</Private>
117117
</Reference>
118+
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
119+
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
120+
<Private>True</Private>
121+
</Reference>
118122
<Reference Include="NuGet.Squirrel, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
119123
<HintPath>..\packages\squirrel.windows.1.2.3\lib\Net45\NuGet.Squirrel.dll</HintPath>
120124
<Private>True</Private>
@@ -167,6 +171,9 @@
167171
<Compile Include="Controls\AddPluginControl.xaml.cs">
168172
<DependentUpon>AddPluginControl.xaml</DependentUpon>
169173
</Compile>
174+
<Compile Include="Controls\CreatePackageControl.xaml.cs">
175+
<DependentUpon>CreatePackageControl.xaml</DependentUpon>
176+
</Compile>
170177
<Compile Include="Controls\Messages\ErrorControl.xaml.cs">
171178
<DependentUpon>ErrorControl.xaml</DependentUpon>
172179
</Compile>
@@ -176,18 +183,23 @@
176183
<Compile Include="Controls\Messages\QuestionControl.xaml.cs">
177184
<DependentUpon>QuestionControl.xaml</DependentUpon>
178185
</Compile>
186+
<Compile Include="Controls\MetadataControl.xaml.cs">
187+
<DependentUpon>MetadataControl.xaml</DependentUpon>
188+
</Compile>
179189
<Compile Include="Controls\RemovePluginControl.xaml.cs">
180190
<DependentUpon>RemovePluginControl.xaml</DependentUpon>
181191
</Compile>
182192
<Compile Include="Extensions\ContainerExtensions.cs" />
183193
<Compile Include="Helpers\AppHelper.cs" />
194+
<Compile Include="Model\Manifest.cs" />
184195
<Compile Include="Model\Plugin.cs" />
185196
<Compile Include="Services\FileService.cs" />
186197
<Compile Include="Services\LiveWriterService.cs" />
187198
<Compile Include="Services\MessageService.cs" />
188199
<Compile Include="Services\ZipService.cs" />
189200
<Compile Include="ViewModel\AboutViewModel.cs" />
190201
<Compile Include="ViewModel\AddPluginViewModel.cs" />
202+
<Compile Include="ViewModel\CreatePackageViewModel.cs" />
191203
<Compile Include="ViewModel\MainViewModel.cs" />
192204
<Compile Include="ViewModel\PluginViewModel.cs" />
193205
<Compile Include="ViewModel\RemovePluginViewModel.cs" />
@@ -200,6 +212,10 @@
200212
<SubType>Designer</SubType>
201213
<Generator>MSBuild:Compile</Generator>
202214
</Page>
215+
<Page Include="Controls\CreatePackageControl.xaml">
216+
<SubType>Designer</SubType>
217+
<Generator>MSBuild:Compile</Generator>
218+
</Page>
203219
<Page Include="Controls\Messages\ErrorControl.xaml">
204220
<SubType>Designer</SubType>
205221
<Generator>MSBuild:Compile</Generator>
@@ -212,6 +228,10 @@
212228
<SubType>Designer</SubType>
213229
<Generator>MSBuild:Compile</Generator>
214230
</Page>
231+
<Page Include="Controls\MetadataControl.xaml">
232+
<SubType>Designer</SubType>
233+
<Generator>MSBuild:Compile</Generator>
234+
</Page>
215235
<Page Include="Controls\RemovePluginControl.xaml">
216236
<SubType>Designer</SubType>
217237
<Generator>MSBuild:Compile</Generator>

LiveWriterPluginManager/MainWindow.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
<TabItem Header="Remove">
4141
<local:RemovePluginControl />
4242
</TabItem>
43+
<TabItem Header="Create">
44+
<local:CreatePackageControl/>
45+
</TabItem>
4346
<TabItem Header="About">
4447
<local:AboutControl />
4548
</TabItem>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Newtonsoft.Json;
2+
3+
namespace LiveWriterPluginManager.Model
4+
{
5+
public class Manifest
6+
{
7+
internal const string ManifestFileName = "manifest.json";
8+
public string Name { get; set; }
9+
public string Author { get; set; }
10+
public string ProjectUrl { get; set; }
11+
public string TermsUrl { get; set; }
12+
public string Version { get; set; }
13+
public string TargetWriterVersion { get; set; }
14+
public string PluginFileName { get; set; }
15+
[JsonIgnore]
16+
public string PluginPath { get; set; }
17+
}
18+
}

LiveWriterPluginManager/Services/FileService.cs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ namespace LiveWriterPluginManager.Services
55
public interface IFileService
66
{
77
string GetZipFile();
8+
string[] GetPackageFiles();
9+
string ChoosePackageLocation();
810
}
911

1012
public class FileService : IFileService
@@ -13,9 +15,9 @@ public string GetZipFile()
1315
{
1416
var openFile = new OpenFileDialog
1517
{
16-
Filter = "Zip files (*.zip)|*.zip",
18+
Filter = "Package files (*.olwpkg)|*.olwpkg",
1719
Multiselect = false,
18-
Title = "Please choose your plugin zip file"
20+
Title = "Please choose your plugin package file"
1921
};
2022

2123
var response = openFile.ShowDialog();
@@ -27,5 +29,43 @@ public string GetZipFile()
2729

2830
return file;
2931
}
32+
33+
public string[] GetPackageFiles()
34+
{
35+
var openFile = new OpenFileDialog
36+
{
37+
Multiselect = true,
38+
Title = "Please choose your package files"
39+
};
40+
41+
var response = openFile.ShowDialog();
42+
if (response ?? false)
43+
{
44+
return openFile.FileNames;
45+
}
46+
47+
return new string[0];
48+
}
49+
50+
public string ChoosePackageLocation()
51+
{
52+
var saveFile = new SaveFileDialog
53+
{
54+
Filter = "Package files (*.olwpkg)|*.olwpkg",
55+
AddExtension = true,
56+
Title = "Please choose where to save the package",
57+
CreatePrompt = true,
58+
OverwritePrompt = true
59+
};
60+
61+
var response = saveFile.ShowDialog();
62+
var file = string.Empty;
63+
if (response ?? false)
64+
{
65+
file = saveFile.FileName;
66+
}
67+
68+
return file;
69+
}
3070
}
3171
}

0 commit comments

Comments
 (0)