1
0
mirror of https://github.com/chylex/Backup-Essentials.git synced 2025-05-22 01:34:04 +02:00

Added backup and cancel buttons to Drop window and fixed page NPE

This commit is contained in:
chylex 2015-04-10 19:25:28 +02:00
parent 4d387c8f9c
commit 7dd04a24c4
3 changed files with 44 additions and 6 deletions

View File

@ -2,6 +2,7 @@
using BackupEssentials.Controls;
using BackupEssentials.Pages;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@ -100,6 +101,7 @@ namespace BackupEssentials{
if (DropData == null && e.Data.GetDataPresent(DataFormats.FileDrop)){
DropData = e.Data.GetData(DataFormats.FileDrop) as string[];
DropOverlayLabel.Visibility = Visibility.Visible;
App.SetForegroundWindow(Process.GetCurrentProcess().MainWindowHandle);
}
else e.Effects = DragDropEffects.None;
@ -113,8 +115,8 @@ namespace BackupEssentials{
private void OnDragDrop(object sender, DragEventArgs e){
if (DropData != null){
ShowPage(typeof(BackupDrop),DropData);
DropOverlayLabel.Visibility = Visibility.Hidden;
ShowPage(typeof(BackupDrop),new object[]{ DropData, ContentFrame.Content == null ? null : (ContentFrame.Content as Page).GetType() });
DropData = null;
}
}
@ -130,7 +132,7 @@ namespace BackupEssentials{
IPageShowData pageDataHandler = page as IPageShowData;
if (pageDataHandler != null && data != IgnoreShowData)pageDataHandler.OnShow(data);
if (!page.AllowDrop){
if (page != null && !page.AllowDrop){
page.AllowDrop = true;
page.DragEnter += new DragEventHandler(OnDragEnter);
page.DragLeave += new DragEventHandler(OnDragLeave);

View File

@ -23,14 +23,14 @@
<StackPanel.Resources>
<Style TargetType="Button">
<Setter Property="Margin" Value="8,8,0,0"/>
<Setter Property="Width" Value="120"/>
<Setter Property="Width" Value="100"/>
<Setter Property="Height" Value="40"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="Template" Value="{StaticResource ButtonStyleDefault}"/>
</Style>
</StackPanel.Resources>
<Button x:Name="ButtonBackup" Content="Backup" IsEnabled="False"/>
<Button x:Name="ButtoonCancel" Content="Cancel" Template="{StaticResource ButtonStyleRedDefault}"/>
<Button x:Name="ButtonBackup" Content="Backup" IsEnabled="False" Click="ClickBackup"/>
<Button x:Name="ButtonCancel" Content="Cancel" Template="{StaticResource ButtonStyleRedDefault}" Click="ClickCancel"/>
</StackPanel>
<ListView Name="LocationsListView" Grid.Row="1" Margin="8" Style="{StaticResource ListViewStyleDefault}" SelectionChanged="ListViewSelectionChanged">

View File

@ -1,8 +1,17 @@
using BackupEssentials.Backup;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
namespace BackupEssentials.Pages{
public partial class BackupDrop : Page, IPageShowData{
private Type PrevPageType;
private string[] FileList;
private bool Running;
public BackupDrop(){
InitializeComponent();
@ -11,11 +20,38 @@ namespace BackupEssentials.Pages{
}
void IPageShowData.OnShow(object data){
string[] files = (string[])data;
FileList = (string[])((Object[])data)[0];
PrevPageType = (Type)((Object[])data)[1];
}
private void ListViewSelectionChanged(object sender, SelectionChangedEventArgs e){
ButtonBackup.IsEnabled = LocationsListView.SelectedItems.Count == 1;
}
private void ClickBackup(object sender, RoutedEventArgs e){
if (FileList.Length == 0 || Running)return;
Process newProcess = new Process();
newProcess.StartInfo.Arguments = "-runshell -locid "+LocationsListView.SelectedIndex+" -src \""+string.Join("\" \"",FileList)+"\"";
newProcess.StartInfo.FileName = Path.GetFileName(Assembly.GetExecutingAssembly().CodeBase);
newProcess.EnableRaisingEvents = true;
newProcess.Start();
newProcess.Exited += (sender2, args2) => {
if (newProcess.ExitCode == 0){
Dispatcher.Invoke(new Action(() => {
MainWindow.Instance.ShowPage(PrevPageType,MainWindow.IgnoreShowData);
}));
}
Running = false;
};
Running = true;
}
private void ClickCancel(object sender, RoutedEventArgs e){
MainWindow.Instance.ShowPage(PrevPageType,MainWindow.IgnoreShowData);
}
}
}