void CBibitemView::OnDblclkListFields(NMHDR* pNMHDR, LRESULT* pResult) { if (m_SelField != -1) { // Open URL CField *fi = (CField*)m_ListFields.GetItemData(m_SelField); if (fi) { if (!fi->GetValue().IsEmpty() && (fi->GetName().CompareNoCase(STR_LOCALURL) == 0 || fi->GetName().CompareNoCase(STR_URL) == 0)) { CString val = fi->GetValue(); CStringList lst; SplitSepString(val, &lst); POSITION p = lst.GetHeadPosition(); while (p) { if (ShellExec(lst.GetNext(p))) { if (p) // Wait some time if there are other files to show Sleep(500); } else MessageBeep(MB_ICONEXCLAMATION); } } else // Or show edit dialog OnFieldlistPopupEdit(); } } *pResult = 0; }
//---------------------------------------- void CFieldsTreeCtrl::UpdateFieldDescription(const wxTreeItemId& id) { if (!id.IsOk()) { return; } CFieldsTreeItemData* itemData = GetItemDataValue(id);; if (itemData == NULL) { return; } CField* field = itemData->GetField(); if (field == NULL) { return; } itemData->SetSplittedFieldDescr(field); wxString str; if (field->GetUnit().empty()) { str.Printf(wxT("%s"), field->GetName().c_str()); } else { str.Printf(wxT("%s (%s)"), field->GetName().c_str(), field->GetUnit().c_str()); } SetItemText(id, str); Refresh(); }
/** * Fill lst with all field names in the list, duplicates are ignored. */ void CBibList::GetAllFieldNames(CStringList *lst) { POSITION p = GetHeadPosition(); while (p) { CBibItem *bi = (CBibItem*)GetNext(p); if (bi->IsRegularItem()) { POSITION pf = bi->GetHeadPosition(); while (pf) { CField *fi = (CField*)bi->GetNext(pf); CString fn = fi->GetName(); fn.MakeLower(); if (lst->Find(fn) == NULL) lst->AddTail(fn); } } } }
void CBibitemView::PopulateFields() { // At the moment nothing is selected m_SelField = -1; BeginUpdate(); int l = -1, c = -1; m_ListFields.GetEditPos(l, c); m_ListFields.DeleteAllItems(); POSITION h = m_TmpItem->GetHeadPosition(); CField* fi; int j = 0; for (int i = 0; i < m_TmpItem->GetCount(); i++) { fi = (CField*)m_TmpItem->GetNext(h); if (fi) { j = m_ListFields.InsertItem(j, fi->GetName(), m_BibDef->GetRequired(m_TmpItem->GetType(), fi->GetName())); m_ListFields.SetItemText(j, 1, fi->GetValue()); m_ListFields.SetItemData(j, (DWORD)fi); } if (h == NULL) break; } // Add all other fields CField *finew; CBibItem *bi = m_BibDef->FindType(m_TmpItem->GetType()); if (bi != NULL) { h = bi->GetHeadPosition(); for (i = 0; i < bi->GetCount(); i++) { fi = (CField*)bi->GetNext(h); if (fi != NULL && m_TmpItem->Find(fi->GetName()) == NULL) { finew = m_TmpItem->New(); finew->SetName(fi->GetName()); finew->SetModified(FALSE); j = m_ListFields.InsertItem(j, finew->GetName(), m_BibDef->GetRequired(m_TmpItem->GetType(), finew->GetName())); m_ListFields.SetItemText(j, 1, _T("")); m_ListFields.SetItemData(j, (DWORD)finew); } if (h == NULL) break; } } // Sort it LVSORTPARAM ss; ss.iHeader = 0; ss.pListView = &m_ListFields; ss.bSortAsc = TRUE; // Sort the list m_ListFields.SortItems(SortFunc, (LPARAM)&ss); m_SortAsc = FALSE; // Edit the last cell if any if (l > -1 && c > -1) { if (l >= m_ListFields.GetItemCount()) { m_ListFields.CancelEdit(TRUE); m_ListFields.EditSubItem(m_ListFields.GetItemCount()-1, c); } else m_ListFields.EditSubItem(l, c); } m_ListFields.UpdateEditor(); EndUpdate(); }
//---------------------------------------- void CFieldsTreeCtrl::ShowMenu(wxTreeItemId id, const wxPoint& pt) { CFieldsTreeItemData* itemData = id.IsOk() ? dynamic_cast<CFieldsTreeItemData*>(GetItemData(id)) : NULL; if (itemData == NULL) { return; } CField* field = itemData->GetField(); if (field == NULL) { return; } wxString title; //title << wxT("Menu for ") << field->GetName().c_str(); title.Printf(wxT("Menu for '%s'"), field->GetName().c_str()); wxMenu* menu = wxGetApp().GetMenuFieldsTreeCtrl(); if (menu == NULL) { return; } menu->SetTitle(title); wxMenuItem* menuItem = menu->FindItem(ID_ASXMENU); if (menuItem != NULL) { menuItem->Enable(!ItemHasChildren(id)); } menuItem = menu->FindItem(ID_ASYMENU); if (menuItem != NULL) { menuItem->Enable(!ItemHasChildren(id)); } menuItem = menu->FindItem(ID_ASDATAMENU); if (menuItem != NULL) { menuItem->Enable(!ItemHasChildren(id)); } menuItem = menu->FindItem(ID_ASSELECTMENU); if (menuItem != NULL) { menuItem->Enable(!ItemHasChildren(id)); } menuItem = menu->FindItem(ID_FIELD_ATTR_CHANGE_UNIT); if (menuItem != NULL) { menuItem->Enable(CField::GetFieldNetCdfCFAttr(field, false) != NULL); } PopupMenu(menu, pt); /* #if wxUSE_MENUS wxMenu menu(title); menu.Append(-1, wxT("&Set as X...")); menu.Append(-1, wxT("&Set as Y...")); menu.Append(-1, wxT("&Set as Data...")); menu.Append(-1, wxT("&Set as Selection criteria...")); #endif // wxUSE_MENUS */ }
//---------------------------------------- wxTreeItemId CFieldsTreeCtrl::InsertField(const wxTreeItemId& parentId, CObjectTreeNode* node) { int32_t depth = node->GetLevel(); long numChildren = node->ChildCount(); CField *field = dynamic_cast<CField*>(node->GetData()); if (field == NULL) { wxMessageBox("ERROR in CFieldsTreeCtrl::InsertField - at least one of the tree object is not a CField object", "Error", wxOK | wxICON_ERROR); return parentId; } if ((typeid(*field) == typeid(CFieldIndex)) && field->IsVirtual()) { return parentId; } if ( depth <= 1 ) { wxString str; str.Printf(wxT("%s"), field->GetName().c_str()); // here we pass to AppendItem() normal and selected item images (we // suppose that selected image follows the normal one in the enum) int32_t image = TreeCtrlIcon_Folder; int32_t imageSel = image + 1; wxTreeItemId id = AddRoot(str, image, image, new CFieldsTreeItemData(field)); return id; } bool hasChildren = numChildren > 0; wxString str; if (field->GetUnit().empty()) { str.Printf(wxT("%s"), field->GetName().c_str()); } else { str.Printf(wxT("%s (%s)"), field->GetName().c_str(), field->GetUnit().c_str()); } /* // at depth 1 elements won't have any more children if ( hasChildren ) { str.Printf(wxT("%s"), field->GetName().c_str()); } else { str.Printf(wxT("%s child %d.%d"), wxT("File"), folder, n + 1); } */ // here we pass to AppendItem() normal and selected item images (we // suppose that selected image follows the normal one in the enum) int32_t image = (hasChildren) ? TreeCtrlIcon_Folder : TreeCtrlIcon_File; int32_t imageSel = image + 1; //wxTreeItemId id = AppendItem(idParent, str, image, imageSel, // new MyTreeItemData(str)); wxTreeItemId id = AppendItem(parentId, str, image, imageSel, new CFieldsTreeItemData(field)); //Expand(parentId); if ( (typeid(*field) == typeid(CFieldRecord)) || ( (typeid(*field) == typeid(CFieldArray)) && (field->IsFixedSize() == false) ) ) { SetItemBold(id, true); //SetItemFont(parentId, *wxSWISS_FONT); //SetItemFont(rootId, *wxITALIC_FONT); } // and now we also set the expanded one (only for the folders) if ( hasChildren ) { SetItemImage(id, TreeCtrlIcon_FolderOpened, wxTreeItemIcon_Expanded); } // remember the last child for OnEnsureVisible() if ( !hasChildren ) { m_lastItem = id; } wxTreeItemId returnId; if (hasChildren) { returnId = id; } else { returnId = parentId; CObjectTreeNode* parentNode = node->GetParent(); while (parentNode != NULL) { if (parentNode->m_current == parentNode->GetChildren().end()) { returnId = GetItemParent(returnId); parentNode = parentNode->GetParent(); } else { break; } } } return returnId; }