Added commit and undo + Bugfix
- Bugfix: The Name-filter was based on Name and FullName, instead of how it is now, OldName and OldFullName. This would previously cause the filter to apply to the already previewed changes.
This commit is contained in:
parent
5d8327f071
commit
e0fe30b380
|
@ -68,8 +68,8 @@
|
||||||
<!-- Commit and Undo Buttons -->
|
<!-- Commit and Undo Buttons -->
|
||||||
<Border Grid.Row="2" Classes="ConnectUp">
|
<Border Grid.Row="2" Classes="ConnectUp">
|
||||||
<Grid ColumnDefinitions="*,*">
|
<Grid ColumnDefinitions="*,*">
|
||||||
<Button Grid.Column="0" Content="Undo"/>
|
<Button Grid.Column="0" Content="Undo" Command="{Binding Undo}" IsEnabled="{Binding !!UndoCount}"/>
|
||||||
<Button Grid.Column="1" Content="Rename All"/>
|
<Button Grid.Column="1" Content="Rename All" Command="{Binding Commit}" IsEnabled="{Binding IsCommitButtonEnabled}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace BFR
|
||||||
// Filter all files in the directory for those satisfying the given filters
|
// Filter all files in the directory for those satisfying the given filters
|
||||||
Files.ReplaceAll(AllFiles.Where(x =>
|
Files.ReplaceAll(AllFiles.Where(x =>
|
||||||
(FilterExtension == "" || x.Extension == FilterExtension)
|
(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();
|
Preview();
|
||||||
}
|
}
|
||||||
|
@ -51,15 +51,23 @@ namespace BFR
|
||||||
foreach (var operation in Operations)
|
foreach (var operation in Operations)
|
||||||
operation.ApplyTo(Files);
|
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.
|
// Refresh the file list to guarantee that changes are displayed. TODO: Find a better way to do this.
|
||||||
Files.ReplaceAll(new List<FileModel>(Files));
|
Files.ReplaceAll(new List<FileModel>(Files));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddOperation()
|
public void AddOperation()
|
||||||
{
|
{
|
||||||
|
if (Operations.Count >= 1)
|
||||||
Operations.Insert(
|
Operations.Insert(
|
||||||
SelectedOperation >= 0 ? SelectedOperation + 1 : Operations.Count,
|
SelectedOperation >= 0 ? SelectedOperation + 1 : Operations.Count,
|
||||||
OperationTypes[SelectedOperationType].Create());
|
OperationTypes[SelectedOperationType].Create());
|
||||||
|
else Operations.Add(OperationTypes[SelectedOperationType].Create());
|
||||||
Preview();
|
Preview();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +89,27 @@ namespace BFR
|
||||||
Preview();
|
Preview();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Commit()
|
||||||
|
{
|
||||||
|
foreach (var file in Files)
|
||||||
|
if (file.OldPath != file.Path)
|
||||||
|
File.Move(file.OldPath, file.Path);
|
||||||
|
|
||||||
|
UndoStack.Push(new List<FileModel>(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();
|
public MainWindow() => InitializeComponent();
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,7 @@ using Avalonia.Controls;
|
||||||
|
|
||||||
using BFR.DataModels;
|
using BFR.DataModels;
|
||||||
using BFR.Operations;
|
using BFR.Operations;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace BFR
|
namespace BFR
|
||||||
{
|
{
|
||||||
|
@ -24,6 +25,14 @@ namespace BFR
|
||||||
OperationType.Make<Overwrite>()
|
OperationType.Make<Overwrite>()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public readonly AvaloniaProperty<bool> isCommitButtonEnabled =
|
||||||
|
AvaloniaProperty.Register<MainWindow, bool>("IsCommitButtonEnabled", defaultValue: false);
|
||||||
|
public bool IsCommitButtonEnabled { get => GetValue(isCommitButtonEnabled); set => SetValue(isCommitButtonEnabled, value); }
|
||||||
|
public readonly AvaloniaProperty<int> undoCount =
|
||||||
|
AvaloniaProperty.Register<MainWindow, int>("UndoCount", defaultValue: 0);
|
||||||
|
public int UndoCount { get => GetValue(undoCount); set => SetValue(undoCount, value); }
|
||||||
|
private readonly Stack<List<FileModel>> UndoStack = new Stack<List<FileModel>>();
|
||||||
|
|
||||||
// Filters
|
// Filters
|
||||||
public string FilterExtension { get; set; } = "";
|
public string FilterExtension { get; set; } = "";
|
||||||
public string FilterPattern { get; set; } = "";
|
public string FilterPattern { get; set; } = "";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user