Change from KeywordFilter property to ICustomSearch

This commit is contained in:
John Lewin 2018-12-21 18:35:59 -08:00
parent 28333b5926
commit f88b04b7bc
11 changed files with 78 additions and 47 deletions

View file

@ -477,7 +477,17 @@ namespace MatterHackers.MatterControl.PrintLibrary
{
UiThread.RunOnIdle(() =>
{
libraryContext.ActiveContainer.KeywordFilter = searchInput.Text.Trim();
if (libraryContext.ActiveContainer.CustomSearch is ICustomSearch customSearch)
{
// Do custom search
customSearch.ApplyFilter(searchInput.Text.Trim(), libraryContext);
}
else
{
// Do basic filtering
// filter the view with a predicate, applying the active sort
libraryView.ApplyFilter(searchInput.Text.Trim());
}
});
}
@ -490,11 +500,20 @@ namespace MatterHackers.MatterControl.PrintLibrary
UiThread.RunOnIdle(() =>
{
searchContainer.KeywordFilter = "";
// Restore the original ActiveContainer before search started - some containers may change context
libraryContext.ActiveContainer = searchContainer;
if (libraryContext.ActiveContainer.CustomSearch is ICustomSearch customSearch)
{
// Clear custom search
customSearch.ClearFilter();
// Restore the original ActiveContainer before search started - some containers may change context
libraryContext.ActiveContainer = searchContainer;
}
else
{
// Clear basic filtering
libraryView.ClearFilter();
}
searchContainer = null;
});
}
@ -544,7 +563,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
libraryTreeView.SelectedNode = owningNode;
}
searchInput.Text = activeContainer.KeywordFilter;
//searchInput.Text = activeContainer.KeywordFilter;
breadCrumbWidget.SetContainer(activeContainer);
activeContainer.ContentChanged += UpdateStatus;

View file

@ -182,6 +182,8 @@ namespace MatterHackers.MatterControl.CustomWidgets
}
private bool _ascending = true;
private string filterText;
public bool Ascending
{
get => _ascending;
@ -200,6 +202,12 @@ namespace MatterHackers.MatterControl.CustomWidgets
this.Reload().ConfigureAwait(false);
}
private bool ContainsActiveFilter(ILibraryItem item)
{
return string.IsNullOrWhiteSpace(filterText)
|| item.Name.IndexOf(filterText, StringComparison.OrdinalIgnoreCase) >= 0;
}
/// <summary>
/// Empties the list children and repopulates the list with the source container content
/// </summary>
@ -233,6 +241,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
IEnumerable<ILibraryItem> containerItems = from item in sourceContainer.ChildContainers
where item.IsVisible && this.ContainerFilter(item)
&& this.ContainsActiveFilter(item)
select item;
// Folder items
@ -254,6 +263,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
where item.IsVisible
&& (item.IsContentFileType() || item is MissingFileItem)
&& this.ItemFilter(item)
&& this.ContainsActiveFilter(item)
select item;
foreach (var item in this.SortItems(filteredResults))
@ -543,6 +553,18 @@ namespace MatterHackers.MatterControl.CustomWidgets
}
}
internal void ApplyFilter(string filterText)
{
this.filterText = filterText;
this.Reload().ConfigureAwait(false);
}
internal void ClearFilter()
{
this.filterText = null;
this.Reload().ConfigureAwait(false);
}
public override void OnMouseWheel(MouseEventArgs mouseEvent)
{
if (scrollAmount == -1)

View file

@ -317,7 +317,10 @@ namespace MatterHackers.MatterControl.PrintLibrary
{
UiThread.RunOnIdle(() =>
{
ApplicationController.Instance.Library.ActiveContainer.KeywordFilter = searchInput.Text.Trim();
if (ApplicationController.Instance.Library.ActiveContainer.CustomSearch is ICustomSearch customSearch)
{
customSearch.ApplyFilter(searchInput.Text.Trim(), ApplicationController.Instance.Library);
}
});
}
@ -330,7 +333,10 @@ namespace MatterHackers.MatterControl.PrintLibrary
UiThread.RunOnIdle(() =>
{
searchContainer.KeywordFilter = "";
if (searchContainer.CustomSearch is ICustomSearch customSearch)
{
customSearch.ClearFilter();
}
// Restore the original ActiveContainer before search started - some containers may change context
ApplicationController.Instance.Library.ActiveContainer = searchContainer;
@ -378,7 +384,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
bool containerSupportsEdits = activeContainer is ILibraryWritableContainer;
searchInput.Text = activeContainer.KeywordFilter;
//searchInput.Text = activeContainer.KeywordFilter;
breadCrumbWidget.SetContainer(activeContainer);
activeContainer.ContentChanged += UpdateStatus;