Skip to content

Commit f26db38

Browse files
committed
Some drag/drop (doesn't work) and textbox styles
1 parent d8de004 commit f26db38

File tree

5 files changed

+126
-66
lines changed

5 files changed

+126
-66
lines changed

LiveWriterPluginManager/Controls/CreatePackageControl.xaml

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -67,39 +67,47 @@
6767
</Border>
6868
</DataTemplate>
6969
</UserControl.Resources>
70-
<Grid>
71-
<Grid.RowDefinitions>
72-
<RowDefinition Height="Auto" />
73-
<RowDefinition Height="*" />
74-
<RowDefinition Height="Auto" />
75-
</Grid.RowDefinitions>
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>
7679

77-
<StackPanel>
78-
<TextBlock Text="Please choose the files that you would like to add to your package."
79-
TextWrapping="WrapWithOverflow"
80-
Margin="10" />
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-
<Button Content="Open package"
90-
Margin="10,0,10,10"
91-
Command="{Binding OpenPackageCommand}"/>
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>
9296
</StackPanel>
93-
</StackPanel>
9497

95-
<ListView ItemsSource="{Binding Files}"
96-
Grid.Row="1" />
98+
<ListView ItemsSource="{Binding Files}"
99+
Grid.Row="1" />
97100

98-
<Button Content="Create package"
99-
Grid.Row="2"
100-
HorizontalAlignment="Right"
101-
Margin="10"
102-
IsEnabled="{Binding IsValidPackage}"
103-
Command="{Binding CreatePackageCommand}"/>
104-
</Grid>
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>
105113
</UserControl>

LiveWriterPluginManager/Controls/CreatePackageControl.xaml.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using System.Windows.Controls;
1+
using System.Linq;
2+
using System.Windows;
3+
using System.Windows.Controls;
4+
using LiveWriterPluginManager.Model;
5+
using LiveWriterPluginManager.ViewModel;
26

37
namespace LiveWriterPluginManager.Controls
48
{
@@ -11,5 +15,25 @@ public CreatePackageControl()
1115
{
1216
InitializeComponent();
1317
}
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+
}
1438
}
1539
}

LiveWriterPluginManager/Controls/MetadataControl.xaml

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,37 @@
99
d:DesignWidth="300"
1010
MinWidth="300"
1111
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+
1221
<Grid>
1322
<ScrollViewer VerticalScrollBarVisibility="Auto">
14-
<StackPanel Orientation="Vertical">
23+
<StackPanel Orientation="Vertical"
24+
Margin="10">
1525
<TextBox x:Name="Name"
16-
Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
26+
Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
27+
wpf:TextFieldAssist.Hint="Plugin name"/>
1728
<TextBox x:Name="Author"
18-
Text="{Binding Author, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
29+
Text="{Binding Author, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
30+
wpf:TextFieldAssist.Hint="Author"/>
1931
<TextBox x:Name="ProjectUrl"
20-
Text="{Binding ProjectUrl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
32+
Text="{Binding ProjectUrl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
33+
wpf:TextFieldAssist.Hint="Project Url" />
2134
<TextBox x:Name="TermsUrl"
22-
Text="{Binding TermsUrl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
35+
Text="{Binding TermsUrl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
36+
wpf:TextFieldAssist.Hint="Terms Url" />
2337
<TextBox x:Name="Version"
24-
Text="{Binding Version, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
38+
Text="{Binding Version, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
39+
wpf:TextFieldAssist.Hint="Version" />
2540
<TextBox x:Name="WriterVersion"
26-
Text="{Binding TargetWriterVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
41+
Text="{Binding TargetWriterVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
42+
wpf:TextFieldAssist.Hint="Target Writer version" />
2743

2844
<Button Content="Save"
2945
Margin="10"

