Added support for disabled menu items.
The target function of an item is now called upon every action, not only if that item had a sub menu... git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8651 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -25,7 +25,7 @@ static const console_color kItemColor = SILVER;
|
|||||||
static const console_color kSelectedItemColor = WHITE;
|
static const console_color kSelectedItemColor = WHITE;
|
||||||
static const console_color kBackgroundColor = BLACK;
|
static const console_color kBackgroundColor = BLACK;
|
||||||
static const console_color kSelectedBackgroundColor = SILVER;
|
static const console_color kSelectedBackgroundColor = SILVER;
|
||||||
|
static const console_color kDisabledColor = GREY;
|
||||||
|
|
||||||
static int32 sMenuOffset = 0;
|
static int32 sMenuOffset = 0;
|
||||||
|
|
||||||
@@ -68,6 +68,9 @@ print_item_at(int32 line, MenuItem *item, bool clearHelp = true)
|
|||||||
console_color background = selected ? kSelectedBackgroundColor : kBackgroundColor;
|
console_color background = selected ? kSelectedBackgroundColor : kBackgroundColor;
|
||||||
console_color foreground = selected ? kSelectedItemColor : kItemColor;
|
console_color foreground = selected ? kSelectedItemColor : kItemColor;
|
||||||
|
|
||||||
|
if (!item->IsEnabled())
|
||||||
|
foreground = kDisabledColor;
|
||||||
|
|
||||||
console_set_cursor(kOffsetX, line + kFirstLine);
|
console_set_cursor(kOffsetX, line + kFirstLine);
|
||||||
console_set_color(foreground, background);
|
console_set_color(foreground, background);
|
||||||
|
|
||||||
@@ -276,7 +279,7 @@ run_menu(Menu *menu)
|
|||||||
switch (key.code.bios) {
|
switch (key.code.bios) {
|
||||||
case BIOS_KEY_UP:
|
case BIOS_KEY_UP:
|
||||||
while ((item = menu->ItemAt(--selected)) != NULL) {
|
while ((item = menu->ItemAt(--selected)) != NULL) {
|
||||||
if (item->Type() != MENU_ITEM_SEPARATOR)
|
if (item->IsEnabled() && item->Type() != MENU_ITEM_SEPARATOR)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (selected < 0)
|
if (selected < 0)
|
||||||
@@ -284,7 +287,7 @@ run_menu(Menu *menu)
|
|||||||
break;
|
break;
|
||||||
case BIOS_KEY_DOWN:
|
case BIOS_KEY_DOWN:
|
||||||
while ((item = menu->ItemAt(++selected)) != NULL) {
|
while ((item = menu->ItemAt(++selected)) != NULL) {
|
||||||
if (item->Type() != MENU_ITEM_SEPARATOR)
|
if (item->IsEnabled() && item->Type() != MENU_ITEM_SEPARATOR)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (selected >= menu->CountItems())
|
if (selected >= menu->CountItems())
|
||||||
@@ -294,7 +297,7 @@ run_menu(Menu *menu)
|
|||||||
selected -= menu_height() - 1;
|
selected -= menu_height() - 1;
|
||||||
|
|
||||||
while ((item = menu->ItemAt(selected)) != NULL) {
|
while ((item = menu->ItemAt(selected)) != NULL) {
|
||||||
if (item->Type() != MENU_ITEM_SEPARATOR)
|
if (item->IsEnabled() && item->Type() != MENU_ITEM_SEPARATOR)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
selected--;
|
selected--;
|
||||||
@@ -307,7 +310,7 @@ run_menu(Menu *menu)
|
|||||||
selected += menu_height() - 1;
|
selected += menu_height() - 1;
|
||||||
|
|
||||||
while ((item = menu->ItemAt(selected)) != NULL) {
|
while ((item = menu->ItemAt(selected)) != NULL) {
|
||||||
if (item->Type() != MENU_ITEM_SEPARATOR)
|
if (item->IsEnabled() && item->Type() != MENU_ITEM_SEPARATOR)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
selected++;
|
selected++;
|
||||||
@@ -359,6 +362,9 @@ run_menu(Menu *menu)
|
|||||||
// toggle state
|
// toggle state
|
||||||
item->SetMarked(!item->IsMarked());
|
item->SetMarked(!item->IsMarked());
|
||||||
print_item_at(selected, item);
|
print_item_at(selected, item);
|
||||||
|
|
||||||
|
if (item->Target() != NULL)
|
||||||
|
(*item->Target())(menu, item);
|
||||||
} else if (key.code.ascii == 0xd) {
|
} else if (key.code.ascii == 0xd) {
|
||||||
// the space key does not exit the menu
|
// the space key does not exit the menu
|
||||||
|
|
||||||
@@ -366,6 +372,10 @@ run_menu(Menu *menu)
|
|||||||
&& item->Type() != MENU_ITEM_NO_CHOICE
|
&& item->Type() != MENU_ITEM_NO_CHOICE
|
||||||
&& item->Type() != MENU_ITEM_TITLE)
|
&& item->Type() != MENU_ITEM_TITLE)
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
|
|
||||||
|
if (item->Target() != NULL)
|
||||||
|
(*item->Target())(menu, item);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (key.code.ascii == 0x1b && menu->Type() != MAIN_MENU)
|
} else if (key.code.ascii == 0x1b && menu->Type() != MAIN_MENU)
|
||||||
|
|||||||
Reference in New Issue
Block a user