Author: Omar Emara Date: 2021-08-23T22:07:04-07:00 New Revision: 945cde8b6a4579406886d08f803b632e00f0b1ec
URL: https://github.com/llvm/llvm-project/commit/945cde8b6a4579406886d08f803b632e00f0b1ec DIFF: https://github.com/llvm/llvm-project/commit/945cde8b6a4579406886d08f803b632e00f0b1ec.diff LOG: [LLDB][GUI] Add submit form key combination 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. Differential Revision: https://reviews.llvm.org/D108410 Added: Modified: lldb/source/Core/IOHandlerCursesGUI.cpp Removed: ################################################################################ diff --git a/lldb/source/Core/IOHandlerCursesGUI.cpp b/lldb/source/Core/IOHandlerCursesGUI.cpp index 1539175fb60ec..ca06a332e4edd 100644 --- a/lldb/source/Core/IOHandlerCursesGUI.cpp +++ b/lldb/source/Core/IOHandlerCursesGUI.cpp @@ -93,6 +93,7 @@ using llvm::StringRef; #define KEY_DELETE 127 #define KEY_SHIFT_TAB (KEY_MAX + 1) +#define KEY_ALT_ENTER (KEY_MAX + 2) namespace curses { class Menu; @@ -2315,6 +2316,7 @@ class FormDelegate { // 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; @@ -2649,13 +2651,24 @@ class FormWindowDelegate : public WindowDelegate { 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); @@ -2778,8 +2791,8 @@ class FormWindowDelegate : public WindowDelegate { 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; @@ -2794,10 +2807,13 @@ class FormWindowDelegate : public WindowDelegate { 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: @@ -7458,6 +7474,7 @@ void IOHandlerCursesGUI::Activate() { 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