LiveWriterPluginManager/Services/FileService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public string GetZipFile()
1515
{
1616
var openFile = new OpenFileDialog
1717
{
18-
Filter = "Package files (*.wlwpkg)|*.wlwpkg",
18+
Filter = "Package files (*.olwpkg)|*.olwpkg",
1919
Multiselect = false,
2020
Title = "Please choose your plugin package file"
2121
};
@@ -51,7 +51,7 @@ public string ChoosePackageLocation()
5151
{
5252
var saveFile = new SaveFileDialog
5353
{
54-
Filter = "Package files (*.wlwpkg)|*.wlwpkg",
54+
Filter = "Package files (*.olwpkg)|*.olwpkg",
5555
AddExtension = true,
5656
Title = "Please choose where to save the package",
5757
CreatePrompt = true,

LiveWriterPluginManager/ViewModel/CreatePackageViewModel.cs

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.ObjectModel;
33
using System.IO;
44
using System.Linq;
5+
using System.Threading.Tasks;
56
using GalaSoft.MvvmLight;
67
using GalaSoft.MvvmLight.Command;
78
using GalaSoft.MvvmLight.Messaging;
@@ -50,16 +51,21 @@ public RelayCommand AddFilesCommand
5051
return new RelayCommand(() =>
5152
{
5253
var filenames = _fileService.GetPackageFiles();
53-
var files = filenames.Select(x => new FileViewModel(x)).ToList();
54+
AddFiles(filenames);
55+
});
56+
}
57+
}
5458

55-
foreach (var file in files)
56-
{
57-
Files.Add(file);
58-
}
59+
public void AddFiles(string[] filenames)
60+
{
61+
var files = filenames.Select(x => new FileViewModel(x)).ToList();
5962

60-
RaisePropertyChanged(() => IsValidPackage);
61-
});
63+
foreach (var file in files)
64+
{
65+
Files.Add(file);
6266
}
67+
68+
RaisePropertyChanged(() => IsValidPackage);
6369
}
6470

6571
public RelayCommand EditMetadataCommand
@@ -105,26 +111,31 @@ public RelayCommand OpenPackageCommand
105111
return new RelayCommand(async () =>
106112
{
107113
var file = _fileService.GetZipFile();
108-
var packageDetails = await _zipService.OpenPackageForEditing(file);
109-
if (packageDetails.Item1 == null || !packageDetails.Item2.Any())
110-
{
111-
return;
112-
}
113-
ManifestViewModel = new ManifestViewModel(packageDetails.Item1);
114+
await OpenPackage(file);
115+
});
116+
}
117+
}
114118

115-
var files = packageDetails.Item2.Where(x => !x.Contains(Manifest.ManifestFileName)).Select(x => new FileViewModel(x));
116-
Files.Clear();
117-
foreach (var f in files)
118-
{
119-
Files.Add(f);
120-
}
119+
public async Task OpenPackage(string file)
120+
{
121+
var packageDetails = await _zipService.OpenPackageForEditing(file);
122+
if (packageDetails.Item1 == null || !packageDetails.Item2.Any())
123+
{
124+
return;
125+
}
126+
ManifestViewModel = new ManifestViewModel(packageDetails.Item1);
121127

122-
var pluginFile = Files.FirstOrDefault(x => x.Name == ManifestViewModel.PluginFileName);
123-
if (pluginFile != null)
124-
{
125-
pluginFile.IsPluginFile = true;
126-
}
127-
});
128+
var files = packageDetails.Item2.Where(x => !x.Contains(Manifest.ManifestFileName)).Select(x => new FileViewModel(x));
129+
Files.Clear();
130+
foreach (var f in files)
131+
{
132+
Files.Add(f);
133+
}
134+
135+
var pluginFile = Files.FirstOrDefault(x => x.Name == ManifestViewModel.PluginFileName);
136+
if (pluginFile != null)
137+
{
138+
pluginFile.IsPluginFile = true;
128139
}
129140
}
130141
}
@@ -150,6 +161,7 @@ public FileViewModel(string file)
150161
public string Name => File.Name;
151162
public string Path => File.FullName;
152163
public bool IsPluginFile { get; set; }
164+
public string Extension => File.Extension;
153165

154166
public RelayCommand RemoveFileCommand
155167
{

0 commit comments

Comments
 (0)