ENH: fix bug with advanced items loosing edit and do a better job sorting

This commit is contained in:
Bill Hoffman 2004-01-02 17:24:19 -05:00
parent 02d253c59e
commit 0c4bec7563
4 changed files with 154 additions and 115 deletions

View File

@ -76,7 +76,7 @@ IDR_MAINFRAME ICON DISCARDABLE "res\\CMakeSetupDialog.ico"
IDD_ABOUTBOX DIALOGEX 0, 0, 235, 55 IDD_ABOUTBOX DIALOGEX 0, 0, 235, 55
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About CMakeSetup" CAPTION "About CMakeSetup"
FONT 8, "MS Sans Serif" FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN BEGIN
ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20 ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
LTEXT "CMakeSetup\nwww.cmake.org",IDC_STATIC,40,18,119,16 LTEXT "CMakeSetup\nwww.cmake.org",IDC_STATIC,40,18,119,16
@ -108,7 +108,7 @@ BEGIN
PUSHBUTTON "OK",IDC_OK,166,219,51,15 PUSHBUTTON "OK",IDC_OK,166,219,51,15
PUSHBUTTON "Cancel",IDCANCEL,222,219,51,15 PUSHBUTTON "Cancel",IDCANCEL,222,219,51,15
PUSHBUTTON "Help",IDC_HELP_BUTTON,278,219,51,15 PUSHBUTTON "Help",IDC_HELP_BUTTON,278,219,51,15
LISTBOX IDC_LIST2,15,53,419,126,LBS_OWNERDRAWVARIABLE | LISTBOX IDC_LIST2,15,53,419,126,LBS_SORT | LBS_OWNERDRAWVARIABLE |
LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT | WS_VSCROLL |
WS_HSCROLL WS_HSCROLL
GROUPBOX "Cache Values",IDC_FRAME,10,44,432,140 GROUPBOX "Cache Values",IDC_FRAME,10,44,432,140

View File

@ -768,14 +768,9 @@ void CMakeSetupDialog::FillCacheGUIFromCacheManager()
{ {
cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager(); cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
size_t size = m_CacheEntriesList.GetItems().size(); size_t size = m_CacheEntriesList.GetItems().size();
bool reverseOrder = false;
// if there are already entries in the cache, then // if there are already entries in the cache, then
// put the new ones in the top, so they show up first // put the new ones in the top, so they show up first
if(size) bool reverseOrder = false;
{
reverseOrder = true;
}
// all the current values are not new any more // all the current values are not new any more
std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems(); std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
for(std::set<CPropertyItem*>::iterator i = items.begin(); for(std::set<CPropertyItem*>::iterator i = items.begin();
@ -798,15 +793,7 @@ void CMakeSetupDialog::FillCacheGUIFromCacheManager()
{ {
value = '\'' + value + '\''; value = '\'' + value + '\'';
} }
bool advanced = i.GetPropertyAsBool("ADVANCED");
if(!m_AdvancedValues)
{
if(i.GetPropertyAsBool("ADVANCED"))
{
m_CacheEntriesList.RemoveProperty(key);
continue;
}
}
switch(i.GetType() ) switch(i.GetType() )
{ {
case cmCacheManager::BOOL: case cmCacheManager::BOOL:
@ -816,7 +803,8 @@ void CMakeSetupDialog::FillCacheGUIFromCacheManager()
"ON", "ON",
i.GetProperty("HELPSTRING"), i.GetProperty("HELPSTRING"),
CPropertyList::COMBO,"ON|OFF", CPropertyList::COMBO,"ON|OFF",
reverseOrder reverseOrder,
advanced
); );
} }
else else
@ -825,7 +813,7 @@ void CMakeSetupDialog::FillCacheGUIFromCacheManager()
"OFF", "OFF",
i.GetProperty("HELPSTRING"), i.GetProperty("HELPSTRING"),
CPropertyList::COMBO,"ON|OFF", CPropertyList::COMBO,"ON|OFF",
reverseOrder reverseOrder, advanced
); );
} }
break; break;
@ -834,7 +822,7 @@ void CMakeSetupDialog::FillCacheGUIFromCacheManager()
value.c_str(), value.c_str(),
i.GetProperty("HELPSTRING"), i.GetProperty("HELPSTRING"),
CPropertyList::PATH,"", CPropertyList::PATH,"",
reverseOrder reverseOrder, advanced
); );
break; break;
case cmCacheManager::FILEPATH: case cmCacheManager::FILEPATH:
@ -842,7 +830,7 @@ void CMakeSetupDialog::FillCacheGUIFromCacheManager()
value.c_str(), value.c_str(),
i.GetProperty("HELPSTRING"), i.GetProperty("HELPSTRING"),
CPropertyList::FILE,"", CPropertyList::FILE,"",
reverseOrder reverseOrder, advanced
); );
break; break;
case cmCacheManager::STRING: case cmCacheManager::STRING:
@ -850,7 +838,7 @@ void CMakeSetupDialog::FillCacheGUIFromCacheManager()
value.c_str(), value.c_str(),
i.GetProperty("HELPSTRING"), i.GetProperty("HELPSTRING"),
CPropertyList::EDIT,"", CPropertyList::EDIT,"",
reverseOrder reverseOrder, advanced
); );
break; break;
case cmCacheManager::INTERNAL: case cmCacheManager::INTERNAL:
@ -858,6 +846,15 @@ void CMakeSetupDialog::FillCacheGUIFromCacheManager()
break; break;
} }
} }
if(m_CacheEntriesList.GetShowAdvanced())
{
m_CacheEntriesList.ShowAdvanced();
}
else
{
m_CacheEntriesList.HideAdvanced();
}
m_OKButton.EnableWindow(false); m_OKButton.EnableWindow(false);
if(cachem->GetSize() > 0 && !cmSystemTools::GetErrorOccuredFlag()) if(cachem->GetSize() > 0 && !cmSystemTools::GetErrorOccuredFlag())
{ {
@ -867,11 +864,22 @@ void CMakeSetupDialog::FillCacheGUIFromCacheManager()
i != items.end(); ++i) i != items.end(); ++i)
{ {
CPropertyItem* item = *i; CPropertyItem* item = *i;
if(item->m_NewValue) if(item->m_Advanced )
{ {
// if one new value then disable to OK button if(item->m_NewValue && m_CacheEntriesList.GetShowAdvanced())
enable = false; {
break; enable = false;
break;
}
}
else
{
if(item->m_NewValue)
{
// if one new value then disable to OK button
enable = false;
break;
}
} }
} }
if(enable) if(enable)
@ -1274,83 +1282,15 @@ void CMakeSetupDialog::OnHelpButton()
void CMakeSetupDialog::ShowAdvancedValues() void CMakeSetupDialog::ShowAdvancedValues()
{ {
cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager(); m_CacheEntriesList.ShowAdvanced();
for(cmCacheManager::CacheIterator i = cachem->NewIterator();
!i.IsAtEnd(); i.Next())
{
const char* key = i.GetName();
if(!i.GetPropertyAsBool("ADVANCED"))
{
continue;
}
switch(i.GetType() )
{
case cmCacheManager::BOOL:
if(cmSystemTools::IsOn(i.GetValue()))
{
m_CacheEntriesList.AddProperty(key,
"ON",
i.GetProperty("HELPSTRING"),
CPropertyList::COMBO,"ON|OFF",
true
);
}
else
{
m_CacheEntriesList.AddProperty(key,
"OFF",
i.GetProperty("HELPSTRING"),
CPropertyList::COMBO,"ON|OFF",
true
);
}
break;
case cmCacheManager::PATH:
m_CacheEntriesList.AddProperty(key,
i.GetValue(),
i.GetProperty("HELPSTRING"),
CPropertyList::PATH,"",
true
);
break;
case cmCacheManager::FILEPATH:
m_CacheEntriesList.AddProperty(key,
i.GetValue(),
i.GetProperty("HELPSTRING"),
CPropertyList::FILE,"",
true
);
break;
case cmCacheManager::STRING:
m_CacheEntriesList.AddProperty(key,
i.GetValue(),
i.GetProperty("HELPSTRING"),
CPropertyList::EDIT,"",
true
);
break;
case cmCacheManager::INTERNAL:
m_CacheEntriesList.RemoveProperty(key);
break;
}
}
} }
void CMakeSetupDialog::RemoveAdvancedValues() void CMakeSetupDialog::RemoveAdvancedValues()
{ {
cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager(); m_CacheEntriesList.HideAdvanced();
for(cmCacheManager::CacheIterator i = cachem->NewIterator();
!i.IsAtEnd(); i.Next())
{
const char* key = i.GetName();
if(i.GetPropertyAsBool("ADVANCED"))
{
m_CacheEntriesList.RemoveProperty(key);
}
}
} }
void CMakeSetupDialog::OnAdvancedValues() void CMakeSetupDialog::OnAdvancedValues()
{ {
this->UpdateData(); this->UpdateData();

View File

@ -20,6 +20,7 @@
CPropertyList::CPropertyList() CPropertyList::CPropertyList()
{ {
m_Dirty = false; m_Dirty = false;
m_ShowAdvanced = false;
m_curSel = -1; m_curSel = -1;
} }
@ -129,34 +130,52 @@ int CPropertyList::AddItem(CString txt)
int nIndex = AddString(txt); int nIndex = AddString(txt);
return nIndex; return nIndex;
} }
// order = 0 sorted
int CPropertyList::AddPropItem(CPropertyItem* pItem, bool reverseOrder) // order = 1 add to top
// order = 2 add to bottom
int CPropertyList::AddPropItem(CPropertyItem* pItem, int order)
{ {
if(pItem->m_Advanced && ! m_ShowAdvanced)
{
m_PropertyItems.insert(pItem);
return 0;
}
this->HideControls(); this->HideControls();
int nIndex; int nIndex;
if(reverseOrder) if(order)
{ {
nIndex = InsertString(0, _T("")); if(order == 1)
{
order = 0;
}
if(order == 2)
{
order = -1;
}
nIndex = InsertString(order, _T(""));
} }
else else
{ {
nIndex = AddString(_T("")); nIndex = AddString(pItem->m_propName);
} }
SetItemDataPtr(nIndex,pItem); SetItemDataPtr(nIndex,pItem);
m_PropertyItems.insert(pItem); m_PropertyItems.insert(pItem);
return nIndex; return nIndex;
} }
int CPropertyList::AddProperty(const char* name, void CPropertyList::AddProperty(const char* name,
const char* value, const char* value,
const char* helpString, const char* helpString,
int type, int type,
const char* comboItems, bool reverseOrder) const char* comboItems,
bool reverseOrder,
bool advanced)
{ {
CPropertyItem* pItem = 0; CPropertyItem* pItem = 0;
for(int i =0; i < this->GetCount(); ++i) for(std::set<CPropertyItem*>::iterator i = m_PropertyItems.begin();
i != m_PropertyItems.end(); ++i)
{ {
CPropertyItem* item = this->GetItem(i); CPropertyItem* item = *i;
if(item->m_propName == name) if(item->m_propName == name)
{ {
pItem = item; pItem = item;
@ -166,7 +185,7 @@ int CPropertyList::AddProperty(const char* name,
pItem->m_HelpString = helpString; pItem->m_HelpString = helpString;
InvalidateList(); InvalidateList();
} }
return i; return;
} }
} }
// if it is not found, then create a new one // if it is not found, then create a new one
@ -175,7 +194,14 @@ int CPropertyList::AddProperty(const char* name,
pItem = new CPropertyItem(name, value, helpString, type, comboItems); pItem = new CPropertyItem(name, value, helpString, type, comboItems);
pItem->m_NewValue = true; pItem->m_NewValue = true;
} }
return this->AddPropItem(pItem, reverseOrder); pItem->m_Advanced = advanced;
int order = 0;
if(reverseOrder)
{
order = 1;
}
this->AddPropItem(pItem, order);
return;
} }
int CPropertyList::OnCreate(LPCREATESTRUCT lpCreateStruct) int CPropertyList::OnCreate(LPCREATESTRUCT lpCreateStruct)
@ -707,3 +733,66 @@ void CPropertyList::InvalidateList()
m_Dirty = true; m_Dirty = true;
} }
void CPropertyList::ShowAdvanced()
{
this->ResetContent();
m_ShowAdvanced = true;
std::map<std::string, CPropertyItem*> sortProps;
for(std::set<CPropertyItem*>::iterator i = m_PropertyItems.begin();
i != m_PropertyItems.end(); ++i)
{
sortProps[(const char*)(*i)->m_propName] = *i;
}
for(std::map<std::string, CPropertyItem*>::iterator i = sortProps.begin();
i != sortProps.end(); ++i)
{
CPropertyItem* item = i->second;
if(item->m_NewValue)
{
this->AddPropItem(item, 2);
}
}
for(std::map<std::string, CPropertyItem*>::iterator i = sortProps.begin();
i != sortProps.end(); ++i)
{
CPropertyItem* item = i->second;
if(!item->m_NewValue)
{
this->AddPropItem(item, 2);
}
}
this->InvalidateList();
}
void CPropertyList::HideAdvanced()
{
this->ResetContent();
m_ShowAdvanced = false;
std::map<std::string, CPropertyItem*> sortProps;
for(std::set<CPropertyItem*>::iterator i = m_PropertyItems.begin();
i != m_PropertyItems.end(); ++i)
{
sortProps[(const char*)(*i)->m_propName] = *i;
}
for(std::map<std::string, CPropertyItem*>::iterator i = sortProps.begin();
i != sortProps.end(); ++i)
{
CPropertyItem* item = i->second;
if(item->m_NewValue && !item->m_Advanced)
{
this->AddPropItem(item, 2);
}
}
for(std::map<std::string, CPropertyItem*>::iterator i = sortProps.begin();
i != sortProps.end(); ++i)
{
CPropertyItem* item = i->second;
if(!item->m_Advanced && !item->m_NewValue)
{
this->AddPropItem(item, 2);
}
}
this->InvalidateList();
}

View File

@ -35,6 +35,7 @@ public:
CString m_cmbItems; CString m_cmbItems;
bool m_NewValue; bool m_NewValue;
bool m_Removed; bool m_Removed;
bool m_Advanced;
public: public:
CPropertyItem(CString propName, CString curValue, CPropertyItem(CString propName, CString curValue,
@ -48,6 +49,7 @@ public:
m_curValue = curValue; m_curValue = curValue;
m_nItemType = nItemType; m_nItemType = nItemType;
m_cmbItems = cmbItems; m_cmbItems = cmbItems;
m_Advanced = false;
} }
}; };
@ -76,18 +78,22 @@ public:
// Operations // Operations
public: public:
bool GetShowAdvanced() {return m_ShowAdvanced;}
bool IsDirty() { return m_Dirty; } bool IsDirty() { return m_Dirty; }
void ClearDirty() { m_Dirty = false; } void ClearDirty() { m_Dirty = false; }
int AddItem(CString txt); int AddItem(CString txt);
int AddProperty(const char* name, void AddProperty(const char* name,
const char* value, const char* value,
const char* helpString, const char* helpString,
int type, int type,
const char* comboItems, const char* comboItems,
bool reverseOrder); bool reverseOrder,
bool advanced);
void RemoveProperty(const char* name); void RemoveProperty(const char* name);
void HideControls(); void HideControls();
void ShowAdvanced();
void HideAdvanced();
std::set<CPropertyItem*> GetItems() std::set<CPropertyItem*> GetItems()
{ {
return m_PropertyItems; return m_PropertyItems;
@ -136,7 +142,10 @@ protected:
void InvertLine(CDC* pDC,CPoint ptFrom,CPoint ptTo); void InvertLine(CDC* pDC,CPoint ptFrom,CPoint ptTo);
void DisplayButton(CRect region); void DisplayButton(CRect region);
int AddPropItem(CPropertyItem* pItem, bool top); // order = 0 sorted
// order = 1 add to top
// order = 2 add to bottom
int AddPropItem(CPropertyItem* pItem, int order);
void InvalidateList(); void InvalidateList();
CComboBox m_cmbBox; CComboBox m_cmbBox;
@ -158,6 +167,7 @@ protected:
BOOL m_bDivIsSet; BOOL m_bDivIsSet;
HCURSOR m_hCursorArrow; HCURSOR m_hCursorArrow;
HCURSOR m_hCursorSize; HCURSOR m_hCursorSize;
bool m_ShowAdvanced;
std::set<CPropertyItem*> m_PropertyItems; std::set<CPropertyItem*> m_PropertyItems;
}; };