Add MenuCommand::SelectNone and use it when tab completions goes back to original string

This commit is contained in:
Maxime Coste 2012-09-03 19:34:10 +02:00
parent c2a4f68899
commit c61f9cbe6b
3 changed files with 12 additions and 1 deletions

View File

@ -218,7 +218,10 @@ public:
{ {
if (m_current_completion == m_completions.candidates.size() and if (m_current_completion == m_completions.candidates.size() and
std::find(m_completions.candidates.begin(), m_completions.candidates.end(), m_text_before_completion) == m_completions.candidates.end()) std::find(m_completions.candidates.begin(), m_completions.candidates.end(), m_text_before_completion) == m_completions.candidates.end())
{
completion = m_text_before_completion; completion = m_text_before_completion;
m_client.menu_ctrl(MenuCommand::SelectNone);
}
else else
{ {
m_current_completion = 0; m_current_completion = 0;

View File

@ -18,6 +18,7 @@ enum class MenuCommand
SelectFirst, SelectFirst,
SelectPrev, SelectPrev,
SelectNext, SelectNext,
SelectNone,
Close, Close,
}; };

View File

@ -217,7 +217,7 @@ void NCursesClient::show_menu(const memoryview<String>& choices)
m_items.push_back(new_item(m_counts[i].c_str(), m_choices[i].c_str())); m_items.push_back(new_item(m_counts[i].c_str(), m_choices[i].c_str()));
longest = std::max(longest, m_choices[i].length()); longest = std::max(longest, m_choices[i].length());
} }
m_items.push_back(NULL); m_items.push_back(nullptr);
longest += m_counts.back().length() + 2; longest += m_counts.back().length() + 2;
int max_x,max_y; int max_x,max_y;
@ -230,6 +230,7 @@ void NCursesClient::show_menu(const memoryview<String>& choices)
int pos_y = max_y - lines - 1; int pos_y = max_y - lines - 1;
set_menu_sub(m_menu, derwin(stdscr, max_y - pos_y - 1, max_x, pos_y, 0)); set_menu_sub(m_menu, derwin(stdscr, max_y - pos_y - 1, max_x, pos_y, 0));
set_menu_format(m_menu, lines, columns); set_menu_format(m_menu, lines, columns);
set_menu_mark(m_menu, nullptr);
post_menu(m_menu); post_menu(m_menu);
refresh(); refresh();
} }
@ -239,14 +240,20 @@ void NCursesClient::menu_ctrl(MenuCommand command)
switch(command) switch(command)
{ {
case MenuCommand::SelectFirst: case MenuCommand::SelectFirst:
set_menu_fore(m_menu, A_STANDOUT);
menu_driver(m_menu, REQ_FIRST_ITEM); menu_driver(m_menu, REQ_FIRST_ITEM);
break; break;
case MenuCommand::SelectNext: case MenuCommand::SelectNext:
set_menu_fore(m_menu, A_STANDOUT);
menu_driver(m_menu, REQ_NEXT_ITEM); menu_driver(m_menu, REQ_NEXT_ITEM);
break; break;
case MenuCommand::SelectPrev: case MenuCommand::SelectPrev:
set_menu_fore(m_menu, A_STANDOUT);
menu_driver(m_menu, REQ_PREV_ITEM); menu_driver(m_menu, REQ_PREV_ITEM);
break; break;
case MenuCommand::SelectNone:
set_menu_fore(m_menu, A_NORMAL);
break;
case MenuCommand::Close: case MenuCommand::Close:
{ {
if (not m_menu) if (not m_menu)