cmake/Source/CursesDialog/cmCursesCacheEntryComposite.cxx

110 lines
3.2 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
2020-02-01 23:06:01 +01:00
#include <cassert>
#include <utility>
#include <vector>
#include <cm/memory>
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"
2017-04-14 19:02:05 +02:00
#include "cmStateTypes.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2016-10-30 18:24:19 +01:00
#include "cmSystemTools.h"
2021-11-20 13:41:27 +01:00
#include "cmValue.h"
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)
{
2020-02-01 23:06:01 +01:00
this->Label =
cm::make_unique<cmCursesLabelWidget>(this->LabelWidth, 1, 1, 1, key);
this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, " ");
this->Entry =
cm::make_unique<cmCursesStringWidget>(this->EntryWidth, 1, 1, 1);
}
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
2020-02-01 23:06:01 +01:00
const std::string& key, cmState* state, bool isNew, int labelwidth,
2016-07-09 11:21:54 +02:00
int entrywidth)
: Key(key)
, LabelWidth(labelwidth)
, EntryWidth(entrywidth)
{
2020-02-01 23:06:01 +01:00
this->Label =
cm::make_unique<cmCursesLabelWidget>(this->LabelWidth, 1, 1, 1, key);
2016-07-09 11:21:54 +02:00
if (isNew) {
2020-02-01 23:06:01 +01:00
this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, "*");
2016-07-09 11:21:54 +02:00
} else {
2020-02-01 23:06:01 +01:00
this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, " ");
2016-07-09 11:21:54 +02:00
}
2021-11-20 13:41:27 +01:00
cmValue value = state->GetCacheEntryValue(key);
2015-08-17 11:37:30 +02:00
assert(value);
2020-02-01 23:06:01 +01:00
switch (state->GetCacheEntryType(key)) {
case cmStateEnums::BOOL: {
auto bw = cm::make_unique<cmCursesBoolWidget>(this->EntryWidth, 1, 1, 1);
2020-08-30 11:54:41 +02:00
bw->SetValueAsBool(cmIsOn(*value));
2020-02-01 23:06:01 +01:00
this->Entry = std::move(bw);
break;
2020-02-01 23:06:01 +01:00
}
case cmStateEnums::PATH: {
auto pw = cm::make_unique<cmCursesPathWidget>(this->EntryWidth, 1, 1, 1);
2020-08-30 11:54:41 +02:00
pw->SetString(*value);
2020-02-01 23:06:01 +01:00
this->Entry = std::move(pw);
break;
2020-02-01 23:06:01 +01:00
}
case cmStateEnums::FILEPATH: {
auto fpw =
cm::make_unique<cmCursesFilePathWidget>(this->EntryWidth, 1, 1, 1);
2020-08-30 11:54:41 +02:00
fpw->SetString(*value);
2020-02-01 23:06:01 +01:00
this->Entry = std::move(fpw);
break;
2020-02-01 23:06:01 +01:00
}
2017-04-14 19:02:05 +02:00
case cmStateEnums::STRING: {
2021-11-20 13:41:27 +01:00
cmValue stringsProp = state->GetCacheEntryProperty(key, "STRINGS");
2016-07-09 11:21:54 +02:00
if (stringsProp) {
2020-02-01 23:06:01 +01:00
auto ow =
cm::make_unique<cmCursesOptionsWidget>(this->EntryWidth, 1, 1, 1);
2020-08-30 11:54:41 +02:00
for (std::string const& opt : cmExpandedList(*stringsProp)) {
2018-01-26 17:06:56 +01:00
ow->AddOption(opt);
2014-08-03 19:52:23 +02:00
}
2020-08-30 11:54:41 +02:00
ow->SetOption(*value);
2020-02-01 23:06:01 +01:00
this->Entry = std::move(ow);
2016-07-09 11:21:54 +02:00
} else {
2020-02-01 23:06:01 +01:00
auto sw =
cm::make_unique<cmCursesStringWidget>(this->EntryWidth, 1, 1, 1);
2020-08-30 11:54:41 +02:00
sw->SetString(*value);
2020-02-01 23:06:01 +01:00
this->Entry = std::move(sw);
2015-08-17 11:37:30 +02:00
}
2016-07-09 11:21:54 +02:00
break;
}
2017-04-14 19:02:05 +02:00
case cmStateEnums::UNINITIALIZED:
2019-11-11 23:01:05 +01:00
cmSystemTools::Error("Found an undefined variable: " + key);
break;
default:
// TODO : put warning message here
break;
2016-07-09 11:21:54 +02:00
}
}
2020-02-01 23:06:01 +01:00
cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite() = default;
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
}
2018-01-26 17:06:56 +01:00
return nullptr;
}