From ba60b0cab9a5986ef2f688e0e878308192930bae Mon Sep 17 00:00:00 2001 From: Burgy Benjamin Date: Thu, 2 Jun 2016 20:35:17 +0200 Subject: [PATCH] Fix some edge cases when you type the expected result before the regex. --- Solution/App/ViewModels/ShellViewModel.cs | 40 +++++++++++------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Solution/App/ViewModels/ShellViewModel.cs b/Solution/App/ViewModels/ShellViewModel.cs index 5ede189..0f05ba0 100644 --- a/Solution/App/ViewModels/ShellViewModel.cs +++ b/Solution/App/ViewModels/ShellViewModel.cs @@ -82,28 +82,22 @@ private set public async Task ApplyAsync() { - try + this.IsLoading = true; + + using (Disposable.Create(() => this.IsLoading = false)) { - this.IsLoading = true; + var actualFiles = await this._folderSelected.GetFilesAsync(); - using (Disposable.Create(() => this.IsLoading = false)) + foreach (var file in this.Files.AsParallel() + .Where(x => x.FuturResult != null && + actualFiles.Any(f => f.Path == x.StorageFile.Path) + && x.FileName != x.FuturResult)) { - var actualFiles = await this._folderSelected.GetFilesAsync(); - - foreach (var file in this.Files.AsParallel() - .Where(x => x.FuturResult != null && - actualFiles.Any(f => f.Path == x.StorageFile.Path))) - { - await file.StorageFile.RenameAsync(file.FuturResult); - } - - await this.FetchFolderAsync(); - this.CalculateRegex(); + await file.StorageFile.RenameAsync(file.FuturResult); } - } - catch (Exception e) - { - Logger.Error(e); + + await this.FetchFolderAsync(); + this.CalculateRegex(); } } @@ -196,7 +190,12 @@ private void CalculateReplacePattern(string replacePattern) { var increment = 1; - foreach (var item in this.Files.Where(x => x.RegexMatch.Success)) + foreach (var item in this.Files.Where(x => x.RegexMatch == null || !x.RegexMatch.Success)) + { + item.FuturResult = null; + } + + foreach (var item in this.Files.Where(x => x.RegexMatch != null && x.RegexMatch.Success)) { try { @@ -208,7 +207,7 @@ private void CalculateReplacePattern(string replacePattern) } } - this.CanApplyAsync = this.Files.Any(x => x.RegexMatch.Success) && this.ReplacePattern.Value != null; + this.CanApplyAsync = this.Files.Any(x => x.RegexMatch != null && x.RegexMatch.Success) && this.ReplacePattern.Value != null; } else { @@ -250,6 +249,7 @@ private void CalculateRegex(string pattern) foreach (var item in this.Files) { item.Parts = new[] {item.FileName}; + item.FuturResult = null; } return;