2019-01-24 17:43:03 +09:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-07-16 14:55:41 +09:00
|
|
|
|
using osu.Framework.Input;
|
2018-10-02 12:02:47 +09:00
|
|
|
|
using osu.Framework.Input.Events;
|
2022-01-27 20:53:48 -08:00
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2018-11-20 16:51:59 +09:00
|
|
|
|
using osuTK.Input;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-05-12 19:57:06 +09:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
2017-01-10 17:43:00 -05:00
|
|
|
|
{
|
2017-02-19 17:59:22 +09:00
|
|
|
|
public partial class SearchTextBox : FocusedTextBox
|
2017-01-10 17:43:00 -05:00
|
|
|
|
{
|
2017-05-05 01:59:24 -03:00
|
|
|
|
protected virtual bool AllowCommit => false;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-01-10 17:43:00 -05:00
|
|
|
|
public SearchTextBox()
|
|
|
|
|
{
|
|
|
|
|
Height = 35;
|
2022-01-27 20:53:48 -08:00
|
|
|
|
PlaceholderText = HomeStrings.SearchPlaceholder;
|
2017-01-10 17:43:00 -05:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2021-09-16 18:26:12 +09:00
|
|
|
|
public override bool OnPressed(KeyBindingPressEvent<PlatformAction> e)
|
2019-07-16 14:55:41 +09:00
|
|
|
|
{
|
2021-09-16 18:26:12 +09:00
|
|
|
|
switch (e.Action)
|
2019-12-30 09:29:46 -08:00
|
|
|
|
{
|
2021-07-20 14:23:34 +09:00
|
|
|
|
case PlatformAction.MoveBackwardLine:
|
|
|
|
|
case PlatformAction.MoveForwardLine:
|
2019-12-30 09:38:22 -08:00
|
|
|
|
// Shift+delete is handled via PlatformAction on macOS. this is not so useful in the context of a SearchTextBox
|
|
|
|
|
// as we do not allow arrow key navigation in the first place (ie. the caret should always be at the end of text)
|
|
|
|
|
// Avoid handling it here to allow other components to potentially consume the shortcut.
|
2021-07-20 14:23:34 +09:00
|
|
|
|
case PlatformAction.DeleteForwardChar:
|
|
|
|
|
return false;
|
2019-12-30 09:29:46 -08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 18:26:12 +09:00
|
|
|
|
return base.OnPressed(e);
|
2019-07-16 14:55:41 +09:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 12:02:47 +09:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
2017-01-30 10:16:55 -05:00
|
|
|
|
{
|
2018-10-02 12:44:14 +09:00
|
|
|
|
if (!e.ControlPressed && !e.ShiftPressed)
|
2017-02-08 15:30:20 +09:00
|
|
|
|
{
|
2018-10-02 12:02:47 +09:00
|
|
|
|
switch (e.Key)
|
2017-02-08 15:30:20 +09:00
|
|
|
|
{
|
|
|
|
|
case Key.Left:
|
|
|
|
|
case Key.Right:
|
|
|
|
|
case Key.Up:
|
|
|
|
|
case Key.Down:
|
|
|
|
|
return false;
|
2017-07-18 17:40:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-07-18 17:40:34 +08:00
|
|
|
|
if (!AllowCommit)
|
|
|
|
|
{
|
2018-10-02 12:02:47 +09:00
|
|
|
|
switch (e.Key)
|
2017-07-18 17:40:34 +08:00
|
|
|
|
{
|
2017-06-15 23:06:28 +02:00
|
|
|
|
case Key.KeypadEnter:
|
2017-05-05 01:59:24 -03:00
|
|
|
|
case Key.Enter:
|
2017-07-18 17:40:34 +08:00
|
|
|
|
return false;
|
2017-02-08 15:30:20 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-10-02 12:44:14 +09:00
|
|
|
|
if (e.ShiftPressed)
|
2017-02-23 20:01:44 +09:00
|
|
|
|
{
|
2018-10-02 12:02:47 +09:00
|
|
|
|
switch (e.Key)
|
2017-02-23 20:01:44 +09:00
|
|
|
|
{
|
|
|
|
|
case Key.Delete:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-10-02 12:02:47 +09:00
|
|
|
|
return base.OnKeyDown(e);
|
2017-01-30 10:16:55 -05:00
|
|
|
|
}
|
2017-01-10 17:43:00 -05:00
|
|
|
|
}
|
2018-01-05 20:21:19 +09:00
|
|
|
|
}
|