mirror of
https://github.com/chylex/Backup-Essentials.git
synced 2025-08-21 03:54:01 +02:00
BackupEssentials
Backup
Controls
Data
Pages
HomeSub
About.xaml
About.xaml.cs
Backup.xaml
Backup.xaml.cs
BackupDrop.xaml
BackupDrop.xaml.cs
BackupEdit.xaml
BackupEdit.xaml.cs
History.xaml
History.xaml.cs
Home.xaml
Home.xaml.cs
IPageDragDrop.cs
IPageResetUI.cs
IPageShowData.cs
IPageSwitchHandler.cs
Settings.xaml
Settings.xaml.cs
Properties
Resources
Sys
Utils
App.xaml
App.xaml.cs
AppPageManager.cs
BackupEssentials.csproj
BackupReportWindow.xaml
BackupReportWindow.xaml.cs
BackupWindow.xaml
BackupWindow.xaml.cs
MainWindow.xaml
MainWindow.xaml.cs
TestingWindow.xaml
TestingWindow.xaml.cs
.gitignore
BackupEssentials.sln
LICENSE
README.md
112 lines
5.0 KiB
C#
112 lines
5.0 KiB
C#
using BackupEssentials.Backup;
|
|
using BackupEssentials.Backup.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using System.Windows.Threading;
|
|
|
|
namespace BackupEssentials.Pages{
|
|
public partial class Backup : Page, IPageShowData{
|
|
private int DraggingItemIndex = -1;
|
|
private BackupLocation DraggingItem = null;
|
|
|
|
public Backup(){
|
|
InitializeComponent();
|
|
|
|
LocationsListView.Items.Clear();
|
|
LocationsListView.ItemsSource = DataStorage.BackupLocationList;
|
|
|
|
ExplorerIntegration.InitializeRefreshTimer();
|
|
}
|
|
|
|
void IPageShowData.OnShow(object data){
|
|
LocationsListView.Items.Refresh();
|
|
|
|
int count = DataStorage.BackupLocationList.Count;
|
|
if (count > 0 && DataStorage.BackupLocationList[count-1].Name.Length == 0)DataStorage.BackupLocationList.RemoveAt(count-1);
|
|
}
|
|
|
|
private void ListStartDragging(object sender, MouseButtonEventArgs e){
|
|
if ((Keyboard.Modifiers & ~ModifierKeys.Control & ~ModifierKeys.Shift) != Keyboard.Modifiers)return;
|
|
|
|
DispatcherTimer timer = new DispatcherTimer();
|
|
timer.Interval = new TimeSpan(1);
|
|
|
|
timer.Tick += (sender2, args2) => {
|
|
DraggingItemIndex = LocationsListView.SelectedIndex;
|
|
DraggingItem = (BackupLocation)LocationsListView.SelectedItem;
|
|
timer.Stop();
|
|
};
|
|
|
|
timer.Start();
|
|
}
|
|
|
|
private void ListStopDragging(object sender, MouseButtonEventArgs e){
|
|
DraggingItemIndex = -1;
|
|
DraggingItem = null;
|
|
}
|
|
|
|
private void ListMouseMove(object sender, MouseEventArgs e){
|
|
if (DraggingItemIndex != -1 && DraggingItem != null){
|
|
if (e.LeftButton == MouseButtonState.Released){
|
|
DraggingItemIndex = -1;
|
|
DraggingItem = null;
|
|
return;
|
|
}
|
|
|
|
ListViewItem container = ((ListViewItem)LocationsListView.ItemContainerGenerator.ContainerFromItem(DraggingItem));
|
|
double mouseY = e.GetPosition(null).Y, containerY = container.TranslatePoint(new Point(),null).Y;
|
|
|
|
if (DraggingItemIndex > 0 && mouseY < containerY){
|
|
DataStorage.BackupLocationList.RemoveAt(DraggingItemIndex);
|
|
--DraggingItemIndex;
|
|
}
|
|
else if (DraggingItemIndex < LocationsListView.Items.Count-1 && mouseY > containerY+(double)Resources["LocationListItemHeight"]+container.Padding.Top+container.Padding.Bottom-1){
|
|
DataStorage.BackupLocationList.RemoveAt(DraggingItemIndex);
|
|
++DraggingItemIndex;
|
|
}
|
|
else return;
|
|
|
|
DataStorage.BackupLocationList.Insert(DraggingItemIndex,DraggingItem);
|
|
LocationsListView.SelectedIndex = DraggingItemIndex;
|
|
DraggingItem = (BackupLocation)LocationsListView.Items[DraggingItemIndex];
|
|
ExplorerIntegration.Refresh();
|
|
}
|
|
}
|
|
|
|
private void LocationAdd(object sender, RoutedEventArgs e){
|
|
DataStorage.BackupLocationList.Add(new BackupLocation());
|
|
LocationsListView.SelectedIndex = DataStorage.BackupLocationList.Count-1;
|
|
MainWindow.Instance.ShowPage(typeof(BackupEdit),DataStorage.BackupLocationList[LocationsListView.SelectedIndex]);
|
|
}
|
|
|
|
private void LocationEdit(object sender, RoutedEventArgs e){
|
|
if (LocationsListView.SelectedIndex != -1)MainWindow.Instance.ShowPage(typeof(BackupEdit),DataStorage.BackupLocationList[LocationsListView.SelectedIndex]);
|
|
}
|
|
|
|
private void LocationRemove(object sender, RoutedEventArgs e){
|
|
int index = LocationsListView.SelectedIndex;
|
|
List<object> list = new List<object>();
|
|
foreach(object obj in LocationsListView.SelectedItems)list.Add(obj); // MS doesn't need generics apparently...
|
|
|
|
if (MessageBox.Show(App.Window,Sys.Settings.Default.Language["Backup.Deletion.Confirmation.",list.Count,list.Count.ToString()],Sys.Settings.Default.Language["Backup.Deletion.Confirmation.Title"],MessageBoxButton.YesNo,MessageBoxImage.Warning) == MessageBoxResult.Yes){
|
|
foreach(object item in list)DataStorage.BackupLocationList.Remove((BackupLocation)item);
|
|
|
|
if (index > 0)LocationsListView.SelectedIndex = index-1;
|
|
else if (LocationsListView.Items.Count > 0)LocationsListView.SelectedIndex = index;
|
|
|
|
if (DataStorage.BackupLocationList.Count(loc => loc.ShouldRegister()) == 0)ExplorerIntegration.Remove();
|
|
else ExplorerIntegration.Refresh();
|
|
}
|
|
}
|
|
|
|
private void ListViewSelectionChanged(object sender, SelectionChangedEventArgs e){
|
|
ButtonLocationEdit.IsEnabled = LocationsListView.SelectedItems.Count == 1;
|
|
ButtonLocationRemove.IsEnabled = LocationsListView.SelectedItems.Count > 0;
|
|
}
|
|
}
|
|
}
|