Merge branch 'commandSuggestionImprovements' of https://github.com/xxSeys1/FlaxEngine into xxSeys1-commandSuggestionImprovements

This commit is contained in:
Wojtek Figat
2025-09-22 18:06:55 +02:00
3 changed files with 45 additions and 4 deletions

View File

@@ -233,7 +233,10 @@ namespace FlaxEditor.Windows
else else
cm.ClearItems(); cm.ClearItems();
float longestItemWidth = 0.0f;
// Add items // Add items
var font = Style.Current.FontMedium;
ItemsListContextMenu.Item lastItem = null; ItemsListContextMenu.Item lastItem = null;
foreach (var command in commands) foreach (var command in commands)
{ {
@@ -244,7 +247,7 @@ namespace FlaxEditor.Windows
}); });
var flags = DebugCommands.GetCommandFlags(command); var flags = DebugCommands.GetCommandFlags(command);
if (flags.HasFlag(DebugCommands.CommandFlags.Exec)) if (flags.HasFlag(DebugCommands.CommandFlags.Exec))
lastItem.TintColor = new Color(0.85f, 0.85f, 1.0f, 1.0f); lastItem.TintColor = new Color(0.75f, 0.75f, 1.0f, 1.0f);
else if (flags.HasFlag(DebugCommands.CommandFlags.Read) && !flags.HasFlag(DebugCommands.CommandFlags.Write)) else if (flags.HasFlag(DebugCommands.CommandFlags.Read) && !flags.HasFlag(DebugCommands.CommandFlags.Write))
lastItem.TintColor = new Color(0.85f, 0.85f, 0.85f, 1.0f); lastItem.TintColor = new Color(0.85f, 0.85f, 0.85f, 1.0f);
lastItem.Focused += item => lastItem.Focused += item =>
@@ -252,6 +255,10 @@ namespace FlaxEditor.Windows
// Set command // Set command
Set(item.Name); Set(item.Name);
}; };
float width = font.MeasureText(command).X;
if (width > longestItemWidth)
longestItemWidth = width;
} }
cm.ItemClicked += item => cm.ItemClicked += item =>
{ {
@@ -262,6 +269,10 @@ namespace FlaxEditor.Windows
// Setup popup // Setup popup
var count = commands.Count(); var count = commands.Count();
var totalHeight = count * lastItem.Height + cm.ItemsPanel.Margin.Height + cm.ItemsPanel.Spacing * (count - 1); var totalHeight = count * lastItem.Height + cm.ItemsPanel.Margin.Height + cm.ItemsPanel.Spacing * (count - 1);
// Account for scroll bars taking up a part of the width
longestItemWidth += 25f;
cm.Width = longestItemWidth;
cm.Height = 220; cm.Height = 220;
if (cm.Height > totalHeight) if (cm.Height > totalHeight)
cm.Height = totalHeight; // Limit popup height if list is small cm.Height = totalHeight; // Limit popup height if list is small
@@ -314,12 +325,25 @@ namespace FlaxEditor.Windows
// Show commands search popup based on current text input // Show commands search popup based on current text input
var text = Text.Trim(); var text = Text.Trim();
if (text.Length != 0) bool isWhitespaceOnly = string.IsNullOrWhiteSpace(Text) && !string.IsNullOrEmpty(Text);
if (text.Length != 0 || isWhitespaceOnly)
{ {
DebugCommands.Search(text, out var matches); DebugCommands.Search(text, out var matches);
if (matches.Length != 0) if (matches.Length != 0 || isWhitespaceOnly)
{ {
ShowPopup(ref _searchPopup, matches, text); string[] commands = [];
if (isWhitespaceOnly)
DebugCommands.GetAllCommands(out commands);
ShowPopup(ref _searchPopup, isWhitespaceOnly ? commands : matches, text);
if (isWhitespaceOnly)
{
// Scroll to and select first item for consistent behaviour
var firstItem = _searchPopup.ItemsPanel.Children[0] as Item;
_searchPopup.ScrollToAndHighlightItemByName(firstItem.Name);
}
return; return;
} }
} }

View File

@@ -435,6 +435,17 @@ void DebugCommands::InitAsync()
AsyncTask = Task::StartNew(InitCommands); AsyncTask = Task::StartNew(InitCommands);
} }
void DebugCommands::GetAllCommands(Array<StringView>& commands)
{
EnsureInited();
ScopeLock lock(Locker);
for (auto& command : Commands)
{
commands.Add(command.Name);
}
}
DebugCommands::CommandFlags DebugCommands::GetCommandFlags(StringView command) DebugCommands::CommandFlags DebugCommands::GetCommandFlags(StringView command)
{ {
CommandFlags result = CommandFlags::None; CommandFlags result = CommandFlags::None;

View File

@@ -46,6 +46,12 @@ public:
/// </summary> /// </summary>
API_FUNCTION() static void InitAsync(); API_FUNCTION() static void InitAsync();
/// <summary>
/// Gets all available commands.
/// </summary>
/// <param name="matches">The output list of all commands (unsorted).</param>
API_FUNCTION() static void GetAllCommands(API_PARAM(Out) Array<StringView, HeapAllocation>& commands);
/// <summary> /// <summary>
/// Returns flags of the command. /// Returns flags of the command.
/// </summary> /// </summary>