Port CursesDialog to non-iterator cache API.

This commit is contained in:
Stephen Kelly 2015-04-06 12:01:35 +02:00
parent 9e64156725
commit 3e6a76e48b
3 changed files with 110 additions and 76 deletions

View File

@ -18,6 +18,9 @@
#include "cmCursesFilePathWidget.h" #include "cmCursesFilePathWidget.h"
#include "cmCursesDummyWidget.h" #include "cmCursesDummyWidget.h"
#include "../cmSystemTools.h" #include "../cmSystemTools.h"
#include "../cmake.h"
#include <assert.h>
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite( cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
const std::string& key, const std::string& key,
@ -32,7 +35,7 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
} }
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) int labelwidth, int entrywidth)
: Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth) : Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth)
{ {
@ -47,11 +50,13 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
} }
this->Entry = 0; 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); 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); static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true);
} }
@ -62,40 +67,40 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
break; break;
case cmCacheManager::PATH: case cmCacheManager::PATH:
this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1); this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1);
static_cast<cmCursesPathWidget*>(this->Entry)->SetString( static_cast<cmCursesPathWidget*>(this->Entry)->SetString(value);
it.GetValue());
break; break;
case cmCacheManager::FILEPATH: case cmCacheManager::FILEPATH:
this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1); this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1);
static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString( static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(value);
it.GetValue());
break; break;
case cmCacheManager::STRING: case cmCacheManager::STRING:
if(it.PropertyExists("STRINGS")) {
const char* stringsProp = cm->GetCacheManager()
->GetCacheEntryProperty(key, "STRINGS");
if(stringsProp)
{ {
cmCursesOptionsWidget* ow = cmCursesOptionsWidget* ow =
new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1); new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1);
this->Entry = ow; this->Entry = ow;
std::vector<std::string> options; std::vector<std::string> options;
cmSystemTools::ExpandListArgument( cmSystemTools::ExpandListArgument(stringsProp, options);
std::string(it.GetProperty("STRINGS")), options);
for(std::vector<std::string>::iterator for(std::vector<std::string>::iterator
si = options.begin(); si != options.end(); ++si) si = options.begin(); si != options.end(); ++si)
{ {
ow->AddOption(*si); ow->AddOption(*si);
} }
ow->SetOption(it.GetValue()); ow->SetOption(value);
} }
else else
{ {
this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1); this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
static_cast<cmCursesStringWidget*>(this->Entry)->SetString( static_cast<cmCursesStringWidget*>(this->Entry)->SetString(value);
it.GetValue());
} }
break; break;
}
case cmCacheManager::UNINITIALIZED: case cmCacheManager::UNINITIALIZED:
cmSystemTools::Error("Found an undefined variable: ", cmSystemTools::Error("Found an undefined variable: ",
it.GetName().c_str()); key.c_str());
break; break;
default: default:
// TODO : put warning message here // TODO : put warning message here

View File

@ -21,7 +21,7 @@ public:
cmCursesCacheEntryComposite(const std::string& key, int labelwidth, cmCursesCacheEntryComposite(const std::string& key, int labelwidth,
int entrywidth); int entrywidth);
cmCursesCacheEntryComposite(const std::string& key, cmCursesCacheEntryComposite(const std::string& key,
const cmCacheManager::CacheIterator& it, cmake *cm,
bool isNew, int labelwidth, int entrywidth); bool isNew, int labelwidth, int entrywidth);
~cmCursesCacheEntryComposite(); ~cmCursesCacheEntryComposite();
const char* GetValue(); const char* GetValue();

View File

@ -111,13 +111,17 @@ void cmCursesMainForm::InitializeUI()
// Count non-internal and non-static entries // Count non-internal and non-static entries
int count=0; int count=0;
for(cmCacheManager::CacheIterator i = std::vector<std::string> cacheKeys =
this->CMakeInstance->GetCacheManager()->NewIterator(); this->CMakeInstance->GetCacheManager()->GetCacheEntryKeys();
!i.IsAtEnd(); i.Next())
for(std::vector<std::string>::const_iterator it = cacheKeys.begin();
it != cacheKeys.end(); ++it)
{ {
if ( i.GetType() != cmCacheManager::INTERNAL && cmCacheManager::CacheEntryType t = this->CMakeInstance->GetCacheManager()
i.GetType() != cmCacheManager::STATIC && ->GetCacheEntryType(*it);
i.GetType() != cmCacheManager::UNINITIALIZED) if (t != cmCacheManager::INTERNAL &&
t != cmCacheManager::STATIC &&
t != cmCacheManager::UNINITIALIZED)
{ {
++count; ++count;
} }
@ -139,45 +143,49 @@ void cmCursesMainForm::InitializeUI()
// Create the composites. // Create the composites.
// First add entries which are new // First add entries which are new
for(cmCacheManager::CacheIterator i = for(std::vector<std::string>::const_iterator it = cacheKeys.begin();
this->CMakeInstance->GetCacheManager()->NewIterator(); it != cacheKeys.end(); ++it)
!i.IsAtEnd(); i.Next())
{ {
std::string key = i.GetName(); std::string key = *it;
if ( i.GetType() == cmCacheManager::INTERNAL || cmCacheManager::CacheEntryType t = this->CMakeInstance->GetCacheManager()
i.GetType() == cmCacheManager::STATIC || ->GetCacheEntryType(*it);
i.GetType() == cmCacheManager::UNINITIALIZED ) if (t == cmCacheManager::INTERNAL ||
t == cmCacheManager::STATIC ||
t == cmCacheManager::UNINITIALIZED )
{ {
continue; continue;
} }
if (!this->LookForCacheEntry(key)) if (!this->LookForCacheEntry(key))
{ {
newEntries->push_back(new cmCursesCacheEntryComposite(key, i, newEntries->push_back(new cmCursesCacheEntryComposite(key,
true, 30, this->CMakeInstance,
entrywidth)); true, 30,
entrywidth));
this->OkToGenerate = false; this->OkToGenerate = false;
} }
} }
// then add entries which are old // then add entries which are old
for(cmCacheManager::CacheIterator i = for(std::vector<std::string>::const_iterator it = cacheKeys.begin();
this->CMakeInstance->GetCacheManager()->NewIterator(); it != cacheKeys.end(); ++it)
!i.IsAtEnd(); i.Next())
{ {
std::string key = i.GetName(); std::string key = *it;
if ( i.GetType() == cmCacheManager::INTERNAL || cmCacheManager::CacheEntryType t = this->CMakeInstance->GetCacheManager()
i.GetType() == cmCacheManager::STATIC || ->GetCacheEntryType(*it);
i.GetType() == cmCacheManager::UNINITIALIZED ) if (t == cmCacheManager::INTERNAL ||
t == cmCacheManager::STATIC ||
t == cmCacheManager::UNINITIALIZED )
{ {
continue; continue;
} }
if (this->LookForCacheEntry(key)) if (this->LookForCacheEntry(key))
{ {
newEntries->push_back(new cmCursesCacheEntryComposite(key, i, newEntries->push_back(new cmCursesCacheEntryComposite(key,
false, 30, this->CMakeInstance,
entrywidth)); false, 30,
entrywidth));
} }
} }
} }
@ -216,10 +224,13 @@ void cmCursesMainForm::RePost()
std::vector<cmCursesCacheEntryComposite*>::iterator it; std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = this->Entries->begin(); it != this->Entries->end(); ++it) for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
{ {
cmCacheManager::CacheIterator mit = const char* existingValue =
this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue()); this->CMakeInstance->GetCacheManager()
if (mit.IsAtEnd() || ->GetCacheEntryValue((*it)->GetValue());
(!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))) bool advanced =
this->CMakeInstance->GetCacheManager()
->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED");
if (!existingValue || (!this->AdvancedMode && advanced))
{ {
continue; continue;
} }
@ -245,10 +256,13 @@ void cmCursesMainForm::RePost()
std::vector<cmCursesCacheEntryComposite*>::iterator it; std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = this->Entries->begin(); it != this->Entries->end(); ++it) for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
{ {
cmCacheManager::CacheIterator mit = const char* existingValue =
this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue()); this->CMakeInstance->GetCacheManager()
if (mit.IsAtEnd() || ->GetCacheEntryValue((*it)->GetValue());
(!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))) bool advanced =
this->CMakeInstance->GetCacheManager()
->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED");
if (!existingValue || (!this->AdvancedMode && advanced))
{ {
continue; continue;
} }
@ -314,10 +328,13 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
std::vector<cmCursesCacheEntryComposite*>::iterator it; std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = this->Entries->begin(); it != this->Entries->end(); ++it) for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
{ {
cmCacheManager::CacheIterator mit = const char* existingValue =
this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue()); this->CMakeInstance->GetCacheManager()
if (mit.IsAtEnd() || ->GetCacheEntryValue((*it)->GetValue());
(!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))) bool advanced =
this->CMakeInstance->GetCacheManager()
->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED");
if (!existingValue || (!this->AdvancedMode && advanced))
{ {
continue; continue;
} }
@ -334,10 +351,13 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
std::vector<cmCursesCacheEntryComposite*>::iterator it; std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = this->Entries->begin(); it != this->Entries->end(); ++it) for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
{ {
cmCacheManager::CacheIterator mit = const char* existingValue =
this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue()); this->CMakeInstance->GetCacheManager()
if (mit.IsAtEnd() || ->GetCacheEntryValue((*it)->GetValue());
(!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))) bool advanced =
this->CMakeInstance->GetCacheManager()
->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED");
if (!existingValue || (!this->AdvancedMode && advanced))
{ {
continue; continue;
} }
@ -495,11 +515,12 @@ void cmCursesMainForm::UpdateStatusBar(const char* message)
// Get the help string of the current entry // Get the help string of the current entry
// and add it to the help string // and add it to the help string
cmCacheManager::CacheIterator it = const char* existingValue =
this->CMakeInstance->GetCacheManager()->GetCacheIterator(curField); this->CMakeInstance->GetCacheManager()->GetCacheEntryValue(curField);
if (!it.IsAtEnd()) if (existingValue)
{ {
const char* hs = it.GetProperty("HELPSTRING"); const char* hs = this->CMakeInstance->GetCacheManager()
->GetCacheEntryProperty(curField, "HELPSTRING");
if ( hs ) if ( hs )
{ {
strncpy(help, hs, 127); strncpy(help, hs, 127);
@ -792,23 +813,28 @@ void cmCursesMainForm::FillCacheManagerFromUI()
size_t size = this->Entries->size(); size_t size = this->Entries->size();
for(size_t i=0; i < size; i++) for(size_t i=0; i < size; i++)
{ {
cmCacheManager::CacheIterator it = std::string cacheKey = (*this->Entries)[i]->Key;
this->CMakeInstance->GetCacheManager()->GetCacheIterator( const char* existingValue = this->CMakeInstance->GetCacheManager()
(*this->Entries)[i]->Key.c_str()); ->GetCacheEntryValue(cacheKey);
if (!it.IsAtEnd()) if (existingValue)
{ {
std::string oldValue = it.GetValue(); std::string oldValue = existingValue;
std::string newValue = (*this->Entries)[i]->Entry->GetValue(); std::string newValue = (*this->Entries)[i]->Entry->GetValue();
std::string fixedOldValue; std::string fixedOldValue;
std::string fixedNewValue; std::string fixedNewValue;
this->FixValue(it.GetType(), oldValue, fixedOldValue); cmCacheManager::CacheEntryType t =
this->FixValue(it.GetType(), newValue, fixedNewValue); this->CMakeInstance->GetCacheManager()
->GetCacheEntryType(cacheKey);
this->FixValue(t, oldValue, fixedOldValue);
this->FixValue(t, newValue, fixedNewValue);
if(!(fixedOldValue == fixedNewValue)) if(!(fixedOldValue == fixedNewValue))
{ {
// The user has changed the value. Mark it as modified. // The user has changed the value. Mark it as modified.
it.SetProperty("MODIFIED", true); this->CMakeInstance->GetCacheManager()
it.SetValue(fixedNewValue.c_str()); ->SetCacheEntryBoolProperty(cacheKey, "MODIFIED", true);
this->CMakeInstance->GetCacheManager()
->SetCacheEntryValue(cacheKey, fixedNewValue);
} }
} }
} }
@ -1017,12 +1043,15 @@ void cmCursesMainForm::HandleInput()
cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(field_userptr( cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(
this->Fields[findex-2])); this->Fields[findex-2]));
const char* curField = lbl->GetValue(); const char* curField = lbl->GetValue();
const char* helpString=0; const char* helpString = 0;
cmCacheManager::CacheIterator it =
this->CMakeInstance->GetCacheManager()->GetCacheIterator(curField); const char* existingValue =
if (!it.IsAtEnd()) this->CMakeInstance->GetCacheManager()
->GetCacheEntryValue(curField);
if (existingValue)
{ {
helpString = it.GetProperty("HELPSTRING"); helpString = this->CMakeInstance->GetCacheManager()
->GetCacheEntryProperty(curField, "HELPSTRING");
} }
if (helpString) if (helpString)
{ {