// RefineKB.cpp : implementation file // #include "stdafx.h" #include "KBEditors.h" #include "KBEditorsDoc.h" #include "RefineKB.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CRefineKB property page IMPLEMENT_DYNCREATE(CRefineKB, CPropertyPage) CRefineKB::CRefineKB() : CPropertyPage(CRefineKB::IDD) { //{{AFX_DATA_INIT(CRefineKB) m_PrevName = _T(""); m_NewName = _T(""); //}}AFX_DATA_INIT } CRefineKB::~CRefineKB() { } void CRefineKB::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CRefineKB) DDX_Control(pDX, IDC_PROPLIST, m_PropList); DDX_Control(pDX, IDC_CPTLIST, m_CptList); DDX_Text(pDX, IDC_PREVNAME, m_PrevName); DDX_Text(pDX, IDC_NEWNAME, m_NewName); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CRefineKB, CPropertyPage) //{{AFX_MSG_MAP(CRefineKB) ON_LBN_SELCHANGE(IDC_CPTLIST, OnSelchangeCptlist) ON_LBN_SELCHANGE(IDC_PROPLIST, OnSelchangeProplist) ON_BN_CLICKED(IDC_REPLACE, OnReplace) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRefineKB message handlers void CRefineKB::SeeDoc(CKBEditorsDoc*Doc) { m_Doc = Doc; } BOOL CRefineKB::OnSetActive() { m_CptList.ResetContent(); CString str ; POSITION pos = m_Doc->m_CptList.GetStartPosition(); while (pos !=NULL) { m_Doc->m_CptList.GetNextAssoc(pos,str,m_Doc->Cpt); m_CptList.AddString(str); } m_CptList.SetCurSel(0); // OnSelchangeCptlist(); return CPropertyPage::OnSetActive(); } void CRefineKB::OnSelchangeCptlist() { m_PropList.ResetContent(); m_PrevName.Empty(); m_NewName.Empty(); int Sel = m_CptList.GetCurSel(); if (Sel < 0 ) return; CString CptStr; CString PropStr; m_CptList.GetText(Sel,CptStr); m_Doc->CurrentCpt = CptStr; m_Doc->m_CptList.Lookup(CptStr,m_Doc->Cpt); POSITION pos = m_Doc->Cpt->m_PropList.GetStartPosition(); while (pos !=NULL) { m_Doc->Cpt->m_PropList.GetNextAssoc(pos,PropStr,m_Doc->Prop); m_PropList.AddString(PropStr); } m_PrevName= m_NewName = "@"+CptStr+"."; UpdateData(FALSE); } void CRefineKB::OnSelchangeProplist() { int Sel = m_PropList.GetCurSel(); if (Sel < 0 ) return; m_PrevName.Empty(); m_NewName.Empty(); CString str; m_PropList.GetText(Sel,str); m_Doc->CurrentProp = str; m_Doc->m_CptList.Lookup(m_Doc->CurrentCpt,m_Doc->Cpt); m_Doc->Cpt->m_PropList.Lookup(str,m_Doc->Prop); m_PrevName= m_NewName = "@"+m_Doc->CurrentCpt+"."+str; UpdateData(FALSE); } void CRefineKB::OnReplace() { CString NewProp,NewCpt; UpdateData(); int intpos =1; while(m_NewName[intpos] !='.') { NewCpt = NewCpt + m_NewName[intpos++]; } intpos++; while(intpos < m_NewName.GetLength() ) { NewProp = NewProp + m_NewName[intpos++]; } m_Doc->m_CptList.Lookup(m_Doc->CurrentCpt,m_Doc->Cpt); m_Doc->Cpt->m_PropList.Lookup(m_Doc->CurrentProp,m_Doc->Prop); if (!NewProp.IsEmpty()) { m_Doc->Cpt->m_PropList.RemoveKey(m_Doc->CurrentProp); m_Doc->Cpt->m_PropList.SetAt(NewProp,m_Doc->Prop); m_Doc->Prop->NameL = NewProp; } m_Doc->m_CptList.RemoveKey(m_Doc->CurrentCpt); m_Doc->m_CptList.SetAt(NewCpt,m_Doc->Cpt); m_Doc->Cpt->NameL = NewCpt; POSITION pos =m_Doc->m_ClusterList.GetStartPosition(); while (pos) { CString str ; m_Doc->m_ClusterList.GetNextAssoc(pos,str,m_Doc->Cluster); POSITION pos1 = m_Doc->Cluster->RuleList.GetStartPosition(); while (pos1 !=NULL) { m_Doc->Cluster->RuleList.GetNextAssoc(pos1,str,m_Doc->Rule); CString R = m_Doc->Rule->GetAction(); R.Replace(m_PrevName,m_NewName); m_Doc->Rule->SetAction(R); R = m_Doc->Rule->GetCondition(); R.Replace(m_PrevName,m_NewName); m_Doc->Rule->SetCondition(R); } } m_PrevName.Empty(); m_NewName.Empty(); UpdateData(FALSE); OnSelchangeCptlist(); m_Doc->OnSaveDocument(m_Doc->AppName); }