cmCursesCacheEntryComposite.cxx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 (auto const& opt : options) {
  71. ow->AddOption(opt);
  72. }
  73. ow->SetOption(value);
  74. } else {
  75. this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
  76. static_cast<cmCursesStringWidget*>(this->Entry)->SetString(value);
  77. }
  78. break;
  79. }
  80. case cmStateEnums::UNINITIALIZED:
  81. cmSystemTools::Error("Found an undefined variable: ", key.c_str());
  82. break;
  83. default:
  84. // TODO : put warning message here
  85. break;
  86. }
  87. }
  88. cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite()
  89. {
  90. delete this->Label;
  91. delete this->IsNewLabel;
  92. delete this->Entry;
  93. }
  94. const char* cmCursesCacheEntryComposite::GetValue()
  95. {
  96. if (this->Label) {
  97. return this->Label->GetValue();
  98. }
  99. return nullptr;
  100. }