OmarEmaraDev created this revision. OmarEmaraDev added a reviewer: clayborg. Herald added a reviewer: teemperor. OmarEmaraDev requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
This patch adds a new key ALt+Enter key combination to form windows. Once invoked, the first action is executed without having to navigate to its button. Field exit callbacks are now also invoked on validation to support this aforementioned key combination. One concern for this key combination is its potential use by the window manager of the host. I am not sure if this will be a problem, but it is worth putting in consideration. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D108410 Files: lldb/source/Core/IOHandlerCursesGUI.cpp Index: lldb/source/Core/IOHandlerCursesGUI.cpp =================================================================== --- lldb/source/Core/IOHandlerCursesGUI.cpp +++ lldb/source/Core/IOHandlerCursesGUI.cpp @@ -89,6 +89,7 @@ #define KEY_ESCAPE 27 #define KEY_SHIFT_TAB (KEY_MAX + 1) +#define KEY_ALT_ENTER (KEY_MAX + 2) namespace curses { class Menu; @@ -2137,6 +2138,7 @@ // action that requires valid fields. bool CheckFieldsValidity() { for (int i = 0; i < GetNumberOfFields(); i++) { + GetField(i)->FieldDelegateExitCallback(); if (GetField(i)->FieldDelegateHasError()) { SetError("Some fields are invalid!"); return false; @@ -2456,13 +2458,24 @@ Size(width, copy_height)); } + void DrawSubmitHint(Surface &surface, bool is_active) { + surface.MoveCursor(2, surface.GetHeight() - 1); + if (is_active) + surface.AttributeOn(A_BOLD | COLOR_PAIR(BlackOnWhite)); + surface.Printf("[Press Alt+Enter to %s]", + m_delegate_sp->GetAction(0).GetLabel().c_str()); + if (is_active) + surface.AttributeOff(A_BOLD | COLOR_PAIR(BlackOnWhite)); + } + bool WindowDelegateDraw(Window &window, bool force) override { m_delegate_sp->UpdateFieldsVisibility(); window.Erase(); window.DrawTitleBox(m_delegate_sp->GetName().c_str(), - "Press Esc to cancel"); + "Press Esc to Cancel"); + DrawSubmitHint(window, window.IsActive()); Rect content_bounds = window.GetFrame(); content_bounds.Inset(2, 2); @@ -2585,8 +2598,8 @@ return eKeyHandled; } - void ExecuteAction(Window &window) { - FormAction &action = m_delegate_sp->GetAction(m_selection_index); + void ExecuteAction(Window &window, int index) { + FormAction &action = m_delegate_sp->GetAction(index); action.Execute(window); if (m_delegate_sp->HasError()) { m_first_visible_line = 0; @@ -2601,10 +2614,13 @@ case '\n': case KEY_ENTER: if (m_selection_type == SelectionType::Action) { - ExecuteAction(window); + ExecuteAction(window, m_selection_index); return eKeyHandled; } break; + case KEY_ALT_ENTER: + ExecuteAction(window, 0); + return eKeyHandled; case '\t': return SelectNext(key); case KEY_SHIFT_TAB: @@ -6863,6 +6879,7 @@ static_assert(LastColorPairIndex == 18, "Color indexes do not match."); define_key("\033[Z", KEY_SHIFT_TAB); + define_key("\033\015", KEY_ALT_ENTER); } }
Index: lldb/source/Core/IOHandlerCursesGUI.cpp =================================================================== --- lldb/source/Core/IOHandlerCursesGUI.cpp +++ lldb/source/Core/IOHandlerCursesGUI.cpp @@ -89,6 +89,7 @@ #define KEY_ESCAPE 27 #define KEY_SHIFT_TAB (KEY_MAX + 1) +#define KEY_ALT_ENTER (KEY_MAX + 2) namespace curses { class Menu; @@ -2137,6 +2138,7 @@ // action that requires valid fields. bool CheckFieldsValidity() { for (int i = 0; i < GetNumberOfFields(); i++) { + GetField(i)->FieldDelegateExitCallback(); if (GetField(i)->FieldDelegateHasError()) { SetError("Some fields are invalid!"); return false; @@ -2456,13 +2458,24 @@ Size(width, copy_height)); } + void DrawSubmitHint(Surface &surface, bool is_active) { + surface.MoveCursor(2, surface.GetHeight() - 1); + if (is_active) + surface.AttributeOn(A_BOLD | COLOR_PAIR(BlackOnWhite)); + surface.Printf("[Press Alt+Enter to %s]", + m_delegate_sp->GetAction(0).GetLabel().c_str()); + if (is_active) + surface.AttributeOff(A_BOLD | COLOR_PAIR(BlackOnWhite)); + } + bool WindowDelegateDraw(Window &window, bool force) override { m_delegate_sp->UpdateFieldsVisibility(); window.Erase(); window.DrawTitleBox(m_delegate_sp->GetName().c_str(), - "Press Esc to cancel"); + "Press Esc to Cancel"); + DrawSubmitHint(window, window.IsActive()); Rect content_bounds = window.GetFrame(); content_bounds.Inset(2, 2); @@ -2585,8 +2598,8 @@ return eKeyHandled; } - void ExecuteAction(Window &window) { - FormAction &action = m_delegate_sp->GetAction(m_selection_index); + void ExecuteAction(Window &window, int index) { + FormAction &action = m_delegate_sp->GetAction(index); action.Execute(window); if (m_delegate_sp->HasError()) { m_first_visible_line = 0; @@ -2601,10 +2614,13 @@ case '\n': case KEY_ENTER: if (m_selection_type == SelectionType::Action) { - ExecuteAction(window); + ExecuteAction(window, m_selection_index); return eKeyHandled; } break; + case KEY_ALT_ENTER: + ExecuteAction(window, 0); + return eKeyHandled; case '\t': return SelectNext(key); case KEY_SHIFT_TAB: @@ -6863,6 +6879,7 @@ static_assert(LastColorPairIndex == 18, "Color indexes do not match."); define_key("\033[Z", KEY_SHIFT_TAB); + define_key("\033\015", KEY_ALT_ENTER); } }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits