Enable search text box selection.

This commit is contained in:
Peter Kirmeier 2023-06-04 11:34:29 +02:00
parent 87fedfc7d5
commit 28fdd938ee
2 changed files with 21 additions and 21 deletions

View file

@ -69,7 +69,22 @@ namespace SystemTrayMenu.Business
case Key.Enter:
if (modifiers == ModifierKeys.None)
{
if (focussedMenu != null)
if (focussedMenu == null)
{
// Start selection based on the key's origin (sender)
// Usually only needed if no mouse selection was triggered ever before
if (sender.TrySelectAt(0, -1))
{
focussedMenu = sender;
// Home and Down would select first item but it was just selected
if (key != Key.Home && key != Key.Down)
{
SelectByKey(key, focussedMenu);
}
}
}
else
{
SelectByKey(key, focussedMenu);
}
@ -79,7 +94,7 @@ namespace SystemTrayMenu.Business
case Key.F:
if (modifiers == ModifierKeys.Control)
{
focussedMenu?.FocusTextBox();
focussedMenu?.FocusTextBox(); // TODO: Keep it? As of now the text box has focus all the time.
}
break;

View file

@ -44,9 +44,6 @@ namespace SystemTrayMenu.UserInterface
private bool directionToRight;
private Point lastLocation;
#if TODO // SEARCH
private bool isSetSearchText;
#endif
internal Menu(RowData? rowDataParent, string path)
{
InitializeComponent();
@ -188,7 +185,6 @@ namespace SystemTrayMenu.UserInterface
Command = new ActionCommand((_) => textBoxSearch.SelectAll()),
});
dgv.GotFocus += (_, _) => FocusTextBox();
dgv.SelectionChanged += ListView_SelectionChanged;
Loaded += (_, _) =>
@ -196,6 +192,8 @@ namespace SystemTrayMenu.UserInterface
NativeMethods.HideFromAltTab(this);
RaiseEvent(new(routedEvent: FadeInEvent));
FocusTextBox();
};
Closed += (_, _) =>
@ -319,21 +317,8 @@ namespace SystemTrayMenu.UserInterface
internal void FocusTextBox()
{
#if TODO // SEARCH
if (isSetSearchText)
{
isSetSearchText = false;
textBoxSearch.SelectAll();
textBoxSearch.Focus();
textBoxSearch.SelectionStart = textBoxSearch.Text.Length;
textBoxSearch.SelectionLength = 0;
}
else
{
textBoxSearch.SelectAll();
textBoxSearch.Focus();
}
#endif
textBoxSearch.Select(textBoxSearch.Text.Length, 0);
textBoxSearch.Focus();
}
internal void SetSubMenuState(MenuDataDirectoryState state)