From 26ef4fd1c735c25adfde33f332838e23f8561161 Mon Sep 17 00:00:00 2001 From: Rick Strahl Date: Tue, 3 Sep 2019 23:59:37 -0700 Subject: [PATCH] Fix file search where file type was not properly respected. - remove experimental tag. --- MarkdownMonster/Windows/FileSearch/FileSearchControl.xaml | 2 +- MarkdownMonster/Windows/FileSearch/FileSearchModel.cs | 8 +++++--- .../{SearchInFilesFinder.cs => FindInFilesFinder.cs} | 7 +++++-- Tests/MarkdownMonster.Test/SearchInFilesFinderTests.cs | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) rename MarkdownMonster/Windows/FileSearch/{SearchInFilesFinder.cs => FindInFilesFinder.cs} (95%) diff --git a/MarkdownMonster/Windows/FileSearch/FileSearchControl.xaml b/MarkdownMonster/Windows/FileSearch/FileSearchControl.xaml index 8474c08b4..e1ca021d3 100644 --- a/MarkdownMonster/Windows/FileSearch/FileSearchControl.xaml +++ b/MarkdownMonster/Windows/FileSearch/FileSearchControl.xaml @@ -28,7 +28,7 @@ diff --git a/MarkdownMonster/Windows/FileSearch/FileSearchModel.cs b/MarkdownMonster/Windows/FileSearch/FileSearchModel.cs index 71f1cd8e2..700f5b156 100644 --- a/MarkdownMonster/Windows/FileSearch/FileSearchModel.cs +++ b/MarkdownMonster/Windows/FileSearch/FileSearchModel.cs @@ -149,16 +149,18 @@ public FileSearchModel() SearchFolder = Path.GetDirectoryName(SearchFolder); } - SearchFinder = new SearchInFilesFinder(SearchFolder, FileFilters); + FindFinder = new FindInFilesFinder(SearchFolder, FileFilters); } public async Task SearchAsync() { Window.ShowStatusProgress($"Searching files for '{SearchPhrase}'"); - var finder = new SearchInFilesFinder(SearchFolder,FileFilters); + + var finder = new FindInFilesFinder(SearchFolder,FileFilters); finder.SearchSubFolders = SearchSubFolders; var result = await finder.SearchFilesAsync(SearchPhrase); + if (result != null) SearchResults = new ObservableCollection(result.OrderBy( r=> r.FilePath + "!" + r.FileOnly) ); else @@ -171,7 +173,7 @@ public async Task SearchAsync() } - public SearchInFilesFinder SearchFinder { get; set; } + public FindInFilesFinder FindFinder { get; set; } #region INotifyPropertyChanged diff --git a/MarkdownMonster/Windows/FileSearch/SearchInFilesFinder.cs b/MarkdownMonster/Windows/FileSearch/FindInFilesFinder.cs similarity index 95% rename from MarkdownMonster/Windows/FileSearch/SearchInFilesFinder.cs rename to MarkdownMonster/Windows/FileSearch/FindInFilesFinder.cs index 29c40166e..aa4caafc8 100644 --- a/MarkdownMonster/Windows/FileSearch/SearchInFilesFinder.cs +++ b/MarkdownMonster/Windows/FileSearch/FindInFilesFinder.cs @@ -8,7 +8,7 @@ namespace MarkdownMonster.Utilities { - public class SearchInFilesFinder + public class FindInFilesFinder { public string Path { get; set; } public string SearchFilePattern { get; set; } @@ -23,7 +23,7 @@ public class SearchInFilesFinder private byte[] SearchPhraseBytes { get; set; } - public SearchInFilesFinder(string path, string searchFilePattern, params string[] extensions) + public FindInFilesFinder(string path, string searchFilePattern, params string[] extensions) { Path = path; SearchFilePattern = searchFilePattern; @@ -46,6 +46,9 @@ public List SearchFiles(string searchPhrase = null, if (searchPhrase != null) SearchPhrase = searchPhrase; + if (SearchPhrase == null) + return null; + SearchPhraseBytes = Encoding.UTF8.GetBytes(searchPhrase); var list = new List(); diff --git a/Tests/MarkdownMonster.Test/SearchInFilesFinderTests.cs b/Tests/MarkdownMonster.Test/SearchInFilesFinderTests.cs index 00db0df96..c9d288334 100644 --- a/Tests/MarkdownMonster.Test/SearchInFilesFinderTests.cs +++ b/Tests/MarkdownMonster.Test/SearchInFilesFinderTests.cs @@ -19,7 +19,7 @@ public class SearchInFilesFinderTests public void SearchInFilesTest() { - var finder = new SearchInFilesFinder(STR_Folder,"*.*"); + var finder = new FindInFilesFinder(STR_Folder,"*.*"); finder.NoMatchDetails = true; var result = finder.SearchFiles("Markdown"); @@ -31,7 +31,7 @@ public void SearchInFilesTest() public async Task SearchInFilesAsyncTest() { - var finder = new SearchInFilesFinder(STR_Folder, "*.*"); + var finder = new FindInFilesFinder(STR_Folder, "*.*"); var result = await finder.SearchFilesAsync("Single line breaks");