Skip to content

Commit 04d3058

Browse files
committed
Add basic file management
1 parent 6cf731c commit 04d3058

File tree

7 files changed

+197
-10
lines changed

7 files changed

+197
-10
lines changed

LiveWriterPluginManager/Controls/CreatePackageControl.xaml

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,34 @@
1818
<Grid.ColumnDefinitions>
1919
<ColumnDefinition Width="*" />
2020
<ColumnDefinition Width="Auto" />
21+
<ColumnDefinition Width="Auto" />
2122
</Grid.ColumnDefinitions>
22-
23+
2324
<TextBlock Text="{Binding Name}"
24-
VerticalAlignment="Center"/>
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>
2547

26-
<Button Grid.Column="1"
48+
<Button Grid.Column="2"
2749
Style="{StaticResource MaterialDesignFloatingActionMiniAccentButton}"
2850
Height="30"
2951
Width="30"
@@ -56,10 +78,15 @@
5678
<TextBlock Text="Please choose the files that you would like to add to your package."
5779
TextWrapping="WrapWithOverflow"
5880
Margin="10" />
59-
<Button Content="Add files"
60-
HorizontalAlignment="Left"
61-
Margin="10,0,10,10"
62-
Command="{Binding AddFilesCommand}" />
81+
<StackPanel Orientation="Horizontal">
82+
<Button Content="Add files"
83+
HorizontalAlignment="Left"
84+
Margin="10,0,10,10"
85+
Command="{Binding AddFilesCommand}" />
86+
<Button Content="Edit metadata"
87+
Margin="10,0,10,10"
88+
Command="{Binding EditMetadataCommand}"/>
89+
</StackPanel>
6390
</StackPanel>
6491

6592
<ListView ItemsSource="{Binding Files}"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
<Grid>
13+
<ScrollViewer VerticalScrollBarVisibility="Auto">
14+
<StackPanel Orientation="Vertical">
15+
<TextBox x:Name="Name"
16+
Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
17+
<TextBox x:Name="Author"
18+
Text="{Binding Author, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
19+
<TextBox x:Name="ProjectUrl"
20+
Text="{Binding ProjectUrl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
21+
<TextBox x:Name="TermsUrl"
22+
Text="{Binding TermsUrl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
23+
<TextBox x:Name="Version"
24+
Text="{Binding Version, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
25+
<TextBox x:Name="WriterVersion"
26+
Text="{Binding TargetWriterVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
27+
28+
<Button Content="Save"
29+
Margin="10"
30+
Command="{x:Static wpf:DialogHost.CloseDialogCommand}"/>
31+
</StackPanel>
32+
</ScrollViewer>
33+
</Grid>
34+
</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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace LiveWriterPluginManager.Helpers
1212
{
1313
public static class AppHelper
1414
{
15+
public const string SetPluginFileMsg = "SetPluginFileMsg";
1516
public const string RemovePluginMsg = "RemovePluginMsg";
1617
public const string RemoveFileMsg = "RemoveFileMsg";
1718

LiveWriterPluginManager/LiveWriterPluginManager.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@
183183
<Compile Include="Controls\Messages\QuestionControl.xaml.cs">
184184
<DependentUpon>QuestionControl.xaml</DependentUpon>
185185
</Compile>
186+
<Compile Include="Controls\MetadataControl.xaml.cs">
187+
<DependentUpon>MetadataControl.xaml</DependentUpon>
188+
</Compile>
186189
<Compile Include="Controls\RemovePluginControl.xaml.cs">
187190
<DependentUpon>RemovePluginControl.xaml</DependentUpon>
188191
</Compile>
@@ -225,6 +228,10 @@
225228
<SubType>Designer</SubType>
226229
<Generator>MSBuild:Compile</Generator>
227230
</Page>
231+
<Page Include="Controls\MetadataControl.xaml">
232+
<SubType>Designer</SubType>
233+
<Generator>MSBuild:Compile</Generator>
234+
</Page>
228235
<Page Include="Controls\RemovePluginControl.xaml">
229236
<SubType>Designer</SubType>
230237
<Generator>MSBuild:Compile</Generator>

LiveWriterPluginManager/Services/MessageService.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Threading.Tasks;
2+
using LiveWriterPluginManager.Controls;
23
using LiveWriterPluginManager.Controls.Messages;
34
using MaterialDesignThemes.Wpf;
45

@@ -9,6 +10,7 @@ public interface IMessageService
910
Task<bool> ShowQuestionAsync(string question, string positive, string negative);
1011
Task ShowErrorAsync(string errorMessage);
1112
Task ShowMessageAsync(string message);
13+
Task ShowMetadataAsync();
1214
}
1315

1416
public class MessageService : IMessageService
@@ -44,5 +46,12 @@ public Task ShowMessageAsync(string message)
4446

4547
return DialogHost.Show(infoControl);
4648
}
49+
50+
public Task ShowMetadataAsync()
51+
{
52+
var metadataControl = new MetadataControl();
53+
54+
return DialogHost.Show(metadataControl);
55+
}
4756
}
4857
}

LiveWriterPluginManager/ViewModel/CreatePackageViewModel.cs

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,33 @@ public class CreatePackageViewModel : ViewModelBase
1515
{
1616
private readonly IZipService _zipService;
1717
private readonly IFileService _fileService;
18+
private readonly IMessageService _messageService;
1819

19-
public CreatePackageViewModel(IZipService zipService, IFileService fileService)
20+
public CreatePackageViewModel(IZipService zipService, IFileService fileService, IMessageService messageService)
2021
{
2122
_zipService = zipService;
2223
_fileService = fileService;
24+
_messageService = messageService;
2325

2426
Messenger.Default.Register<NotificationMessage>(this, m =>
2527
{
2628
if (m.Notification.Equals(AppHelper.RemoveFileMsg))
2729
{
2830
Files.Remove(m.Sender as FileViewModel);
2931
}
32+
else if (m.Notification.Equals(AppHelper.SetPluginFileMsg))
33+
{
34+
RaisePropertyChanged(() => IsValidPackage);
35+
}
3036
});
3137
}
3238

3339
public ObservableCollection<FileViewModel> Files { get; set; } = new ObservableCollection<FileViewModel>();
34-
public bool IsValidPackage { get; set; }
40+
41+
public bool IsValidPackage => Files.Any(x => x.Name.Equals(Manifest.ManifestFileName, StringComparison.InvariantCultureIgnoreCase))
42+
|| ManifestViewModel.PluginFileSet;
43+
44+
public ManifestViewModel ManifestViewModel { get; set; } = new ManifestViewModel(new Manifest());
3545

3646
public RelayCommand AddFilesCommand
3747
{
@@ -41,12 +51,24 @@ public RelayCommand AddFilesCommand
4151
{
4252
var filenames = _fileService.GetPackageFiles();
4353
var files = filenames.Select(x => new FileViewModel(x)).ToList();
44-
IsValidPackage = files.Any(x => x.Name.Equals(Manifest.ManifestFileName, StringComparison.InvariantCultureIgnoreCase));
4554

4655
foreach (var file in files)
4756
{
4857
Files.Add(file);
4958
}
59+
60+
RaisePropertyChanged(() => IsValidPackage);
61+
});
62+
}
63+
}
64+
65+
public RelayCommand EditMetadataCommand
66+
{
67+
get
68+
{
69+
return new RelayCommand(async () =>
70+
{
71+
await _messageService.ShowMetadataAsync();
5072
});
5173
}
5274
}
@@ -57,6 +79,12 @@ public RelayCommand CreatePackageCommand
5779
{
5880
return new RelayCommand(async () =>
5981
{
82+
if (!Files.Any(x => x.IsPluginFile))
83+
{
84+
// TODO: Display an error message
85+
return;
86+
}
87+
6088
var packageFile = _fileService.ChoosePackageLocation();
6189
var filePaths = Files.Select(x => x.Path).ToArray();
6290

@@ -71,12 +99,22 @@ public class FileViewModel : ViewModelBase
7199
public FileViewModel(string file)
72100
{
73101
File = new FileInfo(file);
102+
103+
Messenger.Default.Register<NotificationMessage>(this, m =>
104+
{
105+
if (m.Notification.Equals(AppHelper.SetPluginFileMsg))
106+
{
107+
var selectedFile = m.Sender as FileViewModel;
108+
IsPluginFile = selectedFile?.Path == this.Path;
109+
}
110+
});
74111
}
75112

76113
public FileInfo File { get; set; }
77114

78115
public string Name => File.Name;
79116
public string Path => File.FullName;
117+
public bool IsPluginFile { get; set; }
80118

81119
public RelayCommand RemoveFileCommand
82120
{
@@ -88,5 +126,63 @@ public RelayCommand RemoveFileCommand
88126
});
89127
}
90128
}
129+
130+
public RelayCommand SetPluginFileCommand
131+
{
132+
get
133+
{
134+
return new RelayCommand(() =>
135+
{
136+
Messenger.Default.Send(new NotificationMessage(this, AppHelper.SetPluginFileMsg));
137+
});
138+
}
139+
}
140+
}
141+
142+
public class ManifestViewModel : ViewModelBase
143+
{
144+
private readonly Manifest _manifest;
145+
public ManifestViewModel(Manifest manifest)
146+
{
147+
_manifest = manifest;
148+
149+
Name = _manifest.Name;
150+
Author = _manifest.Author;
151+
ProjectUrl = _manifest.ProjectUrl;
152+
TermsUrl = _manifest.TermsUrl;
153+
Version = _manifest.Version;
154+
TargetWriterVersion = _manifest.TargetWriterVersion;
155+
156+
Messenger.Default.Register<NotificationMessage>(this, m =>
157+
{
158+
if (m.Notification.Equals(AppHelper.SetPluginFileMsg))
159+
{
160+
var file = m.Sender as FileViewModel;
161+
_manifest.PluginFileName = file?.Name;
162+
_manifest.PluginPath = file?.Path;
163+
}
164+
});
165+
}
166+
167+
public string Name { get; set; }
168+
public string Author { get; set; }
169+
public string ProjectUrl { get; set; }
170+
public string TermsUrl { get; set; }
171+
public string Version { get; set; }
172+
public string TargetWriterVersion { get; set; }
173+
174+
public bool PluginFileSet => !string.IsNullOrEmpty(_manifest?.PluginFileName);
175+
176+
public Manifest GetManifest()
177+
{
178+
_manifest.Name = Name;
179+
_manifest.Author = Author;
180+
_manifest.ProjectUrl = ProjectUrl;
181+
_manifest.TermsUrl = TermsUrl;
182+
_manifest.Version = Version;
183+
_manifest.TargetWriterVersion = TargetWriterVersion;
184+
185+
return _manifest;
186+
}
91187
}
92188
}

0 commit comments

Comments
 (0)