Skip to content

Commit

Permalink
Fix file search where file type was not properly respected.
Browse files Browse the repository at this point in the history
- remove experimental tag.
  • Loading branch information
RickStrahl committed Sep 4, 2019
1 parent 151944e commit 26ef4fd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion MarkdownMonster/Windows/FileSearch/FileSearchControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<StackPanel Orientation="Horizontal">
<fa:FontAwesome Icon="Search" Foreground="Goldenrod" Height="16" Width="16" Margin="5,2,0,0" />
<TextBlock Height="Auto"
Text="Find in Files (experimental)"
Text="Find in Files"
FontWeight="SemiBold" FontSize="11" Padding="4,5,2,5" />
</StackPanel>

Expand Down
8 changes: 5 additions & 3 deletions MarkdownMonster/Windows/FileSearch/FileSearchModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SearchFileResult>(result.OrderBy( r=> r.FilePath + "!" + r.FileOnly) );
else
Expand All @@ -171,7 +173,7 @@ public async Task SearchAsync()
}


public SearchInFilesFinder SearchFinder { get; set; }
public FindInFilesFinder FindFinder { get; set; }


#region INotifyPropertyChanged
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace MarkdownMonster.Utilities
{
public class SearchInFilesFinder
public class FindInFilesFinder
{
public string Path { get; set; }
public string SearchFilePattern { get; set; }
Expand All @@ -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;
Expand All @@ -46,6 +46,9 @@ public List<SearchFileResult> SearchFiles(string searchPhrase = null,
if (searchPhrase != null)
SearchPhrase = searchPhrase;

if (SearchPhrase == null)
return null;

SearchPhraseBytes = Encoding.UTF8.GetBytes(searchPhrase);

var list = new List<SearchFileResult>();
Expand Down
4 changes: 2 additions & 2 deletions Tests/MarkdownMonster.Test/SearchInFilesFinderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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");

Expand Down

0 comments on commit 26ef4fd

Please sign in to comment.