cmCursesCacheEntryComposite.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 <cassert>
  5. #include <utility>
  6. #include <vector>
  7. #include <cm/memory>
  8. #include "cmCursesBoolWidget.h"
  9. #include "cmCursesFilePathWidget.h"
  10. #include "cmCursesLabelWidget.h"
  11. #include "cmCursesOptionsWidget.h"
  12. #include "cmCursesPathWidget.h"
  13. #include "cmCursesStringWidget.h"
  14. #include "cmCursesWidget.h"
  15. #include "cmList.h"
  16. #include "cmState.h"
  17. #include "cmStateTypes.h"
  18. #include "cmSystemTools.h"
  19. #include "cmValue.h"
  20. cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
  21. const std::string& key, int labelwidth, int entrywidth)
  22. : Key(key)
  23. , LabelWidth(labelwidth)
  24. , EntryWidth(entrywidth)
  25. {
  26. this->Label =
  27. cm::make_unique<cmCursesLabelWidget>(this->LabelWidth, 1, 1, 1, key);
  28. this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, " ");
  29. this->Entry =
  30. cm::make_unique<cmCursesStringWidget>(this->EntryWidth, 1, 1, 1);
  31. }
  32. cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
  33. const std::string& key, cmState* state, bool isNew, int labelwidth,
  34. int entrywidth)
  35. : Key(key)
  36. , LabelWidth(labelwidth)
  37. , EntryWidth(entrywidth)
  38. {
  39. this->Label =
  40. cm::make_unique<cmCursesLabelWidget>(this->LabelWidth, 1, 1, 1, key);
  41. if (isNew) {
  42. this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, "*");
  43. } else {
  44. this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, " ");
  45. }
  46. cmValue value = state->GetCacheEntryValue(key);
  47. assert(value);
  48. switch (state->GetCacheEntryType(key)) {
  49. case cmStateEnums::BOOL: {
  50. auto bw = cm::make_unique<cmCursesBoolWidget>(this->EntryWidth, 1, 1, 1);
  51. bw->SetValueAsBool(cmIsOn(*value));
  52. this->Entry = std::move(bw);
  53. break;
  54. }
  55. case cmStateEnums::PATH: {
  56. auto pw = cm::make_unique<cmCursesPathWidget>(this->EntryWidth, 1, 1, 1);
  57. pw->SetString(*value);
  58. this->Entry = std::move(pw);
  59. break;
  60. }
  61. case cmStateEnums::FILEPATH: {
  62. auto fpw =
  63. cm::make_unique<cmCursesFilePathWidget>(this->EntryWidth, 1, 1, 1);
  64. fpw->SetString(*value);
  65. this->Entry = std::move(fpw);
  66. break;
  67. }
  68. case cmStateEnums::STRING: {
  69. cmValue stringsProp = state->GetCacheEntryProperty(key, "STRINGS");
  70. if (stringsProp) {
  71. auto ow =
  72. cm::make_unique<cmCursesOptionsWidget>(this->EntryWidth, 1, 1, 1);
  73. for (auto const& opt : cmList{ *stringsProp }) {
  74. ow->AddOption(opt);
  75. }
  76. ow->SetOption(*value);
  77. this->Entry = std::move(ow);
  78. } else {
  79. auto sw =
  80. cm::make_unique<cmCursesStringWidget>(this->EntryWidth, 1, 1, 1);
  81. sw->SetString(*value);
  82. this->Entry = std::move(sw);
  83. }
  84. break;
  85. }
  86. case cmStateEnums::UNINITIALIZED:
  87. cmSystemTools::Error("Found an undefined variable: " + key);
  88. break;
  89. default:
  90. // TODO : put warning message here
  91. break;
  92. }
  93. }
  94. cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite() = default;
  95. const char* cmCursesCacheEntryComposite::GetValue()
  96. {
  97. if (this->Label) {
  98. return this->Label->GetValue();
  99. }
  100. return nullptr;
  101. }