Revise and build out ICustomSearch implementations
This commit is contained in:
parent
f88b04b7bc
commit
230ffdc029
4 changed files with 45 additions and 10 deletions
|
|
@ -39,15 +39,17 @@ using MatterHackers.Agg.UI;
|
|||
|
||||
namespace MatterHackers.MatterControl.Library
|
||||
{
|
||||
public class FileSystemContainer : WritableContainer
|
||||
public class FileSystemContainer : WritableContainer, ICustomSearch
|
||||
{
|
||||
private FileSystemWatcher directoryWatcher;
|
||||
|
||||
private bool isActiveContainer;
|
||||
private bool isDirty;
|
||||
private string keywordFilter;
|
||||
|
||||
public FileSystemContainer(string fullPath)
|
||||
{
|
||||
this.CustomSearch = this;
|
||||
this.FullPath = fullPath;
|
||||
this.Name = Path.GetFileName(fullPath);
|
||||
|
||||
|
|
@ -84,6 +86,8 @@ namespace MatterHackers.MatterControl.Library
|
|||
base.Activate();
|
||||
}
|
||||
|
||||
public override ICustomSearch CustomSearch { get; }
|
||||
|
||||
public override void Deactivate()
|
||||
{
|
||||
this.isActiveContainer = false;
|
||||
|
|
@ -145,7 +149,7 @@ namespace MatterHackers.MatterControl.Library
|
|||
|
||||
try
|
||||
{
|
||||
string filter = ""; // keywordFilter.Trim();
|
||||
string filter = keywordFilter?.Trim() ?? "";
|
||||
|
||||
var allFiles = Directory.GetFiles(FullPath, "*.*", searchDepth);
|
||||
|
||||
|
|
@ -218,6 +222,20 @@ namespace MatterHackers.MatterControl.Library
|
|||
return validName;
|
||||
}
|
||||
|
||||
public void ApplyFilter(string filter, ILibraryContext libraryContext)
|
||||
{
|
||||
keywordFilter = filter;
|
||||
this.Load();
|
||||
this.OnContentChanged();
|
||||
}
|
||||
|
||||
public void ClearFilter()
|
||||
{
|
||||
keywordFilter = null;
|
||||
this.Load();
|
||||
this.OnContentChanged();
|
||||
}
|
||||
|
||||
public async override void Add(IEnumerable<ILibraryItem> items)
|
||||
{
|
||||
if (!items.Any())
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ namespace MatterHackers.MatterControl.Library
|
|||
|
||||
public string StatusMessage { get; set; } = "";
|
||||
|
||||
public ICustomSearch CustomSearch { get; } = null;
|
||||
public virtual ICustomSearch CustomSearch { get; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Reloads the container when contents have changes and fires ContentChanged to notify listeners
|
||||
|
|
|
|||
|
|
@ -50,15 +50,20 @@ namespace MatterHackers.MatterControl.Library
|
|||
public override string Name { get => this.PrintItem.Name; set => this.PrintItem.Name = value; }
|
||||
}
|
||||
|
||||
public class SqliteLibraryContainer : WritableContainer
|
||||
public class SqliteLibraryContainer : WritableContainer, ICustomSearch
|
||||
{
|
||||
private string keywordFilter = "";
|
||||
|
||||
// Use default rootCollectionID - normally this constructor isn't used but exists to validate behavior in tests
|
||||
public SqliteLibraryContainer()
|
||||
: this(Datastore.Instance.dbSQLite.Table<PrintItemCollection>().Where(v => v.Name == "_library").Take(1).FirstOrDefault()?.Id ?? 0)
|
||||
{ }
|
||||
{
|
||||
}
|
||||
|
||||
public SqliteLibraryContainer(int collectionID)
|
||||
{
|
||||
this.CustomSearch = this;
|
||||
|
||||
this.IsProtected = false;
|
||||
this.ChildContainers = new List<ILibraryContainerLink>();
|
||||
this.Items = new List<ILibraryItem>();
|
||||
|
|
@ -68,9 +73,7 @@ namespace MatterHackers.MatterControl.Library
|
|||
|
||||
public int CollectionID { get; private set; }
|
||||
|
||||
private string keywordFilter = "";
|
||||
|
||||
public ICustomSearch CustomSearch { get; } = null;
|
||||
public override ICustomSearch CustomSearch { get; }
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
|
|
@ -152,7 +155,7 @@ namespace MatterHackers.MatterControl.Library
|
|||
});
|
||||
}
|
||||
|
||||
public List<PrintItem> GetLibraryItems(string keyphrase = null)
|
||||
private List<PrintItem> GetLibraryItems(string keyphrase = null)
|
||||
{
|
||||
// TODO: String concatenation to build sql statements is the root of all sql injection attacks. This needs to be changed to use parameter objects as would be expected
|
||||
string query;
|
||||
|
|
@ -242,6 +245,20 @@ namespace MatterHackers.MatterControl.Library
|
|||
{
|
||||
}
|
||||
|
||||
public void ApplyFilter(string filter, ILibraryContext libraryContext)
|
||||
{
|
||||
keywordFilter = filter;
|
||||
this.Load();
|
||||
this.OnContentChanged();
|
||||
}
|
||||
|
||||
public void ClearFilter()
|
||||
{
|
||||
keywordFilter = null;
|
||||
this.Load();
|
||||
this.OnContentChanged();
|
||||
}
|
||||
|
||||
public class SqliteLibraryContainerLink : ILibraryContainerLink
|
||||
{
|
||||
public string ID { get; } = Guid.NewGuid().ToString();
|
||||
|
|
|
|||
|
|
@ -477,7 +477,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
if (libraryContext.ActiveContainer.CustomSearch is ICustomSearch customSearch)
|
||||
if (libraryContext.ActiveContainer.CustomSearch is ICustomSearch customSearch)
|
||||
{
|
||||
// Do custom search
|
||||
customSearch.ApplyFilter(searchInput.Text.Trim(), libraryContext);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue