From 6885e561db7ef1d8fb75fc9121ca4d2b6b39fd71 Mon Sep 17 00:00:00 2001 From: Nils Hausfeld Date: Thu, 30 May 2024 19:48:34 +0200 Subject: [PATCH 1/3] - Improved item search for item list context menu (based on visject CM item search improvements) --- Source/Editor/GUI/ItemsListContextMenu.cs | 90 +++++++++++++++++------ 1 file changed, 68 insertions(+), 22 deletions(-) diff --git a/Source/Editor/GUI/ItemsListContextMenu.cs b/Source/Editor/GUI/ItemsListContextMenu.cs index 78fbcd779..4084715fe 100644 --- a/Source/Editor/GUI/ItemsListContextMenu.cs +++ b/Source/Editor/GUI/ItemsListContextMenu.cs @@ -23,6 +23,9 @@ namespace FlaxEditor.GUI [HideInEditor] public class Item : Control { + private bool _isStartsWithMatch; + private bool _isFullMatch; + /// /// The is mouse down flag. /// @@ -43,6 +46,11 @@ namespace FlaxEditor.GUI /// public string Category; + /// + /// A computed score for the context menu order + /// + public float SortScore; + /// /// Occurs when items gets clicked by the user. /// @@ -61,44 +69,69 @@ namespace FlaxEditor.GUI { } + /// + /// Updates the + /// + public void UpdateScore() + { + SortScore = 0; + + if(!Visible) + return; + + if (_highlights is { Count: > 0 }) + SortScore += 1; + if (_isStartsWithMatch) + SortScore += 2; + if (_isFullMatch) + SortScore += 5; + } + /// /// Updates the filter. /// /// The filter text. public void UpdateFilter(string filterText) { + _isStartsWithMatch = _isFullMatch = false; + if (string.IsNullOrWhiteSpace(filterText)) { // Clear filter _highlights?.Clear(); Visible = true; + return; } - else + + if (QueryFilterHelper.Match(filterText, Name, out var ranges)) { - if (QueryFilterHelper.Match(filterText, Name, out var ranges)) - { - // Update highlights - if (_highlights == null) - _highlights = new List(ranges.Length); - else - _highlights.Clear(); - var style = Style.Current; - var font = style.FontSmall; - for (int i = 0; i < ranges.Length; i++) - { - var start = font.GetCharPosition(Name, ranges[i].StartIndex); - var end = font.GetCharPosition(Name, ranges[i].EndIndex); - _highlights.Add(new Rectangle(start.X + 2, 0, end.X - start.X, Height)); - } - Visible = true; - } + // Update highlights + if (_highlights == null) + _highlights = new List(ranges.Length); else + _highlights.Clear(); + var style = Style.Current; + var font = style.FontSmall; + for (int i = 0; i < ranges.Length; i++) { - // Hide - _highlights?.Clear(); - Visible = false; + var start = font.GetCharPosition(Name, ranges[i].StartIndex); + var end = font.GetCharPosition(Name, ranges[i].EndIndex); + _highlights.Add(new Rectangle(start.X + 2, 0, end.X - start.X, Height)); + + if (ranges[i].StartIndex <= 0) + { + _isStartsWithMatch = true; + if (ranges[i].Length == Name.Length) + _isFullMatch = true; + } } + Visible = true; + return; } + + // Hide + _highlights?.Clear(); + Visible = false; } /// @@ -178,7 +211,14 @@ namespace FlaxEditor.GUI public override int Compare(Control other) { if (other is Item otherItem) - return string.Compare(Name, otherItem.Name, StringComparison.Ordinal); + { + int order = -1 * SortScore.CompareTo(otherItem.SortScore); + if (order == 0) + { + order = string.Compare(Name, otherItem.Name, StringComparison.Ordinal); + } + return order; + } return base.Compare(other); } } @@ -249,7 +289,10 @@ namespace FlaxEditor.GUI for (int i = 0; i < items.Count; i++) { if (items[i] is Item item) + { item.UpdateFilter(_searchBox.Text); + item.UpdateScore(); + } } if (_categoryPanels != null) { @@ -262,6 +305,7 @@ namespace FlaxEditor.GUI if (category.Children[j] is Item item2) { item2.UpdateFilter(_searchBox.Text); + item2.UpdateScore(); anyVisible |= item2.Visible; } } @@ -273,6 +317,8 @@ namespace FlaxEditor.GUI } } + SortItems(); + UnlockChildrenRecursive(); PerformLayout(true); _searchBox.Focus(); From 8ef1cad6fbfbb7b81dbe0af4f294501849bca86d Mon Sep 17 00:00:00 2001 From: Nils Hausfeld Date: Thu, 30 May 2024 19:48:43 +0200 Subject: [PATCH 2/3] Revert "- Improved item search for item list context menu (based on visject CM item search improvements)" This reverts commit 6885e561db7ef1d8fb75fc9121ca4d2b6b39fd71. --- Source/Editor/GUI/ItemsListContextMenu.cs | 88 ++++++----------------- 1 file changed, 21 insertions(+), 67 deletions(-) diff --git a/Source/Editor/GUI/ItemsListContextMenu.cs b/Source/Editor/GUI/ItemsListContextMenu.cs index 4084715fe..78fbcd779 100644 --- a/Source/Editor/GUI/ItemsListContextMenu.cs +++ b/Source/Editor/GUI/ItemsListContextMenu.cs @@ -23,9 +23,6 @@ namespace FlaxEditor.GUI [HideInEditor] public class Item : Control { - private bool _isStartsWithMatch; - private bool _isFullMatch; - /// /// The is mouse down flag. /// @@ -46,11 +43,6 @@ namespace FlaxEditor.GUI /// public string Category; - /// - /// A computed score for the context menu order - /// - public float SortScore; - /// /// Occurs when items gets clicked by the user. /// @@ -69,69 +61,44 @@ namespace FlaxEditor.GUI { } - /// - /// Updates the - /// - public void UpdateScore() - { - SortScore = 0; - - if(!Visible) - return; - - if (_highlights is { Count: > 0 }) - SortScore += 1; - if (_isStartsWithMatch) - SortScore += 2; - if (_isFullMatch) - SortScore += 5; - } - /// /// Updates the filter. /// /// The filter text. public void UpdateFilter(string filterText) { - _isStartsWithMatch = _isFullMatch = false; - if (string.IsNullOrWhiteSpace(filterText)) { // Clear filter _highlights?.Clear(); Visible = true; - return; } - - if (QueryFilterHelper.Match(filterText, Name, out var ranges)) + else { - // Update highlights - if (_highlights == null) - _highlights = new List(ranges.Length); - else - _highlights.Clear(); - var style = Style.Current; - var font = style.FontSmall; - for (int i = 0; i < ranges.Length; i++) + if (QueryFilterHelper.Match(filterText, Name, out var ranges)) { - var start = font.GetCharPosition(Name, ranges[i].StartIndex); - var end = font.GetCharPosition(Name, ranges[i].EndIndex); - _highlights.Add(new Rectangle(start.X + 2, 0, end.X - start.X, Height)); - - if (ranges[i].StartIndex <= 0) + // Update highlights + if (_highlights == null) + _highlights = new List(ranges.Length); + else + _highlights.Clear(); + var style = Style.Current; + var font = style.FontSmall; + for (int i = 0; i < ranges.Length; i++) { - _isStartsWithMatch = true; - if (ranges[i].Length == Name.Length) - _isFullMatch = true; + var start = font.GetCharPosition(Name, ranges[i].StartIndex); + var end = font.GetCharPosition(Name, ranges[i].EndIndex); + _highlights.Add(new Rectangle(start.X + 2, 0, end.X - start.X, Height)); } + Visible = true; + } + else + { + // Hide + _highlights?.Clear(); + Visible = false; } - Visible = true; - return; } - - // Hide - _highlights?.Clear(); - Visible = false; } /// @@ -211,14 +178,7 @@ namespace FlaxEditor.GUI public override int Compare(Control other) { if (other is Item otherItem) - { - int order = -1 * SortScore.CompareTo(otherItem.SortScore); - if (order == 0) - { - order = string.Compare(Name, otherItem.Name, StringComparison.Ordinal); - } - return order; - } + return string.Compare(Name, otherItem.Name, StringComparison.Ordinal); return base.Compare(other); } } @@ -289,10 +249,7 @@ namespace FlaxEditor.GUI for (int i = 0; i < items.Count; i++) { if (items[i] is Item item) - { item.UpdateFilter(_searchBox.Text); - item.UpdateScore(); - } } if (_categoryPanels != null) { @@ -305,7 +262,6 @@ namespace FlaxEditor.GUI if (category.Children[j] is Item item2) { item2.UpdateFilter(_searchBox.Text); - item2.UpdateScore(); anyVisible |= item2.Visible; } } @@ -317,8 +273,6 @@ namespace FlaxEditor.GUI } } - SortItems(); - UnlockChildrenRecursive(); PerformLayout(true); _searchBox.Focus(); From 11ec018933b929ab207f120c78ed2b2a6eb6891b Mon Sep 17 00:00:00 2001 From: Nils Hausfeld Date: Thu, 30 May 2024 19:53:54 +0200 Subject: [PATCH 3/3] - Improved Items list context menu item search (based on visject search improvements) --- Source/Editor/GUI/ItemsListContextMenu.cs | 90 +++++++++++++++++------ 1 file changed, 68 insertions(+), 22 deletions(-) diff --git a/Source/Editor/GUI/ItemsListContextMenu.cs b/Source/Editor/GUI/ItemsListContextMenu.cs index 78fbcd779..4a1793982 100644 --- a/Source/Editor/GUI/ItemsListContextMenu.cs +++ b/Source/Editor/GUI/ItemsListContextMenu.cs @@ -23,6 +23,9 @@ namespace FlaxEditor.GUI [HideInEditor] public class Item : Control { + private bool _isStartsWithMatch; + private bool _isFullMatch; + /// /// The is mouse down flag. /// @@ -43,6 +46,11 @@ namespace FlaxEditor.GUI /// public string Category; + /// + /// A computed score for the context menu order + /// + public float SortScore; + /// /// Occurs when items gets clicked by the user. /// @@ -61,44 +69,69 @@ namespace FlaxEditor.GUI { } + /// + /// Updates the + /// + public void UpdateScore() + { + SortScore = 0; + + if (!Visible) + return; + + if (_highlights is { Count: > 0 }) + SortScore += 1; + if (_isStartsWithMatch) + SortScore += 2; + if (_isFullMatch) + SortScore += 5; + } + /// /// Updates the filter. /// /// The filter text. public void UpdateFilter(string filterText) { + _isStartsWithMatch = _isFullMatch = false; + if (string.IsNullOrWhiteSpace(filterText)) { // Clear filter _highlights?.Clear(); Visible = true; + return; } - else + + if (QueryFilterHelper.Match(filterText, Name, out var ranges)) { - if (QueryFilterHelper.Match(filterText, Name, out var ranges)) - { - // Update highlights - if (_highlights == null) - _highlights = new List(ranges.Length); - else - _highlights.Clear(); - var style = Style.Current; - var font = style.FontSmall; - for (int i = 0; i < ranges.Length; i++) - { - var start = font.GetCharPosition(Name, ranges[i].StartIndex); - var end = font.GetCharPosition(Name, ranges[i].EndIndex); - _highlights.Add(new Rectangle(start.X + 2, 0, end.X - start.X, Height)); - } - Visible = true; - } + // Update highlights + if (_highlights == null) + _highlights = new List(ranges.Length); else + _highlights.Clear(); + var style = Style.Current; + var font = style.FontSmall; + for (int i = 0; i < ranges.Length; i++) { - // Hide - _highlights?.Clear(); - Visible = false; + var start = font.GetCharPosition(Name, ranges[i].StartIndex); + var end = font.GetCharPosition(Name, ranges[i].EndIndex); + _highlights.Add(new Rectangle(start.X + 2, 0, end.X - start.X, Height)); + + if (ranges[i].StartIndex <= 0) + { + _isStartsWithMatch = true; + if (ranges[i].Length == Name.Length) + _isFullMatch = true; + } } + Visible = true; + return; } + + // Hide + _highlights?.Clear(); + Visible = false; } /// @@ -178,7 +211,14 @@ namespace FlaxEditor.GUI public override int Compare(Control other) { if (other is Item otherItem) - return string.Compare(Name, otherItem.Name, StringComparison.Ordinal); + { + int order = -1 * SortScore.CompareTo(otherItem.SortScore); + if (order == 0) + { + order = string.Compare(Name, otherItem.Name, StringComparison.Ordinal); + } + return order; + } return base.Compare(other); } } @@ -249,7 +289,10 @@ namespace FlaxEditor.GUI for (int i = 0; i < items.Count; i++) { if (items[i] is Item item) + { item.UpdateFilter(_searchBox.Text); + item.UpdateScore(); + } } if (_categoryPanels != null) { @@ -262,6 +305,7 @@ namespace FlaxEditor.GUI if (category.Children[j] is Item item2) { item2.UpdateFilter(_searchBox.Text); + item2.UpdateScore(); anyVisible |= item2.Visible; } } @@ -273,6 +317,8 @@ namespace FlaxEditor.GUI } } + SortItems(); + UnlockChildrenRecursive(); PerformLayout(true); _searchBox.Focus();