Skip to content
This repository has been archived by the owner on Nov 12, 2022. It is now read-only.

Commit

Permalink
Fix some edge cases when you type the expected result before the regex.
Browse files Browse the repository at this point in the history
  • Loading branch information
minidfx committed Jun 2, 2016
1 parent c9c03b1 commit ba60b0c
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions Solution/App/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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
{
Expand All @@ -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
{
Expand Down Expand Up @@ -250,6 +249,7 @@ private void CalculateRegex(string pattern)
foreach (var item in this.Files)
{
item.Parts = new[] {item.FileName};
item.FuturResult = null;
}

return;
Expand Down

0 comments on commit ba60b0c

Please sign in to comment.