[Lldb-commits] [PATCH] D106459: [LLDB][GUI] Check fields validity in actions

Omar Emara via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Jul 21 10:01:09 PDT 2021


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 virtual method HasError to fields, it can be
overridden by fields that have errors. Additionally, a form method
CheckFieldsValidity was added to be called by actions that expects all
the field to be valid.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106459

Files:
  lldb/source/Core/IOHandlerCursesGUI.cpp


Index: lldb/source/Core/IOHandlerCursesGUI.cpp
===================================================================
--- lldb/source/Core/IOHandlerCursesGUI.cpp
+++ lldb/source/Core/IOHandlerCursesGUI.cpp
@@ -1061,6 +1061,9 @@
   // Select the last element in the field if multiple elements exists.
   virtual void FieldDelegateSelectLastElement() { return; }
 
+  // Returns true if the field has an error, false otherwise.
+  virtual bool FieldDelegateHasError() { return false; }
+
   bool FieldDelegateIsVisible() { return m_is_visible; }
 
   void FieldDelegateHide() { m_is_visible = false; }
@@ -1097,7 +1100,7 @@
   // field and an optional line for an error if it exists.
   int FieldDelegateGetHeight() override {
     int height = GetFieldHeight();
-    if (HasError())
+    if (FieldDelegateHasError())
       height++;
     return height;
   }
@@ -1137,7 +1140,7 @@
   }
 
   void DrawError(SubPad &surface) {
-    if (!HasError())
+    if (!FieldDelegateHasError())
       return;
     surface.MoveCursor(0, 0);
     surface.AttributeOn(COLOR_PAIR(RedOnBlack));
@@ -1238,7 +1241,7 @@
     return eKeyNotHandled;
   }
 
-  bool HasError() { return !m_error.empty(); }
+  bool FieldDelegateHasError() override { return !m_error.empty(); }
 
   void ClearError() { m_error.clear(); }
 
@@ -1854,6 +1857,19 @@
 
   void SetError(const char *error) { m_error = error; }
 
+  // If all fields are valid, true is returned. Otherwise, an error message is
+  // set and false is returned. This method is usually called at the start of an
+  // action that requires valid fields.
+  bool CheckFieldsValidity() {
+    for (int i = 0; i < GetNumberOfFields(); i++) {
+      if (GetField(i)->FieldDelegateHasError()) {
+        SetError("Some fields are invalid!");
+        return false;
+      }
+    }
+    return true;
+  }
+
   // Factory methods to create and add fields of specific types.
 
   TextFieldDelegate *AddTextField(const char *label, const char *content) {
@@ -2464,6 +2480,10 @@
   void Attach(Window &window) {
     ClearError();
 
+    bool all_fields_are_valid = CheckFieldsValidity();
+    if (!all_fields_are_valid)
+      return;
+
     bool process_is_running = StopRunningProcess();
     if (process_is_running)
       return;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106459.360503.patch
Type: text/x-patch
Size: 2253 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210721/c86dfa68/attachment.bin>


More information about the lldb-commits mailing list