diff --git a/BFR/MainWindow.xaml b/BFR/MainWindow.xaml
index 01bcc86..6dc8cf3 100644
--- a/BFR/MainWindow.xaml
+++ b/BFR/MainWindow.xaml
@@ -68,8 +68,8 @@
-
-
+
+
diff --git a/BFR/MainWindow.xaml.cs b/BFR/MainWindow.xaml.cs
index 7d9c3c4..89191cf 100644
--- a/BFR/MainWindow.xaml.cs
+++ b/BFR/MainWindow.xaml.cs
@@ -32,7 +32,7 @@ namespace BFR
// 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))));
+ && (FilterFullName ? x.OldFullName : x.OldName).RegexContains(FilterRegex ? FilterPattern : Regex.Escape(FilterPattern))));
Preview();
}
@@ -51,15 +51,23 @@ namespace BFR
foreach (var operation in Operations)
operation.ApplyTo(Files);
+ // Validate that there are any changes, and that the new file names are all unique.
+ IsCommitButtonEnabled =
+ Files.Any(x => x.Path != x.OldPath) // Check for changes
+ && Files.GroupBy(x => x.Path).All(g => g.Count() == 1) // Check for duplicates
+ && !Files.Any(x => x.FullName == ""); // Check for invalid file names; TODO: Further validation
+
// Refresh the file list to guarantee that changes are displayed. TODO: Find a better way to do this.
Files.ReplaceAll(new List(Files));
}
public void AddOperation()
{
- Operations.Insert(
- SelectedOperation >= 0 ? SelectedOperation + 1 : Operations.Count,
- OperationTypes[SelectedOperationType].Create());
+ if (Operations.Count >= 1)
+ Operations.Insert(
+ SelectedOperation >= 0 ? SelectedOperation + 1 : Operations.Count,
+ OperationTypes[SelectedOperationType].Create());
+ else Operations.Add(OperationTypes[SelectedOperationType].Create());
Preview();
}
@@ -81,6 +89,27 @@ namespace BFR
Preview();
}
+ public void Commit()
+ {
+ foreach (var file in Files)
+ if (file.OldPath != file.Path)
+ File.Move(file.OldPath, file.Path);
+
+ UndoStack.Push(new List(Files));
+ UndoCount = UndoStack.Count;
+
+ OpenDirectory(WorkingDirectory);
+ }
+
+ public void Undo()
+ {
+ foreach (var file in UndoStack.Pop())
+ File.Move(file.Path, file.OldPath);
+
+ UndoCount = UndoStack.Count;
+ OpenDirectory(WorkingDirectory);
+ }
+
public MainWindow() => InitializeComponent();
private void InitializeComponent()
{
diff --git a/BFR/MainWindowUIProperties.cs b/BFR/MainWindowUIProperties.cs
index f381cf5..157b8e8 100644
--- a/BFR/MainWindowUIProperties.cs
+++ b/BFR/MainWindowUIProperties.cs
@@ -4,6 +4,7 @@ using Avalonia.Controls;
using BFR.DataModels;
using BFR.Operations;
+using System.Collections.Generic;
namespace BFR
{
@@ -24,6 +25,14 @@ namespace BFR
OperationType.Make()
};
+ public readonly AvaloniaProperty isCommitButtonEnabled =
+ AvaloniaProperty.Register("IsCommitButtonEnabled", defaultValue: false);
+ public bool IsCommitButtonEnabled { get => GetValue(isCommitButtonEnabled); set => SetValue(isCommitButtonEnabled, value); }
+ public readonly AvaloniaProperty undoCount =
+ AvaloniaProperty.Register("UndoCount", defaultValue: 0);
+ public int UndoCount { get => GetValue(undoCount); set => SetValue(undoCount, value); }
+ private readonly Stack> UndoStack = new Stack>();
+
// Filters
public string FilterExtension { get; set; } = "";
public string FilterPattern { get; set; } = "";