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 CBibitemView::OnFieldlistPopupEdit() { CSourceDialog dlg; CField* fi = (CField*)m_ListFields.GetItemData(m_SelField); dlg.SetSource(fi->GetValue()); if (dlg.DoModal() == IDOK) { fi->SetValue(dlg.GetSource()); SetModified(m_Modified || fi->GetModified()); m_ListFields.SetItemText(m_SelField, 1, dlg.GetSource()); } }
void CBibitemView::OnPopupBrowse() { CString f; CString fn; CField* fi = (CField*)m_ListFields.GetItemData(m_SelField); fn = DecodeFilename(fi->GetValue()); CFileFind finder; if (!finder.FindFile(fn)) // Dialog will not show when file does not exist fn.Empty(); finder.Close(); f.Format(_T("%s||"), AfxLoadString(IDS_STRING_ALLFILTER)); CFileDialogEx dlg(TRUE, NULL, fn, OFN_HIDEREADONLY | OFN_ENABLESIZING, f, this); if (dlg.DoModal() == IDOK) { m_ListFields.SetItemText(m_SelField, 1, EncodeFilename(dlg.GetPathName())); fi->SetValue(EncodeFilename(dlg.GetPathName())); SetModified(fi->GetModified()); } }
void CBibList::GetAllFieldValues(CString field, CStringList *lst) { lst->RemoveAll(); if (field.IsEmpty()) return; POSITION p = GetHeadPosition(); while (p) { CBibItem *bi = (CBibItem*)GetNext(p); if (bi->IsRegularItem()) { CField *fi = bi->Find(field); if (fi) { CString val = fi->GetValue(); if (!val.IsEmpty() && lst->Find(val) == NULL) lst->AddTail(val); } } } }
/** * Find a Field with name `Local-Url' and append the filename. * If no such field exists add one. */ void CBibitemView::AddLocalURL(CString url) { CField *fi = m_TmpItem->Find(STR_LOCALURL); if (!fi) AddField(STR_LOCALURL, url, FALSE); else { CString val = fi->GetValue(); if (!val.IsEmpty()) val += _T("; ") + url; else val = url; fi->SetValue(val); for (int i = 0; i < m_ListFields.GetItemCount(); i++) { if (m_ListFields.GetItemData(i) == (DWORD)fi) { m_ListFields.SetItemText(i, 1, val); break; } } } }
void CBibitemView::OnPopupLocalurl() { CString f, fn; f.Format(_T("%s||"), AfxLoadString(IDS_STRING_ALLFILTER)); CFileDialogEx dlg(TRUE, NULL, fn, OFN_HIDEREADONLY | OFN_ENABLESIZING, f, this); if (dlg.DoModal() == IDOK) { CField *fi = m_TmpItem->Find(STR_LOCALURL); if (fi == NULL) { fi = m_TmpItem->New(); fi->SetName(STR_LOCALURL); fi->SetValue(EncodeFilename(dlg.GetPathName())); } else { CString val = fi->GetValue(); if (!val.IsEmpty()) val += _T("; ") + EncodeFilename(dlg.GetPathName()); else val = EncodeFilename(dlg.GetPathName()); fi->SetValue(val); } SetModified(); PopulateFields(); } }
void COnlineSearch::DoSearch() { CWaitCursor wait; // Save the infos to the profile SaveProfile(); #ifdef _DEBUG m_editRawData.Clear(); #endif m_lstResults.SetRedraw(FALSE); m_lstResults.DeleteAllItems(); m_staticResults.SetWindowText(AfxLoadString(IDS_STRING_SEARCHRESULT)); CString str; try { m_editHost.GetWindowText(str); CString port; m_editPort.GetWindowText(port); CYazConn conn(str, _ttoi(port)); if (!conn.GetConnected()) { // Connection failed ShowError(conn.GetLastError()); } else { // Connection established conn.SetOption(_T("implementationName"), _T("BibEdt Version ") + CAboutDlg::GetAppVersion()); m_editUser.GetWindowText(str); if (!str.IsEmpty()) conn.SetOption(_T("user"), str); m_editGroup.GetWindowText(str); if (!str.IsEmpty()) conn.SetOption(_T("group"), str); m_editPass.GetWindowText(str); if (!str.IsEmpty()) conn.SetOption(_T("password"), str); m_editProxy.GetWindowText(str); if (!str.IsEmpty()) conn.SetOption(_T("proxy"), str); m_editDatabase.GetWindowText(str); if (!str.IsEmpty()) conn.SetOption(_T("databaseName"), str); conn.SetOption(_T("preferredRecordSyntax"), m_RecordSyntax); // conn.SetOption(_T("preferredRecordSyntax"), "OPAC"); m_editSearchFor.GetWindowText(str); CYazQuery* q = NULL; switch (GetQueryType()) { case QT_PREFIX: q = new CYazPrefixQuery(); break; case QT_CQL: q = new CYazCQLQuery(); break; case QT_CCL: q = new CYazCCLQuery(); break; default: ShowError(IDS_STRING_STRANGEQUERYTYPE); return; } ASSERT(q); q->SetQueryString(str); CYazResultSet rs = conn.Search(q); m_editRecStart.GetWindowText(str); int recstart = _ttoi(str); m_editRecEnd.GetWindowText(str); int recend = _ttoi(str); int n = rs.GetCount(); str.Format(AfxLoadString(IDS_STRING_SEARCHRESULTSNUM), n); m_staticResults.SetWindowText(str); if (recend > 0) n = min(n, recend); int ix = -1; #ifdef _DEBUG CFile dbgfile; try { dbgfile.Open(COptions::AddBackslash(COptions::GetAppPath()) + _T("result.xml"), CFile::modeWrite | CFile::shareExclusive | CFile::modeCreate); } catch (...) { } #endif for (int i = recstart - 1; i < n; i++) { CYazRecord rec = rs.GetRecord(i); CString rawdata = rec.GetRaw(); #ifdef _DEBUG try { dbgfile.Write(rawdata, rawdata.GetLength()); } catch (...) { } int selstart = m_editRawData.GetWindowTextLength(); m_editRawData.SetSel(selstart, selstart, TRUE); m_editRawData.ReplaceSel(rawdata + _T("\r\n")); #endif // Add the item to m_Results list CBibItem* item = m_Results.New(); item->SetType(rec.GetType()); item->Add(_T("raw"), rawdata); str = rec.GetValue(STR_AUTHOR); if (!str.IsEmpty()) item->Add(STR_AUTHOR, str); str = rec.GetValue(STR_EDITOR); if (!str.IsEmpty()) item->Add(STR_EDITOR, str); str = rec.GetValue(STR_TITLE); if (!str.IsEmpty()) item->Add(STR_TITLE, str); str = rec.GetValue(STR_EDITION); if (!str.IsEmpty()) item->Add(STR_EDITION, str); str = rec.GetValue(STR_SERIES); if (!str.IsEmpty()) item->Add(STR_SERIES, str); str = rec.GetValue(_T("Performer")); if (!str.IsEmpty()) item->Add(_T("Performer"), str); str = rec.GetValue(STR_YEAR); if (!str.IsEmpty()) item->Add(STR_YEAR, str); str = rec.GetValue(_T("ISBN")); if (!str.IsEmpty()) item->Add(_T("ISBN"), str); str = rec.GetValue(_T("Topic")); if (!str.IsEmpty()) item->Add(_T("Topic"), str); str = rec.GetValue(_T("Contents")); if (!str.IsEmpty()) item->Add(_T("Contents"), str); // Add it to the listview CField* field = item->Find(STR_AUTHOR); if (!field) field = item->Find(STR_EDITOR); if (!field) field = item->Find(_T("Performer")); if (field) ix = m_lstResults.InsertItem(ix+1, field->GetValue(), -1); else ix = m_lstResults.InsertItem(ix+1, NULL, -1); m_lstResults.SetItemData(ix, (DWORD)item); field = item->Find(STR_TITLE); if (field) m_lstResults.SetItemText(ix, 1, field->GetValue()); field = item->Find(STR_YEAR); if (field) m_lstResults.SetItemText(ix, 2, field->GetValue()); } delete q; #ifdef _DEBUG try { dbgfile.Close(); } catch (...) { } #endif } // if (conn.GetConnected()) } catch (...) { ShowError(IDS_STRING_YAZEXCEPTION); } m_lstResults.SetRedraw(); m_staticResults.Invalidate(); }
inline bool CField::operator==(const CField& oValue) const { return operator==(oValue.GetValue()); }
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(); }
int CBibList::KeySortProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { CBibList *lst = (CBibList*)lParamSort; POSITION p = lst->FindIndex(lParam1); if (!p) return 0; CBibItem *bi1 = (CBibItem*)lst->GetAt(p); p = lst->FindIndex(lParam2); if (!p) return 0; CBibItem *bi2 = (CBibItem*)lst->GetAt(p); // Handle @string{}, @comment{}, @preamble{} differently // - Filter should be on top of the file // - Preamble should be AFTER strings, so string macros can be used // - Strings should be on top of the file // - Comments should be where they actually are // Only real Bib items should be sorted by their Key // Put filter on top of the file if (bi1->IsType(STR_COMMENT) && bi1->GetKey().CompareNoCase(STR_FILTER) == 0) return -1; else if (bi2->IsType(STR_COMMENT) && bi2->GetKey().CompareNoCase(STR_FILTER) == 0) return 1; // Comments should be where they are if (bi1->IsType(STR_COMMENT) || bi2->IsType(STR_COMMENT)) return 0; // Strings should be before preambles if (bi1->IsType(STR_PREAMBLE) && bi2->IsType(STR_STRING)) return 1; if (bi1->IsType(STR_STRING) && bi2->IsType(STR_PREAMBLE)) return -1; // Preambles are before real bibitems if (bi1->IsType(STR_PREAMBLE) && !bi2->IsType(STR_PREAMBLE)) return -1; if (!bi1->IsType(STR_PREAMBLE) && bi2->IsType(STR_PREAMBLE)) return 1; if (bi1->IsType(STR_PREAMBLE) && bi2->IsType(STR_PREAMBLE)) return 0; // Strings are before real bibitems if (bi1->IsType(STR_STRING) && !bi2->IsType(STR_STRING)) return -1; if (!bi1->IsType(STR_STRING) && bi2->IsType(STR_STRING)) return 1; // Ensure that cross-referenced items appear after cross-referencing items CField* crossref = bi1->Find(STR_CROSSREF); CBibItem* refed; CString crv; if (crossref) { crv = crossref->GetValue(); if (!crv.IsEmpty()) { refed = lst->Find(crv); if (refed) refed->m_CrossRefed = TRUE; } } crossref = bi2->Find(STR_CROSSREF); if (crossref) { crv = crossref->GetValue(); if (!crv.IsEmpty()) { refed = lst->Find(crv); if (refed) refed->m_CrossRefed = TRUE; } } if (bi1->m_CrossRefed && !bi2->m_CrossRefed) return 1; else if (bi2->m_CrossRefed && !bi1->m_CrossRefed) return -1; // Reached that, both must be real bibitems -> compare the key if (((CBibedtApp*)AfxGetApp())->m_Options->m_SortCaseSensitive) return bi1->GetKey().Compare(bi2->GetKey()); else return bi1->GetKey().CompareNoCase(bi2->GetKey()); }
CScriptObject::MEMBERRESULT CFieldScriptObject::ExecuteMemberFunction( char* pszName, Variant* pParameters, int nParameters, Variant& returnValue ) { //field value query/modification functions - only if field properties allow! if( stricmp( pszName, "getfieldvalue" ) == 0 ) { if( nParameters == 1 ) { //search the entire field list int iMax = m_FieldList.GetSize(); for( int i = 0; i < iMax; i++ ) { //get the next item and return the value if it's the one we're looking for CField* pField = m_FieldList[i]; if( pField && pField->m_Code == pParameters[0] ) { if( pField->m_dwFlags & FIELD_SCRIPTREAD ) { returnValue = pField->GetValue(); return OK; } else { AfxMessageBox( CString("Field is protected: ") + CString(LPCSTR(pParameters[0])) ); return UNKNOWN_ERROR; } } }; //couldn't find it... AfxMessageBox( CString("Field not found: ") + CString(LPCSTR(pParameters[0])) ); return UNKNOWN_ERROR; } else return nParameters < 1 ? TOO_FEW_PARAMS : TOO_MANY_PARAMS; } if( stricmp( pszName, "setfieldvalue" ) == 0 ) { if( nParameters == 2 ) { //search the entire field list int iMax = m_FieldList.GetSize(); for( int i = 0; i < iMax; i++ ) { //get the next item and change the value if it's the one we're looking for CField* pField = m_FieldList[i]; if( pField && pField->m_Code == pParameters[0] ) { if( pField->m_dwFlags & FIELD_SCRIPTWRITE ) { pField->SetValue( pParameters[1] ); return OK; } else { AfxMessageBox( CString("Field is protected: ") + CString(LPCSTR(pParameters[0])) ); return UNKNOWN_ERROR; } } }; //couldn't find it... AfxMessageBox( CString("Field not found: ") + CString(LPCSTR(pParameters[0])) ); return UNKNOWN_ERROR; } else return nParameters < 2 ? TOO_FEW_PARAMS : TOO_MANY_PARAMS; } return NOT_FOUND; }