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 "cmStringAlgorithms.h"
  14. #include "cmSystemTools.h"
  15. #include "cmake.h"
  16. #include <assert.h>
  17. #include <vector>
  18. cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
  19. const std::string& key, int labelwidth, int entrywidth)
  20. : Key(key)
  21. , LabelWidth(labelwidth)
  22. , EntryWidth(entrywidth)
  23. {
  24. this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
  25. this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
  26. this->Entry = nullptr;
  27. this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
  28. }
  29. cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
  30. const std::string& key, cmake* cm, bool isNew, int labelwidth,
  31. int entrywidth)
  32. : Key(key)
  33. , LabelWidth(labelwidth)
  34. , EntryWidth(entrywidth)
  35. {
  36. this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
  37. if (isNew) {
  38. this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, "*");
  39. } else {
  40. this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
  41. }
  42. this->Entry = nullptr;
  43. const char* value = cm->GetState()->GetCacheEntryValue(key);
  44. assert(value);
  45. switch (cm->GetState()->GetCacheEntryType(key)) {
  46. case cmStateEnums::BOOL:
  47. this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1);
  48. if (cmSystemTools::IsOn(value)) {
  49. static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true);
  50. } else {
  51. static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(false);
  52. }
  53. break;
  54. case cmStateEnums::PATH:
  55. this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1);
  56. static_cast<cmCursesPathWidget*>(this->Entry)->SetString(value);
  57. break;
  58. case cmStateEnums::FILEPATH:
  59. this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1);
  60. static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(value);
  61. break;
  62. case cmStateEnums::STRING: {
  63. const char* stringsProp =
  64. cm->GetState()->GetCacheEntryProperty(key, "STRINGS");
  65. if (stringsProp) {
  66. cmCursesOptionsWidget* ow =
  67. new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1);
  68. this->Entry = ow;
  69. std::vector<std::string> options;
  70. cmExpandList(stringsProp, options);
  71. for (auto const& opt : options) {
  72. ow->AddOption(opt);
  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);
  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. }