Skip to content

Commit 9ef7de7

Browse files
OmarEmaraDevclayborg
authored andcommitted
[LLDB][GUI] Add required property to text fields
This patch adds a required property to text fields and their derivatives. Additionally, the Process Name and PID fields in the attach form were marked as required. Differential Revision: https://reviews.llvm.org/D106458
1 parent c93dc25 commit 9ef7de7

File tree

1 file changed

+42
-23
lines changed

1 file changed

+42
-23
lines changed

lldb/source/Core/IOHandlerCursesGUI.cpp

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,8 +1075,9 @@ typedef std::unique_ptr<FieldDelegate> FieldDelegateUP;
10751075

10761076
class TextFieldDelegate : public FieldDelegate {
10771077
public:
1078-
TextFieldDelegate(const char *label, const char *content)
1079-
: m_label(label), m_cursor_position(0), m_first_visibile_char(0) {
1078+
TextFieldDelegate(const char *label, const char *content, bool required)
1079+
: m_label(label), m_required(required), m_cursor_position(0),
1080+
m_first_visibile_char(0) {
10801081
if (content)
10811082
m_content = content;
10821083
}
@@ -1238,6 +1239,13 @@ class TextFieldDelegate : public FieldDelegate {
12381239
return eKeyNotHandled;
12391240
}
12401241

1242+
void FieldDelegateExitCallback() override {
1243+
if (!IsSpecified() && m_required)
1244+
SetError("This field is required!");
1245+
}
1246+
1247+
bool IsSpecified() { return !m_content.empty(); }
1248+
12411249
bool HasError() { return !m_error.empty(); }
12421250

12431251
void ClearError() { m_error.clear(); }
@@ -1250,6 +1258,7 @@ class TextFieldDelegate : public FieldDelegate {
12501258

12511259
protected:
12521260
std::string m_label;
1261+
bool m_required;
12531262
// The position of the top left corner character of the border.
12541263
std::string m_content;
12551264
// The cursor position in the content string itself. Can be in the range
@@ -1266,8 +1275,8 @@ class TextFieldDelegate : public FieldDelegate {
12661275

12671276
class IntegerFieldDelegate : public TextFieldDelegate {
12681277
public:
1269-
IntegerFieldDelegate(const char *label, int content)
1270-
: TextFieldDelegate(label, std::to_string(content).c_str()) {}
1278+
IntegerFieldDelegate(const char *label, int content, bool required)
1279+
: TextFieldDelegate(label, std::to_string(content).c_str(), required) {}
12711280

12721281
// Only accept digits.
12731282
bool IsAcceptableChar(int key) override { return isdigit(key); }
@@ -1278,13 +1287,16 @@ class IntegerFieldDelegate : public TextFieldDelegate {
12781287

12791288
class FileFieldDelegate : public TextFieldDelegate {
12801289
public:
1281-
FileFieldDelegate(const char *label, const char *content,
1282-
bool need_to_exist = true)
1283-
: TextFieldDelegate(label, content), m_need_to_exist(need_to_exist) {}
1290+
FileFieldDelegate(const char *label, const char *content, bool need_to_exist,
1291+
bool required)
1292+
: TextFieldDelegate(label, content, required),
1293+
m_need_to_exist(need_to_exist) {}
12841294

1285-
// Set appropriate error messages if the file doesn't exists or is, in fact, a
1286-
// directory.
12871295
void FieldDelegateExitCallback() override {
1296+
TextFieldDelegate::FieldDelegateExitCallback();
1297+
if (!IsSpecified())
1298+
return;
1299+
12881300
FileSpec file(GetPath());
12891301
if (m_need_to_exist && !FileSystem::Instance().Exists(file)) {
12901302
SetError("File doesn't exist!");
@@ -1306,12 +1318,15 @@ class FileFieldDelegate : public TextFieldDelegate {
13061318
class DirectoryFieldDelegate : public TextFieldDelegate {
13071319
public:
13081320
DirectoryFieldDelegate(const char *label, const char *content,
1309-
bool need_to_exist = true)
1310-
: TextFieldDelegate(label, content), m_need_to_exist(need_to_exist) {}
1321+
bool need_to_exist, bool required)
1322+
: TextFieldDelegate(label, content, required),
1323+
m_need_to_exist(need_to_exist) {}
13111324

1312-
// Set appropriate error messages if the directory doesn't exists or is, in
1313-
// fact, a file.
13141325
void FieldDelegateExitCallback() override {
1326+
TextFieldDelegate::FieldDelegateExitCallback();
1327+
if (!IsSpecified())
1328+
return;
1329+
13151330
FileSpec file(GetPath());
13161331
if (m_need_to_exist && !FileSystem::Instance().Exists(file)) {
13171332
SetError("Directory doesn't exist!");
@@ -1879,31 +1894,35 @@ class FormDelegate {
18791894

18801895
// Factory methods to create and add fields of specific types.
18811896

1882-
TextFieldDelegate *AddTextField(const char *label, const char *content) {
1883-
TextFieldDelegate *delegate = new TextFieldDelegate(label, content);
1897+
TextFieldDelegate *AddTextField(const char *label, const char *content,
1898+
bool required) {
1899+
TextFieldDelegate *delegate =
1900+
new TextFieldDelegate(label, content, required);
18841901
m_fields.push_back(FieldDelegateUP(delegate));
18851902
return delegate;
18861903
}
18871904

18881905
FileFieldDelegate *AddFileField(const char *label, const char *content,
1889-
bool need_to_exist = true) {
1906+
bool need_to_exist, bool required) {
18901907
FileFieldDelegate *delegate =
1891-
new FileFieldDelegate(label, content, need_to_exist);
1908+
new FileFieldDelegate(label, content, need_to_exist, required);
18921909
m_fields.push_back(FieldDelegateUP(delegate));
18931910
return delegate;
18941911
}
18951912

18961913
DirectoryFieldDelegate *AddDirectoryField(const char *label,
18971914
const char *content,
1898-
bool need_to_exist = true) {
1915+
bool need_to_exist, bool required) {
18991916
DirectoryFieldDelegate *delegate =
1900-
new DirectoryFieldDelegate(label, content, need_to_exist);
1917+
new DirectoryFieldDelegate(label, content, need_to_exist, required);
19011918
m_fields.push_back(FieldDelegateUP(delegate));
19021919
return delegate;
19031920
}
19041921

1905-
IntegerFieldDelegate *AddIntegerField(const char *label, int content) {
1906-
IntegerFieldDelegate *delegate = new IntegerFieldDelegate(label, content);
1922+
IntegerFieldDelegate *AddIntegerField(const char *label, int content,
1923+
bool required) {
1924+
IntegerFieldDelegate *delegate =
1925+
new IntegerFieldDelegate(label, content, required);
19071926
m_fields.push_back(FieldDelegateUP(delegate));
19081927
return delegate;
19091928
}
@@ -2368,9 +2387,9 @@ class ProcessAttachFormDelegate : public FormDelegate {
23682387
types.push_back(std::string("Name"));
23692388
types.push_back(std::string("PID"));
23702389
m_type_field = AddChoicesField("Attach By", 2, types);
2371-
m_pid_field = AddIntegerField("PID", 0);
2390+
m_pid_field = AddIntegerField("PID", 0, true);
23722391
m_name_field =
2373-
AddTextField("Process Name", GetDefaultProcessName().c_str());
2392+
AddTextField("Process Name", GetDefaultProcessName().c_str(), true);
23742393
m_continue_field = AddBooleanField("Continue once attached.", false);
23752394
m_wait_for_field = AddBooleanField("Wait for process to launch.", false);
23762395
m_include_existing_field =

0 commit comments

Comments
 (0)