Client::MenuMode wrap through options with j/k Ctrl-n/Ctrl-p and tab

This commit is contained in:
Maxime Coste 2012-09-04 00:02:50 +02:00
parent c4dd6b4038
commit 57b89099ec
3 changed files with 19 additions and 4 deletions

View File

@ -64,14 +64,24 @@ public:
key == Key(Key::Modifiers::Control, 'i') or
key == Key(Key::Modifiers::None, 'j'))
{
m_client.menu_ctrl(MenuCommand::SelectNext);
m_selected = std::min(m_selected+1, m_choice_count-1);
if (++m_selected >= m_choice_count)
{
m_client.menu_ctrl(MenuCommand::SelectFirst);
m_selected = 0;
}
else
m_client.menu_ctrl(MenuCommand::SelectNext);
}
if (key == Key(Key::Modifiers::Control, 'p') or
key == Key(Key::Modifiers::None, 'k'))
{
m_client.menu_ctrl(MenuCommand::SelectPrev);
m_selected = std::max(m_selected-1, 0);
if (--m_selected < 0)
{
m_client.menu_ctrl(MenuCommand::SelectLast);
m_selected = m_choice_count-1;
}
else
m_client.menu_ctrl(MenuCommand::SelectPrev);
}
if (key == Key(Key::Modifiers::Control, 'm'))
{

View File

@ -16,6 +16,7 @@ class Context;
enum class MenuCommand
{
SelectFirst,
SelectLast,
SelectPrev,
SelectNext,
SelectNone,

View File

@ -243,6 +243,10 @@ void NCursesClient::menu_ctrl(MenuCommand command)
set_menu_fore(m_menu, A_STANDOUT);
menu_driver(m_menu, REQ_FIRST_ITEM);
break;
case MenuCommand::SelectLast:
set_menu_fore(m_menu, A_STANDOUT);
menu_driver(m_menu, REQ_LAST_ITEM);
break;
case MenuCommand::SelectNext:
set_menu_fore(m_menu, A_STANDOUT);
menu_driver(m_menu, REQ_NEXT_ITEM);