示例#1
0
void CInspectorTreeCtrl::DeleteCurrentItem(bool confirm) 
{
    HTREEITEM hItem = GetSelectedItem();
    if (hItem)
    {
        if(connection->lockWrite())
        {           
            IPropertyTree * pTree = NULL;
            CString name;

            CTreeListItem * tli = GetTreeListItem(hItem);
            if(tli->getType() == TLT_property)
            {
                if (!confirm || MessageBox("Delete property, are you sure?", "Delete Confirmation", MB_ICONQUESTION | MB_YESNO) == IDYES)
                {                       
                    CTreeListItem * parentTli = GetTreeListItem(GetParentItem(hItem));                  
                    pTree = parentTli->queryPropertyTree();
                    name = tli->getName(pTree, true);
                }
            }
            else
            {
                if (!confirm || MessageBox("Delete attribute, are you sure?", "Delete Confirmation", MB_ICONQUESTION | MB_YESNO) == IDYES)
                {
                    pTree = tli->queryPropertyTree();
                    name = "@";
                    name += tli->getName(NULL);
                }
            }       
            if(pTree)
            {
                if(pTree->removeProp(name))
                {
                    killDataItems(hItem);
                    DeleteItem(hItem);
                }
                else
                {
                    MessageBox("Failed to remove property or attribute, removeProp()\nfailed", "Failed to Remove", MB_OK | MB_ICONEXCLAMATION);
                }
            
            }   
            connection->unlockWrite();
        }
        else
            MessageBox("Unable to lock connection for write", "Cannot Obtain Lock", MB_OK);         
    }
}