public bool TrySetFocus(ConsoleControl newFocusControl)
{
var index = focusStack.Peek().Controls.IndexOf(newFocusControl);
if (index < 0)
{
throw new InvalidOperationException("The given control is not in the control tree");
}
if(newFocusControl.CanFocus == false)
{
return false;
}
else if(newFocusControl == FocusedControl)
{
return true;
}
else
{
if (FocusedControl != null)
{
ClearFocus();
}
newFocusControl.HasFocus = true;
FocusedControl = newFocusControl;
focusStack.Peek().FocusIndex = index;
if (FocusedControl != null)
{
FocusedControl.FireFocused(true);
}
return true;
}
}