Author: Omar Emara Date: 2021-07-23T18:00:10-07:00 New Revision: e160b3987e734ba834cbd985315765ea7f468680
URL: https://github.com/llvm/llvm-project/commit/e160b3987e734ba834cbd985315765ea7f468680 DIFF: https://github.com/llvm/llvm-project/commit/e160b3987e734ba834cbd985315765ea7f468680.diff LOG: [LLDB][GUI] Add Platform Plugin Field This patch adds a new Platform Plugin Field. It is a choices field that lists all the available platform plugins and can retrieve the name of the selected plugin. The default selected plugin is the currently selected one. This patch also allows for arbitrary scrolling to make scrolling easier when setting choices. Differential Revision: https://reviews.llvm.org/D106483 Added: Modified: lldb/source/Core/IOHandlerCursesGUI.cpp Removed: ################################################################################ diff --git a/lldb/source/Core/IOHandlerCursesGUI.cpp b/lldb/source/Core/IOHandlerCursesGUI.cpp index 98ef6bd3d4763..9b2cbb8fca7ca 100644 --- a/lldb/source/Core/IOHandlerCursesGUI.cpp +++ b/lldb/source/Core/IOHandlerCursesGUI.cpp @@ -1454,6 +1454,8 @@ class ChoicesFieldDelegate : public FieldDelegate { } void FieldDelegateDraw(SubPad &surface, bool is_selected) override { + UpdateScrolling(); + surface.TitledBox(m_label.c_str()); Rect content_bounds = surface.GetFrame(); @@ -1473,29 +1475,23 @@ class ChoicesFieldDelegate : public FieldDelegate { m_choice++; } - // If the cursor moved past the first visible choice, scroll up by one - // choice. - void ScrollUpIfNeeded() { - if (m_choice < m_first_visibile_choice) - m_first_visibile_choice--; - } + void UpdateScrolling() { + if (m_choice > GetLastVisibleChoice()) { + m_first_visibile_choice = m_choice - (m_number_of_visible_choices - 1); + return; + } - // If the cursor moved past the last visible choice, scroll down by one - // choice. - void ScrollDownIfNeeded() { - if (m_choice > GetLastVisibleChoice()) - m_first_visibile_choice++; + if (m_choice < m_first_visibile_choice) + m_first_visibile_choice = m_choice; } HandleCharResult FieldDelegateHandleChar(int key) override { switch (key) { case KEY_UP: SelectPrevious(); - ScrollUpIfNeeded(); return eKeyHandled; case KEY_DOWN: SelectNext(); - ScrollDownIfNeeded(); return eKeyHandled; default: break; @@ -1509,6 +1505,15 @@ class ChoicesFieldDelegate : public FieldDelegate { // Returns the index of the choice. int GetChoice() { return m_choice; } + void SetChoice(const std::string &choice) { + for (int i = 0; i < GetNumberOfChoices(); i++) { + if (choice == m_choices[i]) { + m_choice = i; + return; + } + } + } + protected: std::string m_label; int m_number_of_visible_choices; @@ -1519,6 +1524,29 @@ class ChoicesFieldDelegate : public FieldDelegate { int m_first_visibile_choice; }; +class PlatformPluginFieldDelegate : public ChoicesFieldDelegate { +public: + PlatformPluginFieldDelegate(Debugger &debugger) + : ChoicesFieldDelegate("Platform Plugin", 3, GetPossiblePluginNames()) { + PlatformSP platform_sp = debugger.GetPlatformList().GetSelectedPlatform(); + if (platform_sp) + SetChoice(platform_sp->GetName().AsCString()); + } + + std::vector<std::string> GetPossiblePluginNames() { + std::vector<std::string> names; + size_t i = 0; + while (auto name = PluginManager::GetPlatformPluginNameAtIndex(i++)) + names.push_back(name); + return names; + } + + std::string GetPluginName() { + std::string plugin_name = GetChoiceContent(); + return plugin_name; + } +}; + class ProcessPluginFieldDelegate : public ChoicesFieldDelegate { public: ProcessPluginFieldDelegate() @@ -1941,6 +1969,13 @@ class FormDelegate { return delegate; } + PlatformPluginFieldDelegate *AddPlatformPluginField(Debugger &debugger) { + PlatformPluginFieldDelegate *delegate = + new PlatformPluginFieldDelegate(debugger); + m_fields.push_back(FieldDelegateUP(delegate)); + return delegate; + } + ProcessPluginFieldDelegate *AddProcessPluginField() { ProcessPluginFieldDelegate *delegate = new ProcessPluginFieldDelegate(); m_fields.push_back(FieldDelegateUP(delegate)); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits