cmake/Source/CursesDialog/cmCursesCacheEntryComposite.cxx

117 lines
3.8 KiB
C++
Raw Normal View History

2009-10-04 10:30:41 +03:00
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
2009-10-04 10:30:41 +03:00
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
2009-10-04 10:30:41 +03:00
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#include "cmCursesCacheEntryComposite.h"
2016-07-09 11:21:54 +02:00
#include "../cmState.h"
#include "../cmSystemTools.h"
2015-08-17 11:37:30 +02:00
#include "../cmake.h"
2016-07-09 11:21:54 +02:00
#include "cmCursesBoolWidget.h"
#include "cmCursesDummyWidget.h"
#include "cmCursesFilePathWidget.h"
#include "cmCursesLabelWidget.h"
#include "cmCursesOptionsWidget.h"
#include "cmCursesPathWidget.h"
#include "cmCursesStringWidget.h"
2015-08-17 11:37:30 +02:00
#include <assert.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)
{
this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
2013-03-16 19:13:01 +02:00
this->Entry = 0;
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
}
this->Entry = 0;
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
} else {
return 0;
2016-07-09 11:21:54 +02:00
}
}