Automatically filter on details returned by GetDetails() call to make things easier on us

This commit is contained in:
Michael Becker 2014-12-18 10:25:36 -05:00
parent 2b4ef099eb
commit a89c7e18f9
5 changed files with 29 additions and 42 deletions

View File

@ -42,7 +42,17 @@ namespace UniversalEditor.UserInterface.WindowsForms.Dialogs
lv.Items.Clear();
foreach (TRef item in mvarAvailableObjects)
{
if (String.IsNullOrEmpty(txtSearch.Text.Trim()) || item.ShouldFilterObject(txtSearch.Text))
bool itemShouldFilter = false;
string[] details = item.GetDetails();
foreach (string detail in details)
{
if (detail.ToLower().Trim().Contains(txtSearch.Text.ToLower().Trim()))
{
itemShouldFilter = true;
break;
}
}
if (String.IsNullOrEmpty(txtSearch.Text.Trim()) || itemShouldFilter)
{
AddObjectToList(item);
}

View File

@ -30,16 +30,6 @@ namespace UniversalEditor
private string mvarTitle = String.Empty;
public string Title { get { return mvarTitle; } set { mvarTitle = value; } }
/// <summary>
/// Determines if this <see cref="ReferencedBy" /> object should be filtered by the given criteria.
/// </summary>
/// <param name="filter">The filter that determines whether this object should be displayed in a list of <see cref="ReferencedBy" /> objects.</param>
/// <returns>True if this object should appear in the list; false otherwise.</returns>
public bool ShouldFilterObject(string filter)
{
return mvarTitle.ToLower().Contains(filter.ToLower());
}
/// <summary>
/// Gets the detail fields that are shown in lists of this <see cref="ReferencedBy" /> object in details view.

View File

@ -63,24 +63,28 @@ namespace UniversalEditor
public string[] GetDetails()
{
string title = mvarTitle;
/*
if (String.IsNullOrEmpty(mvarTitle) && mvarFilters.Count > 0)
Association[] assocs = Association.FromCriteria(new AssociationCriteria() { DataFormat = this });
if (String.IsNullOrEmpty(mvarTitle) && assocs.Length > 0 && assocs[0].Filters.Count > 0)
{
title = mvarFilters[0].Title;
title = assocs[0].Filters[0].Title;
}
return new string[] { title, DataFormatFilterCollectionToString(mvarFilters) };
*/
return new string[] { title };
}
public bool ShouldFilterObject(string filter)
{
string title = mvarTitle;
if (String.IsNullOrEmpty(mvarTitle))
StringBuilder sb = new StringBuilder();
foreach (Association assoc in assocs)
{
foreach (DataFormatFilter filter in assoc.Filters)
{
foreach (string s in filter.FileNameFilters)
{
sb.Append(s);
if (filter.FileNameFilters.IndexOf(s) < filter.FileNameFilters.Count - 1) sb.Append("; ");
}
if (assoc.Filters.IndexOf(filter) < assoc.Filters.Count - 1) sb.Append("; ");
}
if (Array.IndexOf(assocs, assoc) < assocs.Length - 1) sb.Append("; ");
}
if (title == null) title = String.Empty;
if (title.ToLower().Contains(filter.ToLower())) return true;
return false;
return new string[] { title, sb.ToString() };
}
public DataFormatReference(Guid id)

View File

@ -91,17 +91,6 @@ namespace UniversalEditor
{
return new string[] { mvarTitle, mvarDescription };
}
public bool ShouldFilterObject(string filter)
{
string title = mvarTitle;
if (title == null) title = String.Empty;
string description = mvarDescription;
if (description == null) description = String.Empty;
return ((title.ToLower().Contains(filter.Trim().ToLower()))
|| (description.ToLower().Contains(filter.Trim().ToLower())));
}
private Type mvarType = null;
public Type Type { get { return mvarType; } }

View File

@ -34,11 +34,5 @@ namespace UniversalEditor
/// </summary>
/// <returns>An array of <see cref="String" />s that are shown in detail columns of lists of this <see cref="T:ReferencedBy`1" /> object.</returns>
string[] GetDetails();
/// <summary>
/// Determines if this <see cref="T:ReferencedBy`1" /> object should be filtered by the given criteria.
/// </summary>
/// <param name="filter">The filter that determines whether this object should be displayed in a list of <see cref="T:ReferencedBy`1" /> objects.</param>
/// <returns>True if this object should appear in the list; false otherwise.</returns>
bool ShouldFilterObject(string filter);
}
}