@@ -1075,8 +1075,9 @@ typedef std::unique_ptr<FieldDelegate> FieldDelegateUP;
1075
1075
1076
1076
class TextFieldDelegate : public FieldDelegate {
1077
1077
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 ) {
1080
1081
if (content)
1081
1082
m_content = content;
1082
1083
}
@@ -1238,6 +1239,13 @@ class TextFieldDelegate : public FieldDelegate {
1238
1239
return eKeyNotHandled;
1239
1240
}
1240
1241
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
+
1241
1249
bool HasError () { return !m_error.empty (); }
1242
1250
1243
1251
void ClearError () { m_error.clear (); }
@@ -1250,6 +1258,7 @@ class TextFieldDelegate : public FieldDelegate {
1250
1258
1251
1259
protected:
1252
1260
std::string m_label;
1261
+ bool m_required;
1253
1262
// The position of the top left corner character of the border.
1254
1263
std::string m_content;
1255
1264
// The cursor position in the content string itself. Can be in the range
@@ -1266,8 +1275,8 @@ class TextFieldDelegate : public FieldDelegate {
1266
1275
1267
1276
class IntegerFieldDelegate : public TextFieldDelegate {
1268
1277
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 ) {}
1271
1280
1272
1281
// Only accept digits.
1273
1282
bool IsAcceptableChar (int key) override { return isdigit (key); }
@@ -1278,13 +1287,16 @@ class IntegerFieldDelegate : public TextFieldDelegate {
1278
1287
1279
1288
class FileFieldDelegate : public TextFieldDelegate {
1280
1289
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) {}
1284
1294
1285
- // Set appropriate error messages if the file doesn't exists or is, in fact, a
1286
- // directory.
1287
1295
void FieldDelegateExitCallback () override {
1296
+ TextFieldDelegate::FieldDelegateExitCallback ();
1297
+ if (!IsSpecified ())
1298
+ return ;
1299
+
1288
1300
FileSpec file (GetPath ());
1289
1301
if (m_need_to_exist && !FileSystem::Instance ().Exists (file)) {
1290
1302
SetError (" File doesn't exist!" );
@@ -1306,12 +1318,15 @@ class FileFieldDelegate : public TextFieldDelegate {
1306
1318
class DirectoryFieldDelegate : public TextFieldDelegate {
1307
1319
public:
1308
1320
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) {}
1311
1324
1312
- // Set appropriate error messages if the directory doesn't exists or is, in
1313
- // fact, a file.
1314
1325
void FieldDelegateExitCallback () override {
1326
+ TextFieldDelegate::FieldDelegateExitCallback ();
1327
+ if (!IsSpecified ())
1328
+ return ;
1329
+
1315
1330
FileSpec file (GetPath ());
1316
1331
if (m_need_to_exist && !FileSystem::Instance ().Exists (file)) {
1317
1332
SetError (" Directory doesn't exist!" );
@@ -1879,31 +1894,35 @@ class FormDelegate {
1879
1894
1880
1895
// Factory methods to create and add fields of specific types.
1881
1896
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);
1884
1901
m_fields.push_back (FieldDelegateUP (delegate));
1885
1902
return delegate;
1886
1903
}
1887
1904
1888
1905
FileFieldDelegate *AddFileField (const char *label, const char *content,
1889
- bool need_to_exist = true ) {
1906
+ bool need_to_exist, bool required ) {
1890
1907
FileFieldDelegate *delegate =
1891
- new FileFieldDelegate (label, content, need_to_exist);
1908
+ new FileFieldDelegate (label, content, need_to_exist, required );
1892
1909
m_fields.push_back (FieldDelegateUP (delegate));
1893
1910
return delegate;
1894
1911
}
1895
1912
1896
1913
DirectoryFieldDelegate *AddDirectoryField (const char *label,
1897
1914
const char *content,
1898
- bool need_to_exist = true ) {
1915
+ bool need_to_exist, bool required ) {
1899
1916
DirectoryFieldDelegate *delegate =
1900
- new DirectoryFieldDelegate (label, content, need_to_exist);
1917
+ new DirectoryFieldDelegate (label, content, need_to_exist, required );
1901
1918
m_fields.push_back (FieldDelegateUP (delegate));
1902
1919
return delegate;
1903
1920
}
1904
1921
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);
1907
1926
m_fields.push_back (FieldDelegateUP (delegate));
1908
1927
return delegate;
1909
1928
}
@@ -2368,9 +2387,9 @@ class ProcessAttachFormDelegate : public FormDelegate {
2368
2387
types.push_back (std::string (" Name" ));
2369
2388
types.push_back (std::string (" PID" ));
2370
2389
m_type_field = AddChoicesField (" Attach By" , 2 , types);
2371
- m_pid_field = AddIntegerField (" PID" , 0 );
2390
+ m_pid_field = AddIntegerField (" PID" , 0 , true );
2372
2391
m_name_field =
2373
- AddTextField (" Process Name" , GetDefaultProcessName ().c_str ());
2392
+ AddTextField (" Process Name" , GetDefaultProcessName ().c_str (), true );
2374
2393
m_continue_field = AddBooleanField (" Continue once attached." , false );
2375
2394
m_wait_for_field = AddBooleanField (" Wait for process to launch." , false );
2376
2395
m_include_existing_field =
0 commit comments