private void textLostFocus(object sender, RoutedEventArgs e)
        {
            if (NumericOnly)
            {
                UpdateTextNumeric(text.Text);
            }

            OnTextEntered?.Invoke(this, new TextEventArgs(text.Text));
        }
        public void SetText(string txt)
        {
            text.Text = txt;

            if (NumericOnly)
            {
                UpdateTextNumeric(text.Text);
            }

            OnTextEntered?.Invoke(this, new TextEventArgs(text.Text));
        }
        private void textKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                if (NumericOnly)
                {
                    UpdateTextNumeric(text.Text);
                }

                OnTextEntered?.Invoke(this, new TextEventArgs(text.Text));
            }
        }
Beispiel #4
0
 private static void TextEntered(object sender, TextInputEventArgs e) => OnTextEntered?.Invoke(sender, e);
Beispiel #5
0
        public void PushInput(ConsoleKeyInfo key)
        {
            if (key.Modifiers.HasFlag(ConsoleModifiers.Alt) || key.Modifiers.HasFlag(ConsoleModifiers.Control))
            {
                return;
            }

            var buf = _Content as StringBuilder;

            switch (key.Key)
            {
            case ConsoleKey.Backspace:
            {
                if (buf.Length == 0 || Cursor < 1)
                {
                    break;
                }

                buf.Remove(--Cursor, 1);
                Render();
            }
            break;

            case ConsoleKey.Delete:
            {
                if (Cursor >= buf.Length)
                {
                    break;
                }

                buf.Remove(Cursor, 1);
                Render();     // TODO: Do some speedup here?
            }
            break;

            case ConsoleKey.LeftArrow:
                if (Cursor > 0)
                {
                    Cursor--;
                    Console.CursorLeft--;
                }
                break;

            case ConsoleKey.RightArrow:
                if (Cursor < buf.Length)
                {
                    Cursor++;
                    Console.CursorLeft++;
                }
                break;

            case ConsoleKey.UpArrow:
            {
                if (_HistoryPtr + 1 >= _History.Count)
                {
                    break;
                }

                if (_HistoryPtr < 0 && buf.Length > 0)
                {
                    _HistoryCmd = buf.ToString();
                }

                ++_HistoryPtr;
                buf.Clear();

                buf.Append(_History[_History.Count - _HistoryPtr - 1]);

                Cursor = buf.Length;
                Render();
            }
            break;

            case ConsoleKey.DownArrow:
            {
                if (_HistoryPtr < 0)
                {
                    break;
                }

                --_HistoryPtr;
                buf.Clear();

                if (_HistoryPtr >= 0)
                {
                    buf.Append(_History[_History.Count - _HistoryPtr - 1]);
                }
                else
                {
                    buf.Append(_HistoryCmd);
                }

                Cursor = buf.Length;
                Render();
            }
            break;

            case ConsoleKey.Home:
                Console.CursorLeft -= Cursor;
                Cursor              = 0;
                break;

            case ConsoleKey.End:
                Console.CursorLeft += buf.Length - Cursor;
                Cursor              = buf.Length;
                break;

            case ConsoleKey.Enter:
            {
                var cmd = buf.ToString();

                var displayed = Content;

                buf.Clear();
                Cursor = 0;
                Render();
                Focus();

                _HistoryCmd = null;
                _HistoryPtr = -1;
                _History.Add(cmd);
                if (_History.Count > HistoryLength)
                {
                    _History.RemoveAt(0);
                }

                OnTextEntered?.Invoke(this, cmd);
            }
            break;

            default:
            {
                if (!char.IsControl(key.KeyChar) &&
                    !key.Modifiers.HasFlag(ConsoleModifiers.Alt) &&
                    !key.Modifiers.HasFlag(ConsoleModifiers.Control))
                {
                    buf.Insert(Cursor++, key.KeyChar.ToString());
                    Render();
                    break;
                }
            }
            break;
            }
        }