diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-12-14 19:38:11 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-12-14 19:38:11 +0100 |
| commit | d208067589b93b8e264699b1d6dd14aeb8022837 (patch) | |
| tree | 2d519e5f969c5b5fefc55341c5eb386c9d58fbbd /src/input_handler.cc | |
| parent | 3184159572e2d336d5a61393f9fb939f684678af (diff) | |
InputHandler: call callback on abort and on selected element change as well
Diffstat (limited to 'src/input_handler.cc')
| -rw-r--r-- | src/input_handler.cc | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc index ec461845..d3cd8460 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -152,7 +152,7 @@ public: context.ui().print_status(""); reset_normal_mode(); int selected = m_selected - m_choices.begin(); - m_callback(selected, context); + m_callback(selected, MenuEvent::Validate, context); return; } else if (key == Key::Escape or key == Key{ Key::Modifiers::Control, 'c' }) @@ -168,6 +168,8 @@ public: { context.ui().menu_hide(); reset_normal_mode(); + int selected = m_selected - m_choices.begin(); + m_callback(selected, MenuEvent::Abort, context); } } else if (key == Key::Down or @@ -178,8 +180,7 @@ public: auto it = std::find_if(m_selected+1, m_choices.end(), match_filter); if (it == m_choices.end()) it = std::find_if(m_choices.begin(), m_selected, match_filter); - m_selected = it; - context.ui().menu_select(m_selected - m_choices.begin()); + select(it, context); } else if (key == Key::Up or key == Key::BackTab or @@ -190,8 +191,7 @@ public: auto it = std::find_if(selected+1, m_choices.rend(), match_filter); if (it == m_choices.rend()) it = std::find_if(m_choices.rbegin(), selected, match_filter); - m_selected = it.base()-1; - context.ui().menu_select(m_selected - m_choices.begin()); + select(it.base()-1, context); } else if (key == '/' and not m_edit_filter) { @@ -206,8 +206,7 @@ public: auto it = std::find_if(m_selected, m_choices.end(), match_filter); if (it == m_choices.end()) it = std::find_if(m_choices.begin(), m_selected, match_filter); - m_selected = it; - context.ui().menu_select(m_selected - m_choices.begin()); + select(it, context); } if (m_edit_filter) @@ -222,6 +221,14 @@ private: const ChoiceList m_choices; ChoiceList::const_iterator m_selected; + void select(ChoiceList::const_iterator it, Context& context) + { + m_selected = it; + int selected = m_selected - m_choices.begin(); + context.ui().menu_select(selected); + m_callback(selected, MenuEvent::Select, context); + } + boost::regex m_filter = boost::regex(".*"); bool m_edit_filter = false; LineEditor m_filter_editor; |
