cmCursesCacheEntryComposite.cxx 3.8 KB

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