Port CursesDialog to non-iterator cache API.
This commit is contained in:
parent
9e64156725
commit
3e6a76e48b
|
@ -18,6 +18,9 @@
|
|||
#include "cmCursesFilePathWidget.h"
|
||||
#include "cmCursesDummyWidget.h"
|
||||
#include "../cmSystemTools.h"
|
||||
#include "../cmake.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
|
||||
const std::string& key,
|
||||
|
@ -32,7 +35,7 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
|
|||
}
|
||||
|
||||
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
|
||||
const std::string& key, const cmCacheManager::CacheIterator& it, bool isNew,
|
||||
const std::string& key, cmake *cm, bool isNew,
|
||||
int labelwidth, int entrywidth)
|
||||
: Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth)
|
||||
{
|
||||
|
@ -47,11 +50,13 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
|
|||
}
|
||||
|
||||
this->Entry = 0;
|
||||
switch ( it.GetType() )
|
||||
const char* value = cm->GetCacheManager()->GetCacheEntryValue(key);
|
||||
assert(value);
|
||||
switch (cm->GetCacheManager()->GetCacheEntryType(key))
|
||||
{
|
||||
case cmCacheManager::BOOL:
|
||||
case cmCacheManager::BOOL:
|
||||
this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1);
|
||||
if (cmSystemTools::IsOn(it.GetValue().c_str()))
|
||||
if (cmSystemTools::IsOn(value))
|
||||
{
|
||||
static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true);
|
||||
}
|
||||
|
@ -62,40 +67,40 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
|
|||
break;
|
||||
case cmCacheManager::PATH:
|
||||
this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1);
|
||||
static_cast<cmCursesPathWidget*>(this->Entry)->SetString(
|
||||
it.GetValue());
|
||||
static_cast<cmCursesPathWidget*>(this->Entry)->SetString(value);
|
||||
break;
|
||||
case cmCacheManager::FILEPATH:
|
||||
this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1);
|
||||
static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(
|
||||
it.GetValue());
|
||||
static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(value);
|
||||
break;
|
||||
case cmCacheManager::STRING:
|
||||
if(it.PropertyExists("STRINGS"))
|
||||
{
|
||||
const char* stringsProp = cm->GetCacheManager()
|
||||
->GetCacheEntryProperty(key, "STRINGS");
|
||||
if(stringsProp)
|
||||
{
|
||||
cmCursesOptionsWidget* ow =
|
||||
new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1);
|
||||
this->Entry = ow;
|
||||
std::vector<std::string> options;
|
||||
cmSystemTools::ExpandListArgument(
|
||||
std::string(it.GetProperty("STRINGS")), options);
|
||||
cmSystemTools::ExpandListArgument(stringsProp, options);
|
||||
for(std::vector<std::string>::iterator
|
||||
si = options.begin(); si != options.end(); ++si)
|
||||
{
|
||||
ow->AddOption(*si);
|
||||
}
|
||||
ow->SetOption(it.GetValue());
|
||||
ow->SetOption(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
|
||||
static_cast<cmCursesStringWidget*>(this->Entry)->SetString(
|
||||
it.GetValue());
|
||||
static_cast<cmCursesStringWidget*>(this->Entry)->SetString(value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case cmCacheManager::UNINITIALIZED:
|
||||
cmSystemTools::Error("Found an undefined variable: ",
|
||||
it.GetName().c_str());
|
||||
key.c_str());
|
||||
break;
|
||||
default:
|
||||
// TODO : put warning message here
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
cmCursesCacheEntryComposite(const std::string& key, int labelwidth,
|
||||
int entrywidth);
|
||||
cmCursesCacheEntryComposite(const std::string& key,
|
||||
const cmCacheManager::CacheIterator& it,
|
||||
cmake *cm,
|
||||
bool isNew, int labelwidth, int entrywidth);
|
||||
~cmCursesCacheEntryComposite();
|
||||
const char* GetValue();
|
||||
|
|
|
@ -111,13 +111,17 @@ void cmCursesMainForm::InitializeUI()
|
|||
|
||||
// Count non-internal and non-static entries
|
||||
int count=0;
|
||||
for(cmCacheManager::CacheIterator i =
|
||||
this->CMakeInstance->GetCacheManager()->NewIterator();
|
||||
!i.IsAtEnd(); i.Next())
|
||||
std::vector<std::string> cacheKeys =
|
||||
this->CMakeInstance->GetCacheManager()->GetCacheEntryKeys();
|
||||
|
||||
for(std::vector<std::string>::const_iterator it = cacheKeys.begin();
|
||||
it != cacheKeys.end(); ++it)
|
||||
{
|
||||
if ( i.GetType() != cmCacheManager::INTERNAL &&
|
||||
i.GetType() != cmCacheManager::STATIC &&
|
||||
i.GetType() != cmCacheManager::UNINITIALIZED)
|
||||
cmCacheManager::CacheEntryType t = this->CMakeInstance->GetCacheManager()
|
||||
->GetCacheEntryType(*it);
|
||||
if (t != cmCacheManager::INTERNAL &&
|
||||
t != cmCacheManager::STATIC &&
|
||||
t != cmCacheManager::UNINITIALIZED)
|
||||
{
|
||||
++count;
|
||||
}
|
||||
|
@ -139,45 +143,49 @@ void cmCursesMainForm::InitializeUI()
|
|||
// Create the composites.
|
||||
|
||||
// First add entries which are new
|
||||
for(cmCacheManager::CacheIterator i =
|
||||
this->CMakeInstance->GetCacheManager()->NewIterator();
|
||||
!i.IsAtEnd(); i.Next())
|
||||
for(std::vector<std::string>::const_iterator it = cacheKeys.begin();
|
||||
it != cacheKeys.end(); ++it)
|
||||
{
|
||||
std::string key = i.GetName();
|
||||
if ( i.GetType() == cmCacheManager::INTERNAL ||
|
||||
i.GetType() == cmCacheManager::STATIC ||
|
||||
i.GetType() == cmCacheManager::UNINITIALIZED )
|
||||
std::string key = *it;
|
||||
cmCacheManager::CacheEntryType t = this->CMakeInstance->GetCacheManager()
|
||||
->GetCacheEntryType(*it);
|
||||
if (t == cmCacheManager::INTERNAL ||
|
||||
t == cmCacheManager::STATIC ||
|
||||
t == cmCacheManager::UNINITIALIZED )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!this->LookForCacheEntry(key))
|
||||
{
|
||||
newEntries->push_back(new cmCursesCacheEntryComposite(key, i,
|
||||
true, 30,
|
||||
entrywidth));
|
||||
newEntries->push_back(new cmCursesCacheEntryComposite(key,
|
||||
this->CMakeInstance,
|
||||
true, 30,
|
||||
entrywidth));
|
||||
this->OkToGenerate = false;
|
||||
}
|
||||
}
|
||||
|
||||
// then add entries which are old
|
||||
for(cmCacheManager::CacheIterator i =
|
||||
this->CMakeInstance->GetCacheManager()->NewIterator();
|
||||
!i.IsAtEnd(); i.Next())
|
||||
for(std::vector<std::string>::const_iterator it = cacheKeys.begin();
|
||||
it != cacheKeys.end(); ++it)
|
||||
{
|
||||
std::string key = i.GetName();
|
||||
if ( i.GetType() == cmCacheManager::INTERNAL ||
|
||||
i.GetType() == cmCacheManager::STATIC ||
|
||||
i.GetType() == cmCacheManager::UNINITIALIZED )
|
||||
std::string key = *it;
|
||||
cmCacheManager::CacheEntryType t = this->CMakeInstance->GetCacheManager()
|
||||
->GetCacheEntryType(*it);
|
||||
if (t == cmCacheManager::INTERNAL ||
|
||||
t == cmCacheManager::STATIC ||
|
||||
t == cmCacheManager::UNINITIALIZED )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this->LookForCacheEntry(key))
|
||||
{
|
||||
newEntries->push_back(new cmCursesCacheEntryComposite(key, i,
|
||||
false, 30,
|
||||
entrywidth));
|
||||
newEntries->push_back(new cmCursesCacheEntryComposite(key,
|
||||
this->CMakeInstance,
|
||||
false, 30,
|
||||
entrywidth));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -216,10 +224,13 @@ void cmCursesMainForm::RePost()
|
|||
std::vector<cmCursesCacheEntryComposite*>::iterator it;
|
||||
for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
|
||||
{
|
||||
cmCacheManager::CacheIterator mit =
|
||||
this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
|
||||
if (mit.IsAtEnd() ||
|
||||
(!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")))
|
||||
const char* existingValue =
|
||||
this->CMakeInstance->GetCacheManager()
|
||||
->GetCacheEntryValue((*it)->GetValue());
|
||||
bool advanced =
|
||||
this->CMakeInstance->GetCacheManager()
|
||||
->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED");
|
||||
if (!existingValue || (!this->AdvancedMode && advanced))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -245,10 +256,13 @@ void cmCursesMainForm::RePost()
|
|||
std::vector<cmCursesCacheEntryComposite*>::iterator it;
|
||||
for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
|
||||
{
|
||||
cmCacheManager::CacheIterator mit =
|
||||
this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
|
||||
if (mit.IsAtEnd() ||
|
||||
(!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")))
|
||||
const char* existingValue =
|
||||
this->CMakeInstance->GetCacheManager()
|
||||
->GetCacheEntryValue((*it)->GetValue());
|
||||
bool advanced =
|
||||
this->CMakeInstance->GetCacheManager()
|
||||
->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED");
|
||||
if (!existingValue || (!this->AdvancedMode && advanced))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -314,10 +328,13 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
|
|||
std::vector<cmCursesCacheEntryComposite*>::iterator it;
|
||||
for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
|
||||
{
|
||||
cmCacheManager::CacheIterator mit =
|
||||
this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
|
||||
if (mit.IsAtEnd() ||
|
||||
(!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")))
|
||||
const char* existingValue =
|
||||
this->CMakeInstance->GetCacheManager()
|
||||
->GetCacheEntryValue((*it)->GetValue());
|
||||
bool advanced =
|
||||
this->CMakeInstance->GetCacheManager()
|
||||
->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED");
|
||||
if (!existingValue || (!this->AdvancedMode && advanced))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -334,10 +351,13 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
|
|||
std::vector<cmCursesCacheEntryComposite*>::iterator it;
|
||||
for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
|
||||
{
|
||||
cmCacheManager::CacheIterator mit =
|
||||
this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
|
||||
if (mit.IsAtEnd() ||
|
||||
(!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")))
|
||||
const char* existingValue =
|
||||
this->CMakeInstance->GetCacheManager()
|
||||
->GetCacheEntryValue((*it)->GetValue());
|
||||
bool advanced =
|
||||
this->CMakeInstance->GetCacheManager()
|
||||
->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED");
|
||||
if (!existingValue || (!this->AdvancedMode && advanced))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -495,11 +515,12 @@ void cmCursesMainForm::UpdateStatusBar(const char* message)
|
|||
|
||||
// Get the help string of the current entry
|
||||
// and add it to the help string
|
||||
cmCacheManager::CacheIterator it =
|
||||
this->CMakeInstance->GetCacheManager()->GetCacheIterator(curField);
|
||||
if (!it.IsAtEnd())
|
||||
const char* existingValue =
|
||||
this->CMakeInstance->GetCacheManager()->GetCacheEntryValue(curField);
|
||||
if (existingValue)
|
||||
{
|
||||
const char* hs = it.GetProperty("HELPSTRING");
|
||||
const char* hs = this->CMakeInstance->GetCacheManager()
|
||||
->GetCacheEntryProperty(curField, "HELPSTRING");
|
||||
if ( hs )
|
||||
{
|
||||
strncpy(help, hs, 127);
|
||||
|
@ -792,23 +813,28 @@ void cmCursesMainForm::FillCacheManagerFromUI()
|
|||
size_t size = this->Entries->size();
|
||||
for(size_t i=0; i < size; i++)
|
||||
{
|
||||
cmCacheManager::CacheIterator it =
|
||||
this->CMakeInstance->GetCacheManager()->GetCacheIterator(
|
||||
(*this->Entries)[i]->Key.c_str());
|
||||
if (!it.IsAtEnd())
|
||||
std::string cacheKey = (*this->Entries)[i]->Key;
|
||||
const char* existingValue = this->CMakeInstance->GetCacheManager()
|
||||
->GetCacheEntryValue(cacheKey);
|
||||
if (existingValue)
|
||||
{
|
||||
std::string oldValue = it.GetValue();
|
||||
std::string oldValue = existingValue;
|
||||
std::string newValue = (*this->Entries)[i]->Entry->GetValue();
|
||||
std::string fixedOldValue;
|
||||
std::string fixedNewValue;
|
||||
this->FixValue(it.GetType(), oldValue, fixedOldValue);
|
||||
this->FixValue(it.GetType(), newValue, fixedNewValue);
|
||||
cmCacheManager::CacheEntryType t =
|
||||
this->CMakeInstance->GetCacheManager()
|
||||
->GetCacheEntryType(cacheKey);
|
||||
this->FixValue(t, oldValue, fixedOldValue);
|
||||
this->FixValue(t, newValue, fixedNewValue);
|
||||
|
||||
if(!(fixedOldValue == fixedNewValue))
|
||||
{
|
||||
// The user has changed the value. Mark it as modified.
|
||||
it.SetProperty("MODIFIED", true);
|
||||
it.SetValue(fixedNewValue.c_str());
|
||||
this->CMakeInstance->GetCacheManager()
|
||||
->SetCacheEntryBoolProperty(cacheKey, "MODIFIED", true);
|
||||
this->CMakeInstance->GetCacheManager()
|
||||
->SetCacheEntryValue(cacheKey, fixedNewValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1017,12 +1043,15 @@ void cmCursesMainForm::HandleInput()
|
|||
cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(
|
||||
this->Fields[findex-2]));
|
||||
const char* curField = lbl->GetValue();
|
||||
const char* helpString=0;
|
||||
cmCacheManager::CacheIterator it =
|
||||
this->CMakeInstance->GetCacheManager()->GetCacheIterator(curField);
|
||||
if (!it.IsAtEnd())
|
||||
const char* helpString = 0;
|
||||
|
||||
const char* existingValue =
|
||||
this->CMakeInstance->GetCacheManager()
|
||||
->GetCacheEntryValue(curField);
|
||||
if (existingValue)
|
||||
{
|
||||
helpString = it.GetProperty("HELPSTRING");
|
||||
helpString = this->CMakeInstance->GetCacheManager()
|
||||
->GetCacheEntryProperty(curField, "HELPSTRING");
|
||||
}
|
||||
if (helpString)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue