void BundlePane::RemoveMenuItem(const wxTreeItemId item, bool deep, PListDict& infoDict) { // Get the parent const wxTreeItemId parent = m_bundleTree->GetItemParent(item); const unsigned int ndx = GetTreeItemIndex(parent, item); // Remove item from treeCtrl m_bundleTree->Delete(item); // Get uuid of parent wxString parentUuid; const BundleItemData* data = (BundleItemData*)m_bundleTree->GetItemData(parent); if (data->m_type != BUNDLE_MENU) parentUuid = data->m_uuid; PListDict menuDict; if (!infoDict.GetDict("mainMenu", menuDict)) { wxFAIL_MSG(wxT("No mainMenu in info.plist")); return; } PListDict submenuDict; menuDict.GetDict("submenus", submenuDict); PListArray itemsArray; if (parentUuid.empty()) { if (!menuDict.GetArray("items", itemsArray)) { wxFAIL_MSG(wxT("mainMenu does not contain an item array in info.plist")); return; } } else { if (!submenuDict.IsOk()) { wxFAIL_MSG(wxT("no submenus in info.plist")); return; } PListDict subDict; if (!submenuDict.GetDict(parentUuid.mb_str(wxConvUTF8), subDict)) { wxFAIL_MSG(wxT("could not find submenu in info.plist")); return; } if (!subDict.GetArray("items", itemsArray)) { wxFAIL_MSG(wxT("no items in submenu")); return; } } if (deep) { // If it is a subdir, we have to recursively delete all subdirs const char* uuid = itemsArray.GetString(ndx); if (submenuDict.IsOk() && submenuDict.HasKey(uuid)) { DeleteSubDir(uuid, infoDict); } } // Remove the item itemsArray.DeleteItem(ndx); }
int duTreeListCtrl::GetInsertItem(TreeListItem *pItem, vector<duPlugin *> &vtInsert) { int nIndex = GetTreeItemIndex(pItem); TreeListItem *pNext = GetNextVisibleItem(pItem); while (pNext) { if (pNext == pItem->pNextSibling) break; vtInsert.push_back(pNext->pPlugin); pNext = GetNextVisibleItem(pNext); } return nIndex; }
void ElfHunterSideWidget::setwidget( QTreeWidgetItem *item, int col ) { int temp_item_index; temp_item_index = GetTreeItemIndex(item); if( temp_item_index!=-1 && temp_item_index < (int)elems.size() ) { elems[current_widget]->hide(); /* //TODO do i need this anymore? if( last_treeitem!=NULL ) last_treeitem->setBackground( 0, QBrush(Qt::transparent) ); item->setBackground( 0, QBrush(Qt::cyan) ); last_treeitem = item; */ elems[temp_item_index]->show(); current_widget = temp_item_index; } }
TreeListItem *duTreeListCtrl::InsertTreeItem(TreeListItem *pParent, TreeListItem *pInsertAfter, LPCTSTR lpszTemplate) { if (lpszTemplate == NULL) return NULL; if ((pParent == NULL) || (pParent == TCVIL_ROOT)) pParent = &m_RootItem; TreeListItem *pNewItem = new TreeListItem; pNewItem->pPlugin = NULL; pNewItem->nLevel = 0; pNewItem->fExpand = TRUE; pNewItem->pParent = NULL; pNewItem->pNextSibling = NULL; pNewItem->pFirstChild = NULL; if ((pInsertAfter == TCVIL_FIRST) || !pParent->pFirstChild) { pNewItem->pNextSibling = pParent->pFirstChild; pParent->pFirstChild = pNewItem; } else { TreeListItem *pItem = NULL; if (pInsertAfter == TCVIL_LAST) { for (pItem = pParent->pFirstChild; pItem->pNextSibling; pItem = pItem->pNextSibling) ; } else { for (pItem = pParent->pFirstChild; pItem->pNextSibling; pItem = pItem->pNextSibling) if (pItem == pInsertAfter) break; } pNewItem->pNextSibling = pItem->pNextSibling; pItem->pNextSibling = pNewItem; } pNewItem->pParent = pParent; pNewItem->nLevel = pParent->nLevel + 1; int nIndex = GetTreeItemIndex(pNewItem); pNewItem->pPlugin = duListCtrl::InsertLine(nIndex, lpszTemplate); if (pNewItem->pPlugin == NULL) { delete pNewItem; return NULL; } duPlugin *pFirstCol = pNewItem->pPlugin->GetFirstChild(); if (pFirstCol && lstrcmpi(pFirstCol->GetType(), _T("treelistitem")) == 0) { duTreeListItem *pTreeListItem = (duTreeListItem *)pFirstCol; pTreeListItem->SetLevel(pNewItem->nLevel); pTreeListItem->SetExpand(pNewItem->fExpand); pTreeListItem->ShowCheckBox(TRUE); pTreeListItem->SetTreeListItem(pNewItem); pTreeListItem->Adjust(); //TCHAR szNameStatic[256]; //_stprintf(szNameStatic, _T("Name %d"), m_nCloneIndex); //pFirstCol->GetFirstChild()->GetFirstChild()->GetNextSibling()->SetText(szNameStatic); //pNewItem->pPlugin->SetText(szNameStatic); } return pNewItem; }
void duTreeListCtrl::ExpandItem(TreeListItem *pItem, BOOL fExpand) { if (pItem == NULL || pItem == &m_RootItem) return; if (pItem->fExpand == fExpand || pItem->pFirstChild == NULL) return; duPlugin *pNextSibling = NULL; if (pItem->pNextSibling) pNextSibling = pItem->pNextSibling->pPlugin; if (!fExpand) { pItem->fExpand = FALSE; vector<int> vtRemoveIndex; vtRemoveIndex.clear(); ////////////////////////////////////////////////////////////////////////////////////// // TreeListItem // bug: nIndex return -1 // // // // ////////////////////////////////////////////////////////////////////////////////////// int i; int nIndex = GetTreeItemIndex(pItem); for (i = nIndex + 1;i < GetLineCount(); i++) { duPlugin *pTemp = m_vtLines[i]; if (pTemp == pNextSibling) break; duRect rcTemp; pTemp->GetRect(&rcTemp); pTemp->SetVisible(FALSE); m_nViewCy -= rcTemp.Height(); vtRemoveIndex.push_back(i); } m_vtLines.erase(m_vtLines.begin() + nIndex + 1, m_vtLines.begin() + i); UpdateScroll(); CompleteAdjustLine(); } else { pItem->fExpand = TRUE; vector<duPlugin *> vtInsert; vtInsert.clear(); int nIndex = GetInsertItem(pItem, vtInsert); int i; int nInsertCount = vtInsert.size(); for (i = 0;i < nInsertCount; i++) { duPlugin *pTemp = vtInsert[i]; duRect rcTemp; pTemp->GetRect(&rcTemp); m_nViewCy += rcTemp.Height(); m_vtLines.insert(m_vtLines.begin() + nIndex + i + 1, pTemp); } UpdateScroll(); CompleteAdjustLine(); } duPlugin *pFirstCol = pItem->pPlugin->GetFirstChild(); if (pFirstCol && lstrcmpi(pFirstCol->GetType(), _T("treelistitem")) == 0) { duTreeListItem *pTreeListItem = (duTreeListItem *)pFirstCol; pTreeListItem->SetExpand(fExpand); } Plugin_Redraw(this, TRUE); }
wxTreeItemId BundlePane::InsertMenuItem(const wxTreeItemId& dstItem, const wxString& name, BundleItemData* menuData, PListDict& infoDict) { wxASSERT(dstItem.IsOk()); // Make sure that the new item is marked as being in a menu menuData->m_isMenuItem = true; PListDict menuDict; if (!infoDict.GetDict("mainMenu", menuDict)) { wxFAIL_MSG(wxT("No mainMenu in info.plist")); return wxTreeItemId(); } PListArray itemsArray; if (!menuDict.GetArray("items", itemsArray)) { wxFAIL_MSG(wxT("mainMenu does not contain an item array in info.plist")); return wxTreeItemId(); } // Get parent and index wxTreeItemId parent; unsigned int insPos = 0; const BundleItemData* data = (BundleItemData*)m_bundleTree->GetItemData(dstItem); if (data->m_type == BUNDLE_MENU || data->m_type == BUNDLE_SUBDIR) { parent = dstItem; } else { parent = m_bundleTree->GetItemParent(dstItem); data = (BundleItemData*)m_bundleTree->GetItemData(parent); // Count to get index of selected item insPos = GetTreeItemIndex(parent, dstItem); ++insPos; // after selected item } // Insert in treeCtrl const wxTreeItemId newItem = m_bundleTree->InsertItem(parent, insPos, name, menuData->GetImageId(), -1, menuData); m_bundleTree->EnsureVisible(newItem); m_bundleTree->SelectItem(newItem); // Insert in plist if (data->m_type == BUNDLE_MENU) { itemsArray.InsertString(insPos, menuData->m_uuid.ToUTF8()); } else { PListDict submenuDict; if (!menuDict.GetDict("submenus", submenuDict)) { wxFAIL_MSG(wxT("No submenus in info.plist")); return wxTreeItemId(); } PListDict itemDict; if (!submenuDict.GetDict(data->m_uuid.mb_str(wxConvUTF8), itemDict)) { wxFAIL_MSG(wxT("invalid submenu in info.plist")); return wxTreeItemId(); } PListArray subArray; if (itemDict.GetArray("items", subArray)) { subArray.InsertString(insPos, menuData->m_uuid.ToUTF8()); } else { wxFAIL_MSG(wxT("no items array in submenu")); return wxTreeItemId(); } } return newItem; }