TryMoveFocus() public method

Tries to move the focus forward or backwards
public TryMoveFocus ( bool forward = true ) : bool
forward bool If true then the manager will try to move forwards, otherwise backwards
return bool
Example #1
0
        /// <summary>
        /// Starts the app, asynchronously.
        /// </summary>
        /// <returns>A task that will complete when the app exits</returns>
        public override Task Start()
        {
            QueueAction(() =>
            {
                if (_current != null)
                {
                    throw new NotSupportedException("An application is already running on this thread.");
                }
                // ensures that the current app is set on the message pump thread
                _current = this;
            });

            if (SetFocusOnStart)
            {
                QueueAction(() =>
                {
                    FocusManager.TryMoveFocus();
                });
            }

            Paint();

            Task pumpTask = base.Start();

            var cleanupTask = pumpTask.ContinueWith((t) =>
            {
                ExitInternal();
            });

            return(cleanupTask);
        }
Example #2
0
 /// <summary>
 /// Handles key input for the application
 /// </summary>
 /// <param name="info">The key that was pressed</param>
 protected override void HandleKeyInput(ConsoleKeyInfo info)
 {
     if (FocusManager.GlobalKeyHandlers.TryIntercept(info))
     {
         // great, it was handled
     }
     else if (info.Key == ConsoleKey.Tab)
     {
         FocusManager.TryMoveFocus(info.Modifiers.HasFlag(ConsoleModifiers.Shift) == false);
     }
     else if (info.Key == ConsoleKey.Escape)
     {
         Stop();
         return;
     }
     else if (FocusManager.FocusedControl != null)
     {
         FocusManager.FocusedControl.HandleKeyInput(info);
     }
     else
     {
         // not handled
     }
     Paint();
 }
Example #3
0
        /// <summary>
        /// Starts the app, asynchronously.
        /// </summary>
        /// <returns>A task that will complete when the app exits</returns>
        public override Promise Start()
        {
            QueueActionInFront(() =>
            {
                if (_current != null)
                {
                    throw new NotSupportedException("An application is already running on this thread.");
                }
                // ensures that the current app is set on the message pump thread
                _current = this;
            });

            if (SetFocusOnStart)
            {
                QueueAction(() =>
                {
                    FocusManager.TryMoveFocus();
                });
            }

            Paint();

            return(base.Start().Finally((p) =>
            {
                ExitInternal();
            }));
        }
Example #4
0
        /// <summary>
        /// Starts the app, asynchronously.
        /// </summary>
        /// <returns>A task that will complete when the app exits</returns>
        public override Promise Start()
        {
            QueueActionInFront(() =>
            {
                if (_current != null)
                {
                    throw new NotSupportedException("An application is already running on this thread.");
                }
                // ensures that the current app is set on the message pump thread
                _current = this;
                QueueAction(() =>
                {
                    AssertSizeRequirements(true);
                    this.WindowResized.SubscribeForLifetime(() => this.AssertSizeRequirements(false), this);
                });
            });

            if (SetFocusOnStart)
            {
                QueueAction(() =>
                {
                    FocusManager.TryMoveFocus();
                });
            }

            Paint();

            return(base.Start().Finally((p) =>
            {
                ExitInternal();
            }));
        }
Example #5
0
        /// <summary>
        /// Starts the app, asynchronously.
        /// </summary>
        /// <returns>A task that will complete when the app exits</returns>
        public override async Task Start()
        {
            if (SetFocusOnStart)
            {
                InvokeNextCycle(() =>
                {
                    FocusManager.TryMoveFocus();
                });
            }

            Paint();

            await base.Start();

            ExitInternal();
        }
Example #6
0
        /// <summary>
        /// Starts the app, asynchronously.
        /// </summary>
        /// <returns>A task that will complete when the app exits</returns>
        public override Promise Start()
        {
            if (SetFocusOnStart)
            {
                QueueAction(() =>
                {
                    FocusManager.TryMoveFocus();
                });
            }

            Paint();

            return(base.Start().Finally((p) =>
            {
                ExitInternal();
            }));
        }
Example #7
0
        /// <summary>
        /// Starts the app, asynchronously.
        /// </summary>
        /// <returns>A task that will complete when the app exits</returns>
        public override async Task Start()
        {
            if (SetFocusOnStart)
            {
                InvokeNextCycle(() =>
                {
                    FocusManager.TryMoveFocus();
                });
            }

            try
            {
                Invoke(Startup);
                await base.Start();
            }
            finally
            {
                ExitInternal();
            }
        }
Example #8
0
        public override void Run()
        {
            _current = this;
            if (SetFocusOnStart)
            {
                InvokeNextCycle(() =>
                {
                    FocusManager.TryMoveFocus();
                });
            }

            try
            {
                base.Run();
                Invoke(Startup);
            }
            finally
            {
                ExitInternal();
            }
        }
Example #9
0
        private void KeyPressed(ConsoleKeyInfo info)
        {
            if (FocusManager.GlobalKeyHandlers.TryIntercept(info))
            {
                // great, it was handled
            }
            else if (info.Key == ConsoleKey.Tab)
            {
                FocusManager.TryMoveFocus(info.Modifiers.HasFlag(ConsoleModifiers.Shift) == false);
            }
            else if (info.Key == ConsoleKey.Escape)
            {
                MessagePump.Stop();
                return;
            }
            else if (FocusManager.FocusedControl != null)
            {
                FocusManager.FocusedControl.HandleKeyInput(info);
            }

            Paint();
        }