From a89c7e18f9bf221db8d0ccdf0eb1d464a5eeb721 Mon Sep 17 00:00:00 2001 From: alcexhim Date: Thu, 18 Dec 2014 10:25:36 -0500 Subject: [PATCH] Automatically filter on details returned by GetDetails() call to make things easier on us --- .../Dialogs/GenericBrowserPopup.cs | 12 ++++++- .../UniversalEditor.Core/AccessorReference.cs | 10 ------ .../DataFormatReference.cs | 32 +++++++++++-------- .../ObjectModelReference.cs | 11 ------- .../UniversalEditor.Core/References.cs | 6 ---- 5 files changed, 29 insertions(+), 42 deletions(-) diff --git a/CSharp/Engines/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/Dialogs/GenericBrowserPopup.cs b/CSharp/Engines/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/Dialogs/GenericBrowserPopup.cs index 1223ac83..58d01086 100644 --- a/CSharp/Engines/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/Dialogs/GenericBrowserPopup.cs +++ b/CSharp/Engines/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/Dialogs/GenericBrowserPopup.cs @@ -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); } diff --git a/CSharp/Libraries/UniversalEditor.Core/AccessorReference.cs b/CSharp/Libraries/UniversalEditor.Core/AccessorReference.cs index 12da523a..21003195 100644 --- a/CSharp/Libraries/UniversalEditor.Core/AccessorReference.cs +++ b/CSharp/Libraries/UniversalEditor.Core/AccessorReference.cs @@ -30,16 +30,6 @@ namespace UniversalEditor private string mvarTitle = String.Empty; public string Title { get { return mvarTitle; } set { mvarTitle = value; } } - - /// - /// Determines if this object should be filtered by the given criteria. - /// - /// The filter that determines whether this object should be displayed in a list of objects. - /// True if this object should appear in the list; false otherwise. - public bool ShouldFilterObject(string filter) - { - return mvarTitle.ToLower().Contains(filter.ToLower()); - } /// /// Gets the detail fields that are shown in lists of this object in details view. diff --git a/CSharp/Libraries/UniversalEditor.Core/DataFormatReference.cs b/CSharp/Libraries/UniversalEditor.Core/DataFormatReference.cs index fd511859..80e18cdc 100644 --- a/CSharp/Libraries/UniversalEditor.Core/DataFormatReference.cs +++ b/CSharp/Libraries/UniversalEditor.Core/DataFormatReference.cs @@ -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) diff --git a/CSharp/Libraries/UniversalEditor.Core/ObjectModelReference.cs b/CSharp/Libraries/UniversalEditor.Core/ObjectModelReference.cs index ff75f0bc..ad11ec28 100644 --- a/CSharp/Libraries/UniversalEditor.Core/ObjectModelReference.cs +++ b/CSharp/Libraries/UniversalEditor.Core/ObjectModelReference.cs @@ -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; } } diff --git a/CSharp/Libraries/UniversalEditor.Core/References.cs b/CSharp/Libraries/UniversalEditor.Core/References.cs index 36c5b28d..6feb84ac 100644 --- a/CSharp/Libraries/UniversalEditor.Core/References.cs +++ b/CSharp/Libraries/UniversalEditor.Core/References.cs @@ -34,11 +34,5 @@ namespace UniversalEditor /// /// An array of s that are shown in detail columns of lists of this object. string[] GetDetails(); - /// - /// Determines if this object should be filtered by the given criteria. - /// - /// The filter that determines whether this object should be displayed in a list of objects. - /// True if this object should appear in the list; false otherwise. - bool ShouldFilterObject(string filter); } }