/*========================================================================= * * CPASectO.hpp - CPA_SectionObject : implementation * * * Version 1.0 * Creation date 20.06.97 * Revision date * * Shaitan *=======================================================================*/ #include "stdafx.h" #ifdef ACTIVE_EDITOR #include "itf/CPASaveO.hpp" #include "acp_base.h" #include "itf/CoheMngr.hpp" #include "itf/NameMngr.hpp" #include "itf/CPAInter.hpp" //################################################################################# // INIT //################################################################################# /*=========================================================================== Constructor =========================================================================*/ CPA_SaveObject::CPA_SaveObject (CPA_EditorBase *pEditor, const CString csType, tdeSaveStatus eStatus, CPA_BaseObject *pOwner, BOOL bAvailable, char *p_szDataPath, SCR_tdpfn_Ntfy_Callback pCallBack) : CPA_BaseObject (pEditor, csType, pOwner, bAvailable), CPA_SectionObject ("", p_szDataPath, pCallBack) { // init save status m_eSaveStatus = eStatus; } /*=========================================================================== Copy-Constructor =========================================================================*/ CPA_SaveObject::CPA_SaveObject (CPA_SaveObject &r_oSource) : CPA_BaseObject (r_oSource), CPA_SectionObject (r_oSource) { // init save status m_eSaveStatus = r_oSource.m_eSaveStatus; } /*=========================================================================== Destructor =========================================================================*/ CPA_SaveObject::~CPA_SaveObject (void) { } //################################################################################# // PRIVATE FUNCTIONS //################################################################################# /*=========================================================================== * Description: rename object * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ void CPA_SaveObject::fn_vDoRename (const CString csNewName) { BOOL bFirstRegister; bFirstRegister = GetName().IsEmpty(); // base rename CPA_BaseObject::fn_vDoRename(csNewName); if (!bFirstRegister) { // notify save with new name if (fn_bCanBeNotified()) fn_vNotifyRename(); // update all references fn_vUpdateAllReferences(); } } //################################################################################# // NAME //################################################################################# /*=========================================================================== * Description: get a default name according to validity criteria * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ CString CPA_SaveObject::GetDefaultValidName (const CString csDefaultBaseName /*= ""*/) { CString csNewName; CPA_Interface *pInterface; pInterface = GetEditor()->GetInterface(); do { csNewName = pInterface->GetPrefixedName( GetBaseObjectList() -> GetNewName( csDefaultBaseName ) ); } while( fn_eCheckValidity(csNewName) != E_mc_None ); return csNewName; } /*=========================================================================== * Description: rename object with default name, according to validity criteria * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ void CPA_SaveObject::SetDefaultValidName (const CString csDefaultBaseName /*= ""*/) { CString csNewName; csNewName = GetDefaultValidName( csDefaultBaseName ); fn_vDoRename(csNewName); } /*=========================================================================== * Description: rename object, checking validity criteria * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ tdeMissingCriteria CPA_SaveObject::fn_eRename (const CString csNewName) { tdeMissingCriteria eResult; CPA_Interface *pInterface; CString csName; pInterface = GetEditor()->GetInterface(); // not loading => check prefix if ((!pInterface->fn_bIsLoadingWorld())&&(!csNewName.IsEmpty())) csName = pInterface->GetPrefixedName(csNewName); else csName = csNewName; // check unicity eResult = fn_eCheckValidity(csName); // rename object if (eResult == E_mc_None) fn_vDoRename(csName); // loading => register conflict else if ((eResult != E_mc_NoName)&&(pInterface->fn_bIsLoadingWorld())) { pInterface->fn_vAddRenamedObject(); g_oNameManager.fn_vRegisterConflict(this, csName, eResult); } return eResult; } //################################################################################# // VALIDITY //################################################################################# /*=========================================================================== * Description: check name for forbidden characters (scritps criteria) * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ BOOL CPA_SaveObject::fn_bCheckScriptCharacters (const CString csName) { int iNbFound = 0; iNbFound += csName.Find(' ') + 1; iNbFound += csName.Find('(') + 1; iNbFound += csName.Find(')') + 1; iNbFound += csName.Find('[') + 1; iNbFound += csName.Find(']') + 1; iNbFound += csName.Find('{') + 1; iNbFound += csName.Find('}') + 1; iNbFound += csName.Find('*') + 1; iNbFound += csName.Find('#') + 1; iNbFound += csName.Find('$') + 1; iNbFound += csName.Find(';') + 1; iNbFound += csName.Find(':') + 1; iNbFound += csName.Find('^') + 1; iNbFound += csName.Find('@') + 1; return (iNbFound == 0); } /*=========================================================================== * Description: check if section was notified with Delete * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ BOOL CPA_SaveObject::fn_bCheckNotification (const CString csNewName) { SCR_tdst_Ntfy_Description *pNotification; // if new name is original one, verification is not necessary if (fn_csComputeReferencedSectionName(csNewName) == GetInitialSectionName()) return TRUE; // if this section is registered as deleted, name is not valid pNotification = SCR_fnp_st_SvL1_GetRegisterNotify((char *)(LPCSTR)fn_csComputeCompleteSectionName(csNewName)); if ((pNotification)&&(pNotification->eAction == SCR_EA_Ntfy_DeleteSection)) return FALSE; // no objection return TRUE; } /*=========================================================================== * Description: check name for forbidden characters (scritps criteria) * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ tdeMissingCriteria CPA_SaveObject::fn_eCheckValidity (const CString csNewName) { tdeMissingCriteria eResult; // empty name is never valid if (csNewName.IsEmpty()) return E_mc_NoName; // check unicity eResult = fn_eCheckUnicity(csNewName); if (eResult != E_mc_None) return eResult; // check notification if (fn_bCanBeNotified()) { if (!fn_bCheckScriptCharacters(csNewName)) return E_mc_ScriptCharacters; if (!fn_bCheckNotification(csNewName)) return E_mc_Notification; } // name is valid return eResult; } //################################################################################# // REFERENCES //################################################################################# /*=========================================================================== * Description: update all objects referencing current one * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ void CPA_SaveObject::fn_vUpdateAllReferences (void) { CPA_List stListOfReferences; CPA_BaseObject *pReference; POSITION pos; int iNbReferences; // RAZ stListOfReferences.RemoveAll(); // get all references iNbReferences = g_oCoherenceManager.m_fn_iGetFatherList(this, &stListOfReferences); // notify all references for (pReference = stListOfReferences.GetHeadElement(pos); pReference; pReference = stListOfReferences.GetNextElement(pos)) { if (pReference->fn_bCanBeSaved()) ((CPA_SaveObject *) pReference)->fn_vUpdateReference(this); } } /*=========================================================================== * Description: called when an object referenced by the current one has changed * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ void CPA_SaveObject::fn_vUpdateReference (CPA_SaveObject *pReferencedObject) { // default handling => notify save fn_vNotifySave(); } //################################################################################# // NOTIFICATIONS //################################################################################# /*=========================================================================== * Description: check if obejct must be notifies (save status) * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ BOOL CPA_SaveObject::fn_bCanBeNotified (void) { // default handling => test responsibility level and validity return ((m_eSaveStatus != E_ss_NoSave)&&(m_eSaveStatus != E_ss_NoModif)); } /*=========================================================================== * Description: called when object must be saved (Add or Rebuild) * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ void CPA_SaveObject::fn_vNotifySave (void) { // default handling => set add or rebuild notify on SectionObject fn_vWriteSection(); } /*=========================================================================== * Description: called when object must be removed (Delete) * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ void CPA_SaveObject::fn_vNotifyUnSave (void) { // default handling => set delete notify on SectionObject fn_vDeleteSection(); } /*=========================================================================== * Description: called when object must be restored (cancel Delete and restore previous notify) * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ void CPA_SaveObject::fn_vNotifyRestore (void) { // default handling => restore notify on SectionObject fn_vRestoreSection(); } /*=========================================================================== * Description: called when object is renamed * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ void CPA_SaveObject::fn_vNotifyRename (void) { // default handling => rename section of SectionObject fn_vRenameSection(fn_csComputeReferencedSectionName(GetName())); } //################################################################################# // SECTION NAME //################################################################################# /*=========================================================================== * Description: called when section name must be changed without notification * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ void CPA_SaveObject::fn_vUpdateSectionName (void) { SetReferencedSectionName(fn_csComputeReferencedSectionName(GetName())); } /*=========================================================================== * Description: get referenced (minimum) section name corresponding to new name * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ CString CPA_SaveObject::fn_csComputeReferencedSectionName (const CString csNewName) { CString csSectionName; char szNewSectionName[SCR_CV_ui_Cfg_MaxLenName]; char szFileName[SCR_CV_ui_Cfg_MaxLenName]; char szActionName[SCR_CV_ui_Cfg_MaxLenName]; char szName[SCR_CV_ui_Cfg_MaxLenName]; // default handling => new section is build from old one csSectionName = GetReferencedSectionName(); if (!csSectionName.IsEmpty()) { SCR_fn_v_RdL0_SplitSectionName((char *)(LPCSTR)csSectionName, szFileName, szActionName, szName); SCR_fn_v_RdL0_ComputeSectionName(szNewSectionName, szFileName, szActionName, (char*)(LPCSTR)csNewName); csSectionName = szNewSectionName; } return csSectionName; } /*=========================================================================== * Description: get complete section name corresponding to new name * Creation date: 20.06.97 * Author: Shaitan *--------------------------------------------------------------------------- * Revision date: Author: *=========================================================================*/ CString CPA_SaveObject::fn_csComputeCompleteSectionName (const CString csNewName) { CString csCompleteName; csCompleteName = GetDataPath(); csCompleteName += "\\" + fn_csComputeReferencedSectionName(csNewName); return csCompleteName; } #endif //ACTIVE_EDITOR