Support navigation in the presence of disabled items

This commit is contained in:
miguel
2019-05-04 22:24:53 -04:00
parent f43dd1329d
commit 42d194079b
2 changed files with 28 additions and 8 deletions

View File

@@ -12,8 +12,14 @@ using NStack;
namespace Terminal.Gui {
/// <summary>
/// The dialog box is a window that by default is centered and contains one
/// or more buttons.
/// or more buttons. It defaults to the Colors.Dialog color scheme and has a
/// 1 cell padding around the edges.
/// </summary>
/// <remarks>
/// To run the dialog modally, create the Dialog, and pass this to Application.Run which
/// will execute the dialog until it terminates via the [ESC] key, or when one of the views
/// or buttons added to the dialog set the Running property on the Dialog to false.
/// </remarks>
public class Dialog : Window {
List<Button> buttons = new List<Button> ();
const int padding = 1;

View File

@@ -10,6 +10,7 @@
using System;
using NStack;
using System.Linq;
namespace Terminal.Gui {
@@ -130,6 +131,13 @@ namespace Terminal.Gui {
maxW = Math.Max (l, maxW);
}
current = -1;
for (int i = 0; i < items.Length; i++) {
if (items [i] != null) {
current = i;
break;
}
}
return new Rect (x, y, maxW + 2, items.Length + 2);
}
@@ -191,15 +199,21 @@ namespace Terminal.Gui {
{
switch (kb.Key) {
case Key.CursorUp:
current--;
if (current < 0)
current = barItems.Children.Length - 1;
if (current == -1)
break;
do {
current--;
if (current < 0)
current = barItems.Children.Length - 1;
} while (barItems.Children [current] == null)
SetNeedsDisplay ();
break;
case Key.CursorDown:
current++;
if (current== barItems.Children.Length)
current = 0;
do {
current++;
if (current == barItems.Children.Length)
current = 0;
} while (barItems.Children [current] == null)
SetNeedsDisplay ();
break;
case Key.CursorLeft:
@@ -274,7 +288,7 @@ namespace Terminal.Gui {
/// <summary>
/// Initializes a new instance of the <see cref="T:Terminal.Gui.MenuBar"/> class with the specified set of toplevel menu items.
/// </summary>
/// <param name="menus">Menus.</param>
/// <param name="menus">Individual menu items, if one of those contains a null, then a separator is drawn.</param>
public MenuBar (MenuBarItem [] menus) : base ()
{
X = 0;