cmCursesCacheEntryComposite.cxx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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,
  24. int labelwidth,
  25. int entrywidth) :
  26. Key(key), LabelWidth(labelwidth), 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 = 0;
  31. this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
  32. }
  33. cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
  34. const std::string& key, cmake *cm, bool isNew,
  35. int labelwidth, int entrywidth)
  36. : Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth)
  37. {
  38. this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
  39. if (isNew)
  40. {
  41. this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, "*");
  42. }
  43. else
  44. {
  45. this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
  46. }
  47. this->Entry = 0;
  48. const char* value = cm->GetState()->GetCacheEntryValue(key);
  49. assert(value);
  50. switch (cm->GetState()->GetCacheEntryType(key))
  51. {
  52. case cmState::BOOL:
  53. this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1);
  54. if (cmSystemTools::IsOn(value))
  55. {
  56. static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true);
  57. }
  58. else
  59. {
  60. static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(false);
  61. }
  62. break;
  63. case cmState::PATH:
  64. this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1);
  65. static_cast<cmCursesPathWidget*>(this->Entry)->SetString(value);
  66. break;
  67. case cmState::FILEPATH:
  68. this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1);
  69. static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(value);
  70. break;
  71. case cmState::STRING:
  72. {
  73. const char* stringsProp = cm->GetState()
  74. ->GetCacheEntryProperty(key, "STRINGS");
  75. if(stringsProp)
  76. {
  77. cmCursesOptionsWidget* ow =
  78. new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1);
  79. this->Entry = ow;
  80. std::vector<std::string> options;
  81. cmSystemTools::ExpandListArgument(stringsProp, options);
  82. for(std::vector<std::string>::iterator
  83. si = options.begin(); si != options.end(); ++si)
  84. {
  85. ow->AddOption(*si);
  86. }
  87. ow->SetOption(value);
  88. }
  89. else
  90. {
  91. this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
  92. static_cast<cmCursesStringWidget*>(this->Entry)->SetString(value);
  93. }
  94. break;
  95. }
  96. case cmState::UNINITIALIZED:
  97. cmSystemTools::Error("Found an undefined variable: ",
  98. key.c_str());
  99. break;
  100. default:
  101. // TODO : put warning message here
  102. break;
  103. }
  104. }
  105. cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite()
  106. {
  107. delete this->Label;
  108. delete this->IsNewLabel;
  109. delete this->Entry;
  110. }
  111. const char* cmCursesCacheEntryComposite::GetValue()
  112. {
  113. if (this->Label)
  114. {
  115. return this->Label->GetValue();
  116. }
  117. else
  118. {
  119. return 0;
  120. }
  121. }