cmCursesCacheEntryComposite.cxx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCursesCacheEntryComposite.h"
  4. #include "cmCursesBoolWidget.h"
  5. #include "cmCursesFilePathWidget.h"
  6. #include "cmCursesLabelWidget.h"
  7. #include "cmCursesOptionsWidget.h"
  8. #include "cmCursesPathWidget.h"
  9. #include "cmCursesStringWidget.h"
  10. #include "cmCursesWidget.h"
  11. #include "cmState.h"
  12. #include "cmStateTypes.h"
  13. #include "cmSystemTools.h"
  14. #include "cmake.h"
  15. #include <assert.h>
  16. #include <vector>
  17. cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
  18. const std::string& key, int labelwidth, int entrywidth)
  19. : Key(key)
  20. , LabelWidth(labelwidth)
  21. , EntryWidth(entrywidth)
  22. {
  23. this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
  24. this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
  25. this->Entry = nullptr;
  26. this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
  27. }
  28. cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
  29. const std::string& key, cmake* cm, bool isNew, int labelwidth,
  30. int entrywidth)
  31. : Key(key)
  32. , LabelWidth(labelwidth)
  33. , EntryWidth(entrywidth)
  34. {
  35. this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
  36. if (isNew) {
  37. this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, "*");
  38. } else {
  39. this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
  40. }
  41. this->Entry = nullptr;
  42. const char* value = cm->GetState()->GetCacheEntryValue(key);
  43. assert(value);
  44. switch (cm->GetState()->GetCacheEntryType(key)) {
  45. case cmStateEnums::BOOL:
  46. this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1);
  47. if (cmSystemTools::IsOn(value)) {
  48. static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true);
  49. } else {
  50. static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(false);
  51. }
  52. break;
  53. case cmStateEnums::PATH:
  54. this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1);
  55. static_cast<cmCursesPathWidget*>(this->Entry)->SetString(value);
  56. break;
  57. case cmStateEnums::FILEPATH:
  58. this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1);
  59. static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(value);
  60. break;
  61. case cmStateEnums::STRING: {
  62. const char* stringsProp =
  63. cm->GetState()->GetCacheEntryProperty(key, "STRINGS");
  64. if (stringsProp) {
  65. cmCursesOptionsWidget* ow =
  66. new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1);
  67. this->Entry = ow;
  68. std::vector<std::string> options;
  69. cmSystemTools::ExpandListArgument(stringsProp, options);
  70. for (std::vector<std::string>::iterator si = options.begin();
  71. si != options.end(); ++si) {
  72. ow->AddOption(*si);
  73. }
  74. ow->SetOption(value);
  75. } else {
  76. this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
  77. static_cast<cmCursesStringWidget*>(this->Entry)->SetString(value);
  78. }
  79. break;
  80. }
  81. case cmStateEnums::UNINITIALIZED:
  82. cmSystemTools::Error("Found an undefined variable: ", key.c_str());
  83. break;
  84. default:
  85. // TODO : put warning message here
  86. break;
  87. }
  88. }
  89. cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite()
  90. {
  91. delete this->Label;
  92. delete this->IsNewLabel;
  93. delete this->Entry;
  94. }
  95. const char* cmCursesCacheEntryComposite::GetValue()
  96. {
  97. if (this->Label) {
  98. return this->Label->GetValue();
  99. }
  100. return nullptr;
  101. }