cmake/Source/CursesDialog/cmCursesCacheEntryComposite.cxx

131 lines
4.1 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"
2014-08-03 19:52:23 +02:00
#include "cmCursesOptionsWidget.h"
#include "cmCursesStringWidget.h"
#include "cmCursesLabelWidget.h"
#include "cmCursesBoolWidget.h"
#include "cmCursesPathWidget.h"
#include "cmCursesFilePathWidget.h"
#include "cmCursesDummyWidget.h"
#include "../cmSystemTools.h"
2015-08-17 11:37:30 +02:00
#include "../cmake.h"
#include "../cmState.h"
#include <assert.h>
2015-04-27 22:25:09 +02:00
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
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(
2015-08-17 11:37:30 +02:00
const std::string& key, cmake *cm, bool isNew,
2013-03-16 19:13:01 +02:00
int labelwidth, int entrywidth)
: Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth)
{
this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
if (isNew)
{
this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, "*");
}
else
{
this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
}
this->Entry = 0;
2015-08-17 11:37:30 +02:00
const char* value = cm->GetState()->GetCacheEntryValue(key);
assert(value);
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);
2015-08-17 11:37:30 +02:00
if (cmSystemTools::IsOn(value))
{
static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true);
}
else
{
static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(false);
}
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;
2015-08-17 11:37:30 +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);
2014-08-03 19:52:23 +02:00
for(std::vector<std::string>::iterator
si = options.begin(); si != options.end(); ++si)
{
ow->AddOption(*si);
}
2015-08-17 11:37:30 +02:00
ow->SetOption(value);
2014-08-03 19:52:23 +02:00
}
else
{
this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
2015-08-17 11:37:30 +02:00
static_cast<cmCursesStringWidget*>(this->Entry)->SetString(value);
2014-08-03 19:52:23 +02:00
}
break;
2015-08-17 11:37:30 +02:00
}
case cmState::UNINITIALIZED:
2015-04-27 22:25:09 +02:00
cmSystemTools::Error("Found an undefined variable: ",
2015-08-17 11:37:30 +02:00
key.c_str());
break;
default:
// TODO : put warning message here
break;
}
}
cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite()
{
delete this->Label;
delete this->IsNewLabel;
delete this->Entry;
}
const char* cmCursesCacheEntryComposite::GetValue()
{
if (this->Label)
{
return this->Label->GetValue();
}
else
{
return 0;
}
}