From 57b89099ecfe68e1ccf5c0c4530a07f9fa84e3e9 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 4 Sep 2012 00:02:50 +0200 Subject: [PATCH] Client::MenuMode wrap through options with j/k Ctrl-n/Ctrl-p and tab --- src/client.cc | 18 ++++++++++++++---- src/client.hh | 1 + src/ncurses.cc | 4 ++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/client.cc b/src/client.cc index 8576c885..c48aca25 100644 --- a/src/client.cc +++ b/src/client.cc @@ -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')) { diff --git a/src/client.hh b/src/client.hh index 61c71720..da28fc84 100644 --- a/src/client.hh +++ b/src/client.hh @@ -16,6 +16,7 @@ class Context; enum class MenuCommand { SelectFirst, + SelectLast, SelectPrev, SelectNext, SelectNone, diff --git a/src/ncurses.cc b/src/ncurses.cc index dff4b0f3..02bbe8a9 100644 --- a/src/ncurses.cc +++ b/src/ncurses.cc @@ -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);