cmake/Source/CursesDialog/cmCursesCacheEntryComposite.cxx

109 lines
3.4 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCursesCacheEntryComposite.h"
2016-07-09 11:21:54 +02:00
#include "cmCursesBoolWidget.h"
#include "cmCursesFilePathWidget.h"
#include "cmCursesLabelWidget.h"
#include "cmCursesOptionsWidget.h"
#include "cmCursesPathWidget.h"
#include "cmCursesStringWidget.h"
2016-10-30 18:24:19 +01:00
#include "cmCursesWidget.h"
#include "cmState.h"
#include "cmSystemTools.h"
#include "cmake.h"
2015-08-17 11:37:30 +02:00
#include <assert.h>
2016-10-30 18:24:19 +01:00
#include <cmConfigure.h>
#include <vector>
2015-04-27 22:25:09 +02:00
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
2016-07-09 11:21:54 +02:00
const std::string& key, int labelwidth, int entrywidth)
: Key(key)
, LabelWidth(labelwidth)
, EntryWidth(entrywidth)
{
this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
2016-10-30 18:24:19 +01:00
this->Entry = CM_NULLPTR;
this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
}
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
2016-07-09 11:21:54 +02:00
const std::string& key, cmake* cm, bool isNew, int labelwidth,
int entrywidth)
: Key(key)
, LabelWidth(labelwidth)
, EntryWidth(entrywidth)
{
this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
2016-07-09 11:21:54 +02:00
if (isNew) {
this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, "*");
2016-07-09 11:21:54 +02:00
} else {
this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
2016-07-09 11:21:54 +02:00
}
2016-10-30 18:24:19 +01:00
this->Entry = CM_NULLPTR;
2015-08-17 11:37:30 +02:00
const char* value = cm->GetState()->GetCacheEntryValue(key);
assert(value);
2016-07-09 11:21:54 +02:00
switch (cm->GetState()->GetCacheEntryType(key)) {
2015-08-17 11:37:30 +02:00
case cmState::BOOL:
this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1);
2016-07-09 11:21:54 +02:00
if (cmSystemTools::IsOn(value)) {
static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true);
2016-07-09 11:21:54 +02:00
} else {
static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(false);
2016-07-09 11:21:54 +02:00
}
break;
2015-08-17 11:37:30 +02:00
case cmState::PATH:
this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1);
2015-08-17 11:37:30 +02:00
static_cast<cmCursesPathWidget*>(this->Entry)->SetString(value);
break;
2015-08-17 11:37:30 +02:00
case cmState::FILEPATH:
this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1);
2015-08-17 11:37:30 +02:00
static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(value);
break;
2016-07-09 11:21:54 +02:00
case cmState::STRING: {
const char* stringsProp =
cm->GetState()->GetCacheEntryProperty(key, "STRINGS");
if (stringsProp) {
2014-08-03 19:52:23 +02:00
cmCursesOptionsWidget* ow =
new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1);
this->Entry = ow;
std::vector<std::string> options;
2015-08-17 11:37:30 +02:00
cmSystemTools::ExpandListArgument(stringsProp, options);
2016-07-09 11:21:54 +02:00
for (std::vector<std::string>::iterator si = options.begin();
si != options.end(); ++si) {
2014-08-03 19:52:23 +02:00
ow->AddOption(*si);
}
2016-07-09 11:21:54 +02:00
ow->SetOption(value);
} else {
2014-08-03 19:52:23 +02:00
this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
2015-08-17 11:37:30 +02:00
static_cast<cmCursesStringWidget*>(this->Entry)->SetString(value);
}
2016-07-09 11:21:54 +02:00
break;
}
2015-08-17 11:37:30 +02:00
case cmState::UNINITIALIZED:
2016-07-09 11:21:54 +02:00
cmSystemTools::Error("Found an undefined variable: ", key.c_str());
break;
default:
// TODO : put warning message here
break;
2016-07-09 11:21:54 +02:00
}
}
cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite()
{
delete this->Label;
delete this->IsNewLabel;
delete this->Entry;
}
const char* cmCursesCacheEntryComposite::GetValue()
{
2016-07-09 11:21:54 +02:00
if (this->Label) {
return this->Label->GetValue();
2016-07-09 11:21:54 +02:00
}
2016-10-30 18:24:19 +01:00
return CM_NULLPTR;
}