2019-11-14 18:08:21 +00:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
2019-11-14 19:42:25 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text.RegularExpressions;
|
2019-11-14 18:08:21 +00:00
|
|
|
|
2019-11-14 19:42:25 +00:00
|
|
|
using Avalonia.Input;
|
2019-11-13 19:26:04 +00:00
|
|
|
using Avalonia.Controls;
|
|
|
|
using Avalonia.Markup.Xaml;
|
2019-11-14 19:42:25 +00:00
|
|
|
using Avalonia.Interactivity;
|
2019-11-13 19:26:04 +00:00
|
|
|
|
2019-11-14 18:08:21 +00:00
|
|
|
using BFR.Helpers;
|
2019-11-14 19:42:25 +00:00
|
|
|
using BFR.DataModels;
|
2019-11-14 18:08:21 +00:00
|
|
|
|
2019-11-13 19:26:04 +00:00
|
|
|
namespace BFR
|
|
|
|
{
|
2019-11-13 22:01:08 +00:00
|
|
|
public partial class MainWindow : Window
|
2019-11-13 19:26:04 +00:00
|
|
|
{
|
2019-11-16 01:00:17 +00:00
|
|
|
public async Task OpenDirectoryButtonClick() => OpenDirectory(await new OpenFolderDialog() { Directory = WorkingDirectory }.ShowAsync(this));
|
2019-11-14 18:08:21 +00:00
|
|
|
public void OpenDirectory(string directory)
|
|
|
|
{
|
|
|
|
WorkingDirectory = directory;
|
|
|
|
AllFiles.ReplaceAll(Directory.GetFiles(WorkingDirectory).Select(x => new FileModel(x)));
|
|
|
|
Filter();
|
|
|
|
}
|
|
|
|
|
2019-11-17 01:22:13 +00:00
|
|
|
public void FilterChanged(object sender, KeyEventArgs e) => Filter();
|
|
|
|
public void FilterChanged(object sender, RoutedEventArgs e) => Filter();
|
2019-11-14 18:08:21 +00:00
|
|
|
public void Filter()
|
|
|
|
{
|
2019-11-14 19:42:25 +00:00
|
|
|
// Filter all files in the directory for those satisfying the given filters
|
|
|
|
Files.ReplaceAll(AllFiles.Where(x =>
|
|
|
|
(FilterExtension == "" || x.Extension == FilterExtension)
|
|
|
|
&& (FilterFullName ? x.FullName : x.Name).RegexContains(FilterRegex ? FilterPattern : Regex.Escape(FilterPattern))));
|
2019-11-14 18:08:21 +00:00
|
|
|
|
|
|
|
Preview();
|
|
|
|
}
|
|
|
|
|
2019-11-17 01:22:13 +00:00
|
|
|
public void PreviewChanged(object sender, KeyEventArgs e) => Preview(); // TextBox.KeyUp
|
|
|
|
public void PreviewChanged(object sender, RoutedEventArgs e) => Preview(); // CheckBox.Click
|
|
|
|
public void PreviewChanged(object sender, SelectionChangedEventArgs e) => Preview(); // ComboBox.SelectionChanged
|
|
|
|
public void PreviewChanged(object sender, NumericUpDownValueChangedEventArgs e) => Preview(); // NumericUpDown.ValueChanged
|
2019-11-14 18:08:21 +00:00
|
|
|
public void Preview()
|
|
|
|
{
|
|
|
|
// Reset all files to how they currently exist
|
|
|
|
foreach (var file in Files)
|
|
|
|
file.Path = file.OldPath;
|
|
|
|
|
2019-11-16 01:47:07 +00:00
|
|
|
// Apply operations
|
|
|
|
foreach (var operation in Operations)
|
|
|
|
operation.ApplyTo(Files);
|
2019-11-14 18:08:21 +00:00
|
|
|
|
|
|
|
// Refresh the file list to guarantee that changes are displayed. TODO: Find a better way to do this.
|
|
|
|
Files.ReplaceAll(new List<FileModel>(Files));
|
|
|
|
}
|
|
|
|
|
2019-11-17 01:22:13 +00:00
|
|
|
public void AddOperation()
|
|
|
|
{
|
|
|
|
Operations.Insert(
|
|
|
|
SelectedOperation >= 0 ? SelectedOperation + 1 : Operations.Count,
|
|
|
|
OperationTypes[SelectedOperationType].Create());
|
|
|
|
Preview();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RemoveOperation()
|
|
|
|
{
|
|
|
|
if (SelectedOperation >= 0)
|
|
|
|
Operations.RemoveAt(SelectedOperation);
|
|
|
|
else Operations.RemoveAt(0);
|
|
|
|
Preview();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void MoveOperation(object sender, SpinEventArgs e)
|
|
|
|
{
|
|
|
|
if (Operations.Count > 1)
|
|
|
|
if (e.Direction == SpinDirection.Increase && SelectedOperation > 0)
|
|
|
|
Operations.Move(SelectedOperation, SelectedOperation - 1);
|
|
|
|
else if (e.Direction == SpinDirection.Decrease && SelectedOperation < Operations.Count - 1)
|
|
|
|
Operations.Move(SelectedOperation, SelectedOperation + 1);
|
|
|
|
Preview();
|
|
|
|
}
|
|
|
|
|
2019-11-16 01:00:17 +00:00
|
|
|
public MainWindow() => InitializeComponent();
|
2019-11-13 19:26:04 +00:00
|
|
|
private void InitializeComponent()
|
|
|
|
{
|
|
|
|
AvaloniaXamlLoader.Load(this);
|
2019-11-13 19:40:30 +00:00
|
|
|
DataContext = this;
|
2019-11-14 18:08:21 +00:00
|
|
|
OpenDirectory(Environment.OSVersion.Platform == PlatformID.Win32NT ? @"C:\Users" : @"\home");
|
2019-11-13 19:26:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|