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