Index: src/ictranslate/ICTranslateDlg.cpp =================================================================== diff -u -rd99ea57e5e78d9b2cc7d6024d9f26f2b4da7cc86 -rc72f797f7e7795e3ff15dc2ed832032ee6bafd0a --- src/ictranslate/ICTranslateDlg.cpp (.../ICTranslateDlg.cpp) (revision d99ea57e5e78d9b2cc7d6024d9f26f2b4da7cc86) +++ src/ictranslate/ICTranslateDlg.cpp (.../ICTranslateDlg.cpp) (revision c72f797f7e7795e3ff15dc2ed832032ee6bafd0a) @@ -93,7 +93,7 @@ ON_BN_CLICKED(IDC_CHOOSE_FONT_BUTTON, &CICTranslateDlg::OnBnClickedChooseFontButton) ON_COMMAND(ID_EDIT_CLEANUP_TRANSLATION, &CICTranslateDlg::OnEditCleanupTranslation) ON_COMMAND(ID_FILE_NEWTRANSLATION, &CICTranslateDlg::OnFileNewTranslation) - ON_COMMAND(ID_FILE_SAVETRANSLATIONAS, &CICTranslateDlg::OnFileSavetranslationAs) + ON_COMMAND(ID_FILE_SAVETRANSLATIONAS, &CICTranslateDlg::OnFileSaveTranslationAs) ON_COMMAND(ID_FILE_SAVETRANSLATION, &CICTranslateDlg::OnFileSaveTranslation) END_MESSAGE_MAP() @@ -222,6 +222,10 @@ void CICTranslateDlg::OnFileOpenYourTranslation() { + // check for modification flag + if(!WarnModified()) + return; + CFileDialog fd(TRUE, _T(".lng"), _T(""), OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, _T("Language files (*.lng)|*.lng|All files(*.*)|*.*||"), this); if(fd.DoModal() == IDOK) { @@ -530,6 +534,7 @@ { pCustomItem->SetText(strText, false); pCustomItem->SetChecksum(pBaseItem->GetChecksum()); + m_ldCustom.SetModified(); } UpdateCustomListImage(iPos, true); @@ -569,7 +574,7 @@ } CFontDialog dlg(&lf); - if(dlg.DoModal()) + if(dlg.DoModal() == IDOK) { // set font info dlg.GetCurrentFont(&lf); @@ -591,18 +596,22 @@ void CICTranslateDlg::OnFileNewTranslation() { + // check for modification flag + if(!WarnModified()) + return; + // clear the custom translation m_ldCustom.Clear(); UpdateCustomLanguageList(); } -void CICTranslateDlg::OnFileSavetranslationAs() +void CICTranslateDlg::OnFileSaveTranslationAs() { CString strFilename = m_ldCustom.GetFilename(false); CString strPath = m_ldCustom.GetFilename(true); CFileDialog dlg(FALSE, _T(".lng"), strFilename, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("Language files (*.lng)|*.lng|All files (*.*)|*.*||"), this); - if(dlg.DoModal()) + if(dlg.DoModal() == IDOK) { // store additional informations from the dialog box CString str; @@ -626,7 +635,7 @@ CString strPath = m_ldCustom.GetFilename(true); if(strPath.IsEmpty()) { - OnFileSavetranslationAs(); + OnFileSaveTranslationAs(); } else { @@ -645,3 +654,21 @@ m_ctlDstFilename.SetWindowText(m_ldCustom.GetFilename(true)); } } + +bool CICTranslateDlg::WarnModified() const +{ + // check the modification flag + if(m_ldCustom.IsModified()) + { + int iRes = AfxMessageBox(_T("You have modified the translation file. If you continue, the changes might be lost. Do you want to continue ?"), MB_YESNO | MB_ICONQUESTION); + return iRes == IDYES; + } + else + return true; +} + +void CICTranslateDlg::OnCancel() +{ + if(WarnModified()) + CDialog::OnCancel(); +} Index: src/ictranslate/ICTranslateDlg.h =================================================================== diff -u -rd99ea57e5e78d9b2cc7d6024d9f26f2b4da7cc86 -rc72f797f7e7795e3ff15dc2ed832032ee6bafd0a --- src/ictranslate/ICTranslateDlg.h (.../ICTranslateDlg.h) (revision d99ea57e5e78d9b2cc7d6024d9f26f2b4da7cc86) +++ src/ictranslate/ICTranslateDlg.h (.../ICTranslateDlg.h) (revision c72f797f7e7795e3ff15dc2ed832032ee6bafd0a) @@ -30,6 +30,8 @@ static int CALLBACK ListSortFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort); + bool WarnModified() const; + // Implementation protected: HICON m_hIcon; @@ -69,6 +71,8 @@ afx_msg void OnBnClickedChooseFontButton(); afx_msg void OnEditCleanupTranslation(); afx_msg void OnFileNewTranslation(); - afx_msg void OnFileSavetranslationAs(); + afx_msg void OnFileSaveTranslationAs(); afx_msg void OnFileSaveTranslation(); +protected: + virtual void OnCancel(); }; Index: src/libictranslate/ResourceManager.cpp =================================================================== diff -u -r321b486ce9e2b11c82cf5326832605a1150e1653 -rc72f797f7e7795e3ff15dc2ed832032ee6bafd0a --- src/libictranslate/ResourceManager.cpp (.../ResourceManager.cpp) (revision 321b486ce9e2b11c82cf5326832605a1150e1653) +++ src/libictranslate/ResourceManager.cpp (.../ResourceManager.cpp) (revision c72f797f7e7795e3ff15dc2ed832032ee6bafd0a) @@ -159,7 +159,8 @@ m_pszAuthor(NULL), m_bRTL(false), m_uiSectionID(0), - m_bUpdating(false) + m_bUpdating(false), + m_bModified(false) { } @@ -184,6 +185,11 @@ m_pszHelpName = NULL; delete [] m_pszAuthor; m_pszAuthor = NULL; + m_bModified = false; + m_bRTL = false; + m_bUpdating = false; + m_uiSectionID = 0; + m_wPointSize = 0; m_mapTranslation.clear(); } @@ -193,7 +199,12 @@ m_pszLngName(NULL), m_pszFontFace(NULL), m_pszHelpName(NULL), - m_pszAuthor(NULL) + m_pszAuthor(NULL), + m_bRTL(ld.m_bRTL), + m_bUpdating(ld.m_bUpdating), + m_uiSectionID(ld.m_uiSectionID), + m_wPointSize(ld.m_wPointSize), + m_bModified(false) { SetFilename(ld.GetFilename(true)); SetLangName(ld.GetLangName()); @@ -202,6 +213,8 @@ SetDirection(ld.GetDirection()); SetHelpName(ld.GetHelpName()); SetAuthor(ld.GetAuthor()); + + m_mapTranslation.insert(ld.m_mapTranslation.begin(), ld.m_mapTranslation.end()); } CLangData& CLangData::operator=(const CLangData& rSrc) @@ -215,6 +228,13 @@ SetDirection(rSrc.GetDirection()); SetHelpName(rSrc.GetHelpName()); SetAuthor(rSrc.GetAuthor()); + m_bRTL = rSrc.m_bRTL; + m_bUpdating = rSrc.m_bUpdating; + m_uiSectionID = rSrc.m_uiSectionID; + m_wPointSize = rSrc.m_wPointSize; + m_bModified = false; + + m_mapTranslation.insert(rSrc.m_mapTranslation.begin(), rSrc.m_mapTranslation.end()); } return *this; @@ -224,6 +244,8 @@ { try { + Clear(); + icpf::config cfg(icpf::config::eIni); const uint_t uiLangName = cfg.register_string(_T("Info/Lang Name"), _t("")); const uint_t uiFontFace = cfg.register_string(_T("Info/Font Face"), _T("")); @@ -262,6 +284,8 @@ SetFilename(pszFile); + m_bModified = false; + return true; } catch(...) @@ -432,6 +456,8 @@ SetFilename(pszFile); + m_bModified = false; + return true; } catch(...) @@ -486,6 +512,8 @@ else SetFilename(pszPath); cfg.write(pszPath); + + m_bModified = false; } PCTSTR CLangData::GetString(WORD wHiID, WORD wLoID) @@ -516,7 +544,10 @@ { std::pair pairTranslation = m_mapTranslation.insert(std::make_pair(uiTranslationKey, CTranslationItem())); if(pairTranslation.second) + { + m_bModified = true; return &(*pairTranslation.first).second; + } } } @@ -536,6 +567,7 @@ { if(!rReferenceTranslation.Exists((*iterTranslation).first)) { + m_bModified = true; m_mapTranslation.erase(iterTranslation++); } else @@ -551,6 +583,8 @@ // copy m_pszFilename=new TCHAR[_tcslen(psz)+1]; _tcscpy(m_pszFilename, psz); + + m_bModified = true; } PCTSTR CLangData::GetFilename(bool bFullPath) const @@ -576,6 +610,7 @@ delete [] m_pszLngName; m_pszLngName=new TCHAR[_tcslen(psz)+1]; _tcscpy(m_pszLngName, psz); + m_bModified = true; } void CLangData::SetFontFace(PCTSTR psz) @@ -584,11 +619,13 @@ delete [] m_pszFontFace; m_pszFontFace=new TCHAR[_tcslen(psz)+1]; _tcscpy(m_pszFontFace, psz); + m_bModified = true; } void CLangData::SetHelpName(PCTSTR psz) { SetFnameData(&m_pszHelpName, psz); + m_bModified = true; } void CLangData::SetAuthor(PCTSTR psz) @@ -597,6 +634,7 @@ delete [] m_pszAuthor; m_pszAuthor=new TCHAR[_tcslen(psz)+1]; _tcscpy(m_pszAuthor, psz); + m_bModified = true; } void CLangData::SetFnameData(PTSTR *ppszDst, PCTSTR pszSrc) Index: src/libictranslate/ResourceManager.h =================================================================== diff -u -r321b486ce9e2b11c82cf5326832605a1150e1653 -rc72f797f7e7795e3ff15dc2ed832032ee6bafd0a --- src/libictranslate/ResourceManager.h (.../ResourceManager.h) (revision 321b486ce9e2b11c82cf5326832605a1150e1653) +++ src/libictranslate/ResourceManager.h (.../ResourceManager.h) (revision c72f797f7e7795e3ff15dc2ed832032ee6bafd0a) @@ -115,6 +115,9 @@ void SetAuthor(PCTSTR psz); PCTSTR GetAuthor() const { return m_pszAuthor; }; + bool IsModified() const { return m_bModified; } + void SetModified() { m_bModified = true; } + protected: void SetFnameData(PTSTR *ppszDst, PCTSTR pszSrc); static void EnumAttributesCallback(bool bGroup, const tchar_t* pszName, const tchar_t* pszValue, ptr_t pData); @@ -136,6 +139,7 @@ private: uint_t m_uiSectionID; ///< ID of the currently processed section bool m_bUpdating; ///< Are we updating the language with base language ? + bool m_bModified; ///< States if the translation has been modified }; /////////////////////////////////////////////////////////////////////////////////////