#include "StdAfx.h"
#include "LanguageSelect.h"
#include <locale.h>
-#include <sstream>
-#include "OptionsDef.h"
-#include "OptionsMgr.h"
-#include "Merge.h"
#include "version.h"
-#include "resource.h"
#include "BCMenu.h"
-#include "MainFrm.h"
-#include "OpenFrm.h"
-#include "ChildFrm.h"
-#include "DirFrame.h"
-#include "HexMergeFrm.h"
-#include "ImgMergeFrm.h"
-#include "paths.h"
#include "Environment.h"
// Escaped character constants in range 0x80-0xFF are interpreted in current codepage
/** @brief Default English language. */
const WORD wSourceLangId = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
-CLanguageSelect::CLanguageSelect(UINT idMainMenu, UINT idDocMenu, BOOL bReloadMenu /*=TRUE*/, BOOL bUpdateTitle /*=TRUE*/, CWnd* pParent /*=NULL*/)
-: CDialog(CLanguageSelect::IDD, pParent)
-, m_hCurrentDll(0)
+CLanguageSelect::CLanguageSelect()
+: m_hCurrentDll(0)
, m_wCurLanguage(wSourceLangId)
-, m_idMainMenu(idMainMenu)
-, m_idDocMenu(idDocMenu)
-, m_hModule(NULL)
-, m_bReloadMenu(bReloadMenu)
-, m_bUpdateTitle(bUpdateTitle)
{
SetThreadLocale(MAKELCID(m_wCurLanguage, SORT_DEFAULT));
}
-void CLanguageSelect::DoDataExchange(CDataExchange* pDX)
-{
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CLanguageSelect)
- DDX_Control(pDX, IDC_LANGUAGE_LIST, m_ctlLangList);
- //}}AFX_DATA_MAP
-}
-
-BEGIN_MESSAGE_MAP(CLanguageSelect, CDialog)
-//{{AFX_MSG_MAP(CLanguageSelect)
- ON_LBN_DBLCLK(IDC_LANGUAGE_LIST, OnOK)
-//}}AFX_MSG_MAP
-END_MESSAGE_MAP()
-
/**
* @brief Remove prefix from the string.
* @param [in] text String from which to jump over prefix.
* @param [in] wLangId
* @return TRUE on success, FALSE otherwise.
*/
-BOOL CLanguageSelect::LoadLanguageFile(LANGID wLangId)
+BOOL CLanguageSelect::LoadLanguageFile(LANGID wLangId, BOOL bShowError)
{
String strPath = GetFileName(wLangId);
if (strPath.empty())
// translation system, so go without string resources here.
if (m_hCurrentDll == 0)
{
- if (m_hWnd)
+ if (bShowError)
AfxMessageBox(_T("Failed to load MergeLang.dll"), MB_ICONSTOP);
return FALSE;
}
{
FreeLibrary(m_hCurrentDll);
m_hCurrentDll = 0;
- if (m_hWnd)
+ if (bShowError)
AfxMessageBox(_T("MergeLang.dll version mismatch"), MB_ICONSTOP);
return FALSE;
}
HRSRC mergepot = FindResource(m_hCurrentDll, _T("MERGEPOT"), RT_RCDATA);
if (mergepot == 0)
{
- if (m_hWnd)
+ if (bShowError)
AfxMessageBox(_T("MergeLang.dll is invalid"), MB_ICONSTOP);
return FALSE;
}
{
FreeLibrary(m_hCurrentDll);
m_hCurrentDll = 0;
- if (m_hWnd)
+ if (bShowError)
{
- std_tchar(ostringstream) stm;
- stm << _T("Failed to load ") << strPath.c_str();
- AfxMessageBox(stm.str().c_str(), MB_ICONSTOP);
+ String str = _T("Failed to load ") + strPath;
+ AfxMessageBox(str.c_str(), MB_ICONSTOP);
}
return FALSE;
}
m_hCurrentDll = 0;
m_strarray.clear();
m_codepage = 0;
- if (m_hWnd)
+ if (bShowError)
{
- std_tchar(ostringstream) stm;
- stm << _T("Unresolved or mismatched references detected when ")
- _T("attempting to read translations from\n") << strPath.c_str();
- AfxMessageBox(stm.str().c_str(), MB_ICONSTOP);
+ String str = _T("Unresolved or mismatched references detected when ")
+ _T("attempting to read translations from\n") + strPath;
+ AfxMessageBox(str.c_str(), MB_ICONSTOP);
}
return FALSE;
}
* @param [in] wLangId
* @return TRUE on success, FALSE otherwise.
*/
-BOOL CLanguageSelect::SetLanguage(LANGID wLangId)
+BOOL CLanguageSelect::SetLanguage(LANGID wLangId, BOOL bShowError)
{
if (wLangId == 0)
return FALSE;
m_codepage = 0;
if (wLangId != wSourceLangId)
{
- if (LoadLanguageFile(wLangId))
+ if (LoadLanguageFile(wLangId, bShowError))
AfxSetResourceHandle(m_hCurrentDll);
else
wLangId = wSourceLangId;
return filename;
}
-/**
- * @brief Check if there are language files installed.
- *
- * This function does as fast as possible check for installed language
- * files. It needs to be fast since it is used in enabling/disabling
- * GUI item(s). So the simple check we do is just find one .po file.
- * If there is a .po file we assume we have at least one language
- * installed.
- * @return TRUE if at least one lang file is found. FALSE if no lang
- * files are found.
- */
-BOOL CLanguageSelect::AreLangsInstalled() const
-{
- BOOL bFound = FALSE;
- String path = env_GetProgPath().append(szRelativePath);
- String pattern = path + _T("*.po");
- WIN32_FIND_DATA ff;
- HANDLE h = INVALID_HANDLE_VALUE;
- while ((h = FindFile(h, pattern.c_str(), &ff)) != INVALID_HANDLE_VALUE)
- {
- ff.dwFileAttributes = INVALID_FILE_ATTRIBUTES;
- bFound = TRUE;
- }
- return bFound;
-}
-
/////////////////////////////////////////////////////////////////////////////
// CLanguageSelect commands
return s;
}
-void CLanguageSelect::ReloadMenu()
-{
- if (m_idDocMenu)
- {
- // set the menu of the main frame window
- UINT idMenu = GetDocResId();
- CMergeApp *pApp = dynamic_cast<CMergeApp *> (AfxGetApp());
- CMainFrame * pMainFrame = dynamic_cast<CMainFrame *> ((CFrameWnd*)pApp->m_pMainWnd);
- HMENU hNewDefaultMenu = pMainFrame->NewDefaultMenu(idMenu);
- HMENU hNewMergeMenu = pMainFrame->NewMergeViewMenu();
- HMENU hNewImgMergeMenu = pMainFrame->NewImgMergeViewMenu();
- HMENU hNewDirMenu = pMainFrame->NewDirViewMenu();
- if (hNewDefaultMenu && hNewMergeMenu && hNewDirMenu)
- {
- // Note : for Windows98 compatibility, use FromHandle and not Attach/Detach
- CMenu * pNewDefaultMenu = CMenu::FromHandle(hNewDefaultMenu);
- CMenu * pNewMergeMenu = CMenu::FromHandle(hNewMergeMenu);
- CMenu * pNewImgMergeMenu = CMenu::FromHandle(hNewImgMergeMenu);
- CMenu * pNewDirMenu = CMenu::FromHandle(hNewDirMenu);
-
- CWnd *pFrame = CWnd::FromHandle(::GetWindow(pMainFrame->m_hWndMDIClient, GW_CHILD));
- while (pFrame)
- {
- if (pFrame->IsKindOf(RUNTIME_CLASS(CChildFrame)))
- static_cast<CChildFrame *>(pFrame)->SetSharedMenu(hNewMergeMenu);
- if (pFrame->IsKindOf(RUNTIME_CLASS(CHexMergeFrame)))
- static_cast<CHexMergeFrame *>(pFrame)->SetSharedMenu(hNewMergeMenu);
- if (pFrame->IsKindOf(RUNTIME_CLASS(CImgMergeFrame)))
- static_cast<CImgMergeFrame *>(pFrame)->SetSharedMenu(hNewImgMergeMenu);
- else if (pFrame->IsKindOf(RUNTIME_CLASS(COpenFrame)))
- static_cast<COpenFrame *>(pFrame)->SetSharedMenu(hNewDefaultMenu);
- else if (pFrame->IsKindOf(RUNTIME_CLASS(CDirFrame)))
- static_cast<CDirFrame *>(pFrame)->SetSharedMenu(hNewDirMenu);
- pFrame = pFrame->GetNextWindow();
- }
-
- CFrameWnd *pActiveFrame = pMainFrame->GetActiveFrame();
- if (pActiveFrame)
- {
- if (pActiveFrame->IsKindOf(RUNTIME_CLASS(CChildFrame)))
- pMainFrame->MDISetMenu(pNewMergeMenu, NULL);
- else if (pActiveFrame->IsKindOf(RUNTIME_CLASS(CHexMergeFrame)))
- pMainFrame->MDISetMenu(pNewMergeMenu, NULL);
- else if (pActiveFrame->IsKindOf(RUNTIME_CLASS(CImgMergeFrame)))
- pMainFrame->MDISetMenu(pNewImgMergeMenu, NULL);
- else if (pActiveFrame->IsKindOf(RUNTIME_CLASS(CDirFrame)))
- pMainFrame->MDISetMenu(pNewDirMenu, NULL);
- else
- pMainFrame->MDISetMenu(pNewDefaultMenu, NULL);
- }
- else
- pMainFrame->MDISetMenu(pNewDefaultMenu, NULL);
-
- // Don't delete the old menu
- // There is a bug in BCMenu or in Windows98 : the new menu does not
- // appear correctly if we destroy the old one
-// if (pOldDefaultMenu)
-// pOldDefaultMenu->DestroyMenu();
-// if (pOldMergeMenu)
-// pOldMergeMenu->DestroyMenu();
-// if (pOldDirMenu)
-// pOldDirMenu->DestroyMenu();
-
- // m_hMenuDefault is used to redraw the main menu when we close a child frame
- // if this child frame had a different menu
- pMainFrame->m_hMenuDefault = hNewDefaultMenu;
- pApp->m_pOpenTemplate->m_hMenuShared = hNewDefaultMenu;
- pApp->m_pDiffTemplate->m_hMenuShared = hNewMergeMenu;
- pApp->m_pDirTemplate->m_hMenuShared = hNewDirMenu;
-
- // force redrawing the menu bar
- pMainFrame->DrawMenuBar();
-
- }
- }
-}
-
-
-UINT CLanguageSelect::GetDocResId() const
-{
- if (((CMDIFrameWnd*)AfxGetApp()->m_pMainWnd)->MDIGetActive())
- return m_idDocMenu;
-
- return m_idMainMenu;
-}
-
-
-void CLanguageSelect::UpdateDocTitle()
-{
- CDocManager* pDocManager = AfxGetApp()->m_pDocManager;
- POSITION posTemplate = pDocManager->GetFirstDocTemplatePosition();
- ASSERT(posTemplate != NULL);
-
- while (posTemplate != NULL)
- {
- CDocTemplate* pTemplate = pDocManager->GetNextDocTemplate(posTemplate);
-
- ASSERT(pTemplate != NULL);
-
- POSITION pos = pTemplate->GetFirstDocPosition();
- CDocument* pDoc;
-
- while ( pos != NULL )
- {
- pDoc = pTemplate->GetNextDoc(pos);
- pDoc->SetTitle(NULL);
- ((CFrameWnd*)AfxGetApp()->m_pMainWnd)->OnUpdateFrameTitle(TRUE);
- }
- }
-}
-
-
-
-void CLanguageSelect::OnOK()
-{
- UpdateData();
- int index = m_ctlLangList.GetCurSel();
- if (index<0) return;
- //int i = m_ctlLangList.GetItemData(index);
- WORD lang = (WORD)m_ctlLangList.GetItemData(index); //m_wLangIds[i];
- if (lang != m_wCurLanguage)
- {
- if (SetLanguage(lang))
- GetOptionsMgr()->SaveOption(OPT_SELECTED_LANGUAGE, (int)lang);
-
- theApp.UpdateCodepageModule();
-
- // Update status bar inicator texts
- SetIndicators(GetMainFrame()->m_wndStatusBar, 0, 0);
-
- // Update the current menu
- if (m_bReloadMenu)
- ReloadMenu();
-
- // update the title text of the document
- if (m_bUpdateTitle)
- UpdateDocTitle();
- }
-
- EndDialog(IDOK);
-}
-
-BOOL CLanguageSelect::OnInitDialog()
-{
- TranslateDialog(m_hWnd);
- CDialog::OnInitDialog();
-
- // setup handler for resizing this dialog
- m_constraint.InitializeCurrentSize(this);
- // configure how individual controls adjust when dialog resizes
- m_constraint.ConstrainItem(IDC_LANGUAGE_LIST, 0, 1, 0, 1); // grows right & down
- m_constraint.ConstrainItem(IDCANCEL, .6, 0, 1, 0); // slides down, floats right
- m_constraint.ConstrainItem(IDOK, .3, 0, 1, 0); // slides down, floats right
- m_constraint.SubclassWnd(); // install subclassing
- m_constraint.LoadPosition(_T("ResizeableDialogs"), _T("LanguageSelectDlg"), false); // persist size via registry
-
- AfxGetMainWnd()->CenterWindow(this);
-
- LoadAndDisplayLanguages();
-
- return TRUE;
-}
-
/**
* @brief Load languages available on disk, and display in list, and select current
*/
-void CLanguageSelect::LoadAndDisplayLanguages()
+std::vector<std::pair<LANGID, String> > CLanguageSelect::GetAvailableLanguages() const
{
+ std::vector<std::pair<LANGID, String> > list;
String path = env_GetProgPath().append(szRelativePath);
String pattern = path + _T("*.po");
WIN32_FIND_DATA ff;
h == INVALID_HANDLE_VALUE
? LangFileInfo(wSourceLangId)
: LangFileInfo((path + ff.cFileName).c_str());
- std_tchar(ostringstream) stm;
- stm << lfi.GetString(LOCALE_SLANGUAGE).c_str();
- stm << _T(" - ");
- stm << lfi.GetString(LOCALE_SNATIVELANGNAME|LOCALE_USE_CP_ACP).c_str();
- stm << _T(" (");
- stm << lfi.GetString(LOCALE_SNATIVECTRYNAME|LOCALE_USE_CP_ACP).c_str();
- stm << _T(")");
- /*stm << _T(" - ");
- stm << lfi.GetString(LOCALE_SABBREVLANGNAME|LOCALE_USE_CP_ACP).c_str();
- stm << _T(" (");
- stm << lfi.GetString(LOCALE_SABBREVCTRYNAME|LOCALE_USE_CP_ACP).c_str();
- stm << _T(") ");*/
- stm << _T(" - ");
- stm << lfi.GetString(LOCALE_SENGLANGUAGE).c_str();
- stm << _T(" (");
- stm << lfi.GetString(LOCALE_SENGCOUNTRY).c_str();
- stm << _T(")");
- int i = m_ctlLangList.AddString(stm.str().c_str());
- m_ctlLangList.SetItemData(i, lfi.id);
- if (lfi.id == m_wCurLanguage)
- m_ctlLangList.SetCurSel(i);
+ String str;
+ str += lfi.GetString(LOCALE_SLANGUAGE);
+ str += _T(" - ");
+ str += lfi.GetString(LOCALE_SNATIVELANGNAME | LOCALE_USE_CP_ACP);
+ str += _T(" (");
+ str += lfi.GetString(LOCALE_SNATIVECTRYNAME | LOCALE_USE_CP_ACP);
+ str += _T(")");
+ str += _T(" - ");
+ str += lfi.GetString(LOCALE_SENGLANGUAGE);
+ str += _T(" (");
+ str += lfi.GetString(LOCALE_SENGCOUNTRY);
+ str += _T(")");
+ list.emplace_back(lfi.id, str);
} while ((h = FindFile(h, pattern.c_str(), &ff)) != INVALID_HANDLE_VALUE);
+ return list;
}
/**
return langID;
}
-void CLanguageSelect::InitializeLanguage()
+void CLanguageSelect::InitializeLanguage(WORD langID)
{
ASSERT(LangFileInfo::LangId("GERMAN", "") == MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN));
ASSERT(LangFileInfo::LangId("GERMAN", "DEFAULT") == MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT));
//TRACE(_T("%hs\n"), LangFileInfo::FileName(MAKELANGID(LANG_PORTUGUESE, SUBLANG_PORTUGUESE)).c_str());
//TRACE(_T("%hs\n"), LangFileInfo::FileName(MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT)).c_str());
- WORD langID = (WORD)GetOptionsMgr()->GetInt(OPT_SELECTED_LANGUAGE);
if (langID)
{
// User has set a language override
*/
#pragma once
-#include "CMoveConstraint.h"
-
#include <vector>
#include <string>
/////////////////////////////////////////////////////////////////////////////
-// CLanguageSelect dialog
+// CLanguageSelect class
/**
- * @brief Dialog for selecting GUI language.
+ * @brief Class for selecting GUI language.
*
* Language select dialog shows list of installed GUI languages and
* allows user to select one for use.
*/
-class CLanguageSelect : public CDialog
+class CLanguageSelect
{
// Construction
public:
- void SetModuleHandle(HMODULE hModule) { m_hModule = hModule; }
- CLanguageSelect(UINT idMainMenu, UINT idDocMenu, BOOL bReloadMenu =TRUE, BOOL bUpdateTitle =TRUE, CWnd* pParent = NULL); // standard constructor
- BOOL AreLangsInstalled() const;
+ CLanguageSelect(); // standard constructor
WORD GetLangId() const { return m_wCurLanguage; }
- void InitializeLanguage();
- void UpdateDocTitle();
- void ReloadMenu();
+ void InitializeLanguage(WORD langID);
bool TranslateString(size_t line, std::string &) const;
bool TranslateString(size_t line, std::wstring &) const;
void TranslateDialog(HWND) const;
String LoadString(UINT) const;
std::wstring LoadDialogCaption(LPCTSTR lpDialogTemplateID) const;
+ std::vector<std::pair<LANGID, String> > GetAvailableLanguages() const;
+ BOOL SetLanguage(LANGID, BOOL bShowError = FALSE);
// Implementation data
private:
- prdlg::CMoveConstraint m_constraint;
- BOOL m_bReloadMenu;
- BOOL m_bUpdateTitle;
- HMODULE m_hModule;
- UINT m_idMainMenu;
- UINT m_idDocMenu;
HINSTANCE m_hCurrentDll;
LANGID m_wCurLanguage;
std::vector<std::string> m_strarray;
// Implementation methods
private:
String GetFileName(LANGID) const;
- BOOL LoadLanguageFile(LANGID);
- BOOL SetLanguage(LANGID);
- UINT GetDocResId() const;
- void LoadAndDisplayLanguages();
-
-// Dialog Data
- //{{AFX_DATA(CLanguageSelect)
- enum { IDD = IDD_LANGUAGE_SELECT };
- CListBox m_ctlLangList;
- //}}AFX_DATA
-
-
-// Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CLanguageSelect)
- public:
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
-
-
- // Generated message map functions
- //{{AFX_MSG(CLanguageSelect)
- virtual void OnOK();
- virtual BOOL OnInitDialog();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
+ BOOL LoadLanguageFile(LANGID, BOOL bShowError = FALSE);
};
-
-
-
-
-//{{AFX_INSERT_LOCATION}}
-// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#include "TFile.h"
#include "JumpList.h"
#include "DragDrop.h"
+#include "LanguageSelect.h"
using std::vector;
{ ID_WINDOW_CHANGE_PANE, IDB_WINDOW_CHANGEPANE, CMainFrame::MENU_ALL },
{ ID_EDIT_WMGOTO, IDB_EDIT_GOTO, CMainFrame::MENU_ALL },
{ ID_EDIT_REPLACE, IDB_EDIT_REPLACE, CMainFrame::MENU_ALL },
- { ID_VIEW_LANGUAGE, IDB_VIEW_LANGUAGE, CMainFrame::MENU_ALL },
{ ID_VIEW_SELECTFONT, IDB_VIEW_SELECTFONT, CMainFrame::MENU_ALL },
{ ID_APP_EXIT, IDB_FILE_EXIT, CMainFrame::MENU_ALL },
{ ID_HELP_CONTENTS, IDB_HELP_CONTENTS, CMainFrame::MENU_ALL },
{
// Using singleton shared syntax colors
CPreferencesDlg dlg(GetOptionsMgr(), theApp.GetMainSyntaxColors());
- int rv = dlg.DoModal();
+ INT_PTR rv = dlg.DoModal();
if (rv == IDOK)
{
+ LANGID lang = GetOptionsMgr()->GetInt(OPT_SELECTED_LANGUAGE);
+ if (lang != theApp.m_pLangDlg->GetLangId())
+ {
+ theApp.m_pLangDlg->SetLanguage(lang, TRUE);
+
+ // Update status bar inicator texts
+ theApp.SetIndicators(m_wndStatusBar, 0, 0);
+
+ // Update the current menu
+ ReloadMenu();
+
+ // update the title text of the document
+ UpdateDocTitle();
+
+ UpdateResources();
+ }
+
// Set new filterpath
String filterPath = GetOptionsMgr()->GetString(OPT_FILTER_USERPATH);
theApp.m_pGlobalFileFilter->SetUserFilterPath(filterPath);
return CMDIFrameWnd::WindowProc(message, wParam, lParam);
}
+
+void CMainFrame::ReloadMenu()
+{
+ // set the menu of the main frame window
+ UINT idMenu = IDR_MAINFRAME;
+ CMergeApp *pApp = dynamic_cast<CMergeApp *> (AfxGetApp());
+ CMainFrame * pMainFrame = dynamic_cast<CMainFrame *> ((CFrameWnd*)pApp->m_pMainWnd);
+ HMENU hNewDefaultMenu = pMainFrame->NewDefaultMenu(idMenu);
+ HMENU hNewMergeMenu = pMainFrame->NewMergeViewMenu();
+ HMENU hNewImgMergeMenu = pMainFrame->NewImgMergeViewMenu();
+ HMENU hNewDirMenu = pMainFrame->NewDirViewMenu();
+ if (hNewDefaultMenu && hNewMergeMenu && hNewDirMenu)
+ {
+ // Note : for Windows98 compatibility, use FromHandle and not Attach/Detach
+ CMenu * pNewDefaultMenu = CMenu::FromHandle(hNewDefaultMenu);
+ CMenu * pNewMergeMenu = CMenu::FromHandle(hNewMergeMenu);
+ CMenu * pNewImgMergeMenu = CMenu::FromHandle(hNewImgMergeMenu);
+ CMenu * pNewDirMenu = CMenu::FromHandle(hNewDirMenu);
+
+ CWnd *pFrame = CWnd::FromHandle(::GetWindow(pMainFrame->m_hWndMDIClient, GW_CHILD));
+ while (pFrame)
+ {
+ if (pFrame->IsKindOf(RUNTIME_CLASS(CChildFrame)))
+ static_cast<CChildFrame *>(pFrame)->SetSharedMenu(hNewMergeMenu);
+ if (pFrame->IsKindOf(RUNTIME_CLASS(CHexMergeFrame)))
+ static_cast<CHexMergeFrame *>(pFrame)->SetSharedMenu(hNewMergeMenu);
+ if (pFrame->IsKindOf(RUNTIME_CLASS(CImgMergeFrame)))
+ static_cast<CImgMergeFrame *>(pFrame)->SetSharedMenu(hNewImgMergeMenu);
+ else if (pFrame->IsKindOf(RUNTIME_CLASS(COpenFrame)))
+ static_cast<COpenFrame *>(pFrame)->SetSharedMenu(hNewDefaultMenu);
+ else if (pFrame->IsKindOf(RUNTIME_CLASS(CDirFrame)))
+ static_cast<CDirFrame *>(pFrame)->SetSharedMenu(hNewDirMenu);
+ pFrame = pFrame->GetNextWindow();
+ }
+
+ CFrameWnd *pActiveFrame = pMainFrame->GetActiveFrame();
+ if (pActiveFrame)
+ {
+ if (pActiveFrame->IsKindOf(RUNTIME_CLASS(CChildFrame)))
+ pMainFrame->MDISetMenu(pNewMergeMenu, NULL);
+ else if (pActiveFrame->IsKindOf(RUNTIME_CLASS(CHexMergeFrame)))
+ pMainFrame->MDISetMenu(pNewMergeMenu, NULL);
+ else if (pActiveFrame->IsKindOf(RUNTIME_CLASS(CImgMergeFrame)))
+ pMainFrame->MDISetMenu(pNewImgMergeMenu, NULL);
+ else if (pActiveFrame->IsKindOf(RUNTIME_CLASS(CDirFrame)))
+ pMainFrame->MDISetMenu(pNewDirMenu, NULL);
+ else
+ pMainFrame->MDISetMenu(pNewDefaultMenu, NULL);
+ }
+ else
+ pMainFrame->MDISetMenu(pNewDefaultMenu, NULL);
+
+ // Don't delete the old menu
+ // There is a bug in BCMenu or in Windows98 : the new menu does not
+ // appear correctly if we destroy the old one
+ // if (pOldDefaultMenu)
+ // pOldDefaultMenu->DestroyMenu();
+ // if (pOldMergeMenu)
+ // pOldMergeMenu->DestroyMenu();
+ // if (pOldDirMenu)
+ // pOldDirMenu->DestroyMenu();
+
+ // m_hMenuDefault is used to redraw the main menu when we close a child frame
+ // if this child frame had a different menu
+ pMainFrame->m_hMenuDefault = hNewDefaultMenu;
+ pApp->m_pOpenTemplate->m_hMenuShared = hNewDefaultMenu;
+ pApp->m_pDiffTemplate->m_hMenuShared = hNewMergeMenu;
+ pApp->m_pDirTemplate->m_hMenuShared = hNewDirMenu;
+
+ // force redrawing the menu bar
+ pMainFrame->DrawMenuBar();
+ }
+}
+
+void CMainFrame::UpdateDocTitle()
+{
+ CDocManager* pDocManager = AfxGetApp()->m_pDocManager;
+ POSITION posTemplate = pDocManager->GetFirstDocTemplatePosition();
+ ASSERT(posTemplate != NULL);
+
+ while (posTemplate != NULL)
+ {
+ CDocTemplate* pTemplate = pDocManager->GetNextDocTemplate(posTemplate);
+
+ ASSERT(pTemplate != NULL);
+
+ POSITION pos = pTemplate->GetFirstDocPosition();
+ CDocument* pDoc;
+
+ while (pos != NULL)
+ {
+ pDoc = pTemplate->GetNextDoc(pos);
+ pDoc->SetTitle(NULL);
+ ((CFrameWnd*)AfxGetApp()->m_pMainWnd)->OnUpdateFrameTitle(TRUE);
+ }
+ }
+}
bool AskCloseConfirmation();
BOOL DoOpenConflict(const String& conflictFile, bool checked = false);
FRAMETYPE GetFrameType(const CFrameWnd * pFrame) const;
+ void UpdateDocTitle();
+ void ReloadMenu();
// Overrides
virtual void GetMessageString(UINT nID, CString& rMessage) const;
BEGIN_MESSAGE_MAP(CMergeApp, CWinApp)
//{{AFX_MSG_MAP(CMergeApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
- ON_COMMAND(ID_VIEW_LANGUAGE, OnViewLanguage)
- ON_UPDATE_COMMAND_UI(ID_VIEW_LANGUAGE, OnUpdateViewLanguage)
ON_COMMAND(ID_HELP, OnHelp)
ON_COMMAND_EX_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE16, OnOpenRecentFile)
ON_COMMAND(ID_FILE_MERGINGMODE, OnMergingMode)
, m_pOptions(new CRegOptionsMgr())
, m_pGlobalFileFilter(new FileFilterHelper())
, m_nActiveOperations(0)
-, m_pLangDlg(new CLanguageSelect(IDR_MAINFRAME, IDR_MAINFRAME))
+, m_pLangDlg(new CLanguageSelect())
, m_bEscShutdown(FALSE)
, m_bClearCaseTool(FALSE)
, m_bExitIfNoDiff(MergeCmdLineInfo::Disabled)
// Initialize i18n (multiple language) support
- m_pLangDlg->InitializeLanguage();
+ m_pLangDlg->InitializeLanguage((WORD)GetOptionsMgr()->GetInt(OPT_SELECTED_LANGUAGE));
AddEnglishResourceHook(); // Use English string when l10n (foreign) string missing
/////////////////////////////////////////////////////////////////////////////
// CMergeApp commands
-
-void CMergeApp::OnViewLanguage()
-{
- if (m_pLangDlg->DoModal()==IDOK)
- {
- //m_lang.ReloadMenu();
- //m_LangDlg.UpdateDocTitle();
- GetMainFrame()->UpdateResources();
- }
-}
-
-/**
- * @brief Updates Language select menu item.
- * If there are no languages installed we disable menuitem to
- * open language selection dialog.
- */
-void CMergeApp::OnUpdateViewLanguage(CCmdUI* pCmdUI)
-{
- BOOL bLangsInstalled = m_pLangDlg->AreLangsInstalled();
- pCmdUI->Enable(bLangsInstalled);
-}
-
/**
* @brief Called when application is about to exit.
* This functions is called when application is exiting, so this is
}
/**
- * @brief Reload main menu(s) (for language change)
- */
-void CMergeApp::ReloadMenu()
-{
- m_pLangDlg->ReloadMenu();
-}
-
-/**
* @brief Get default editor path.
* @return full path to the editor program executable.
*/
bool LoadAndOpenProjectFile(const String& sFilepath);
bool IsProjectFile(const String& filepath) const;
- void ReloadMenu();
-
//@{
/**
* @name Active operations counter.
//{{AFX_MSG(CMergeApp)
afx_msg BOOL OnOpenRecentFile(UINT nID);
afx_msg void OnAppAbout();
- afx_msg void OnViewLanguage();
- afx_msg void OnUpdateViewLanguage(CCmdUI* pCmdUI);
afx_msg void OnHelp();
afx_msg void OnMergingMode();
afx_msg void OnUpdateMergingMode(CCmdUI* pCmdUI);
END
MENUITEM "&Status Bar", ID_VIEW_STATUS_BAR
MENUITEM "Ta&b Bar", ID_VIEW_TAB_BAR
- MENUITEM SEPARATOR
- MENUITEM "&Language...", ID_VIEW_LANGUAGE
END
POPUP "&Tools"
BEGIN
END
MENUITEM "&Status Bar", ID_VIEW_STATUS_BAR
MENUITEM "Ta&b Bar", ID_VIEW_TAB_BAR
- MENUITEM "Compa&re Statistics", ID_VIEW_DIR_STATISTICS
MENUITEM SEPARATOR
- MENUITEM "&Language...", ID_VIEW_LANGUAGE
+ MENUITEM "Compa&re Statistics", ID_VIEW_DIR_STATISTICS
MENUITEM SEPARATOR
MENUITEM "Refre&sh\tF5", ID_REFRESH
MENUITEM "&Refresh Selected\tCtrl+F5", ID_RESCAN
MENUITEM "Diff &Pane", ID_VIEW_DETAIL_BAR
MENUITEM "Lo&cation Pane", ID_VIEW_LOCATION_BAR
MENUITEM SEPARATOR
- MENUITEM "&Language...", ID_VIEW_LANGUAGE
- MENUITEM SEPARATOR
MENUITEM "Refre&sh\tF5", ID_REFRESH
END
POPUP "&Merge"
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,141,206,10
CONTROL "Fil&e compare",IDC_MULTIDOC_FILECMP,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,151,206,10
+ LTEXT "Language:",IDC_STATIC,7,171,80,8
+ COMBOBOX IDC_LANGUAGE_LIST,7,181,221,41,CBS_DROPDOWNLIST |
+ WS_VSCROLL | WS_TABSTOP
LTEXT "WinMerge allows hiding some common messageboxes. Press the Reset button to make all messageboxes visible again.",
- IDC_STATIC,7,173,168,31
- PUSHBUTTON "Reset",IDC_RESET_ALL_MESSAGE_BOXES,178,180,50,14,NOT
+ IDC_STATIC,7,198,168,31
+ PUSHBUTTON "Reset",IDC_RESET_ALL_MESSAGE_BOXES,178,205,50,14,NOT
WS_TABSTOP
END
-IDD_LANGUAGE_SELECT DIALOGEX 0, 0, 214, 142
-STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION |
- WS_SYSMENU | WS_THICKFRAME
-CAPTION "Language"
-FONT 8, "MS Shell Dlg", 0, 0, 0x1
-BEGIN
- PUSHBUTTON "OK",IDOK,47,123,52,14
- PUSHBUTTON "Cancel",IDCANCEL,115,123,52,14
- LISTBOX IDC_LANGUAGE_LIST,7,16,200,99,LBS_NOINTEGRALHEIGHT |
- WS_VSCROLL | WS_TABSTOP | LBS_SORT
- LTEXT "Available languages:",IDC_STATIC,7,7,140,8
-END
-
IDD_EDIT_FIND DIALOGEX 30, 73, 293, 84
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION |
WS_SYSMENU
ID_VIEW_DETAIL_BAR "Toggle Diff Pane"
ID_VIEW_LOCATION_BAR "Location pane shows overall picture from files"
ID_VIEW_DIR_STATISTICS "Show folder compare statistics dialog"
- ID_VIEW_LANGUAGE "Select the current user interface language\nLanguage"
ID_VIEW_LINEDIFFS "Shows differences inside lines with different colors\nShow Line Difference"
ID_VIEW_SWAPPANES "Swap the positions of the two panes"
ID_VIEW_LINENUMBERS "Shows line numbers\nShow Line Numbers"
IDB_WINDOW_CHANGEPANE BITMAP "res\\change_pane.bmp"
IDB_EDIT_GOTO BITMAP "res\\go_to.bmp"
IDB_EDIT_REPLACE BITMAP "res\\replace.bmp"
-IDB_VIEW_LANGUAGE BITMAP "res\\language.bmp"
IDB_VIEW_SELECTFONT BITMAP "res\\select_font.bmp"
IDB_FILE_EXIT BITMAP "res\\exit.bmp"
IDB_HELP_CONTENTS BITMAP "res\\help_contents.bmp"
#include "OptionsDef.h"
#include "OptionsMgr.h"
#include "OptionsPanel.h"
+#include "LanguageSelect.h"
#ifdef _DEBUG
#define new DEBUG_NEW
pWnd->SetCurSel(m_nAutoCompleteSource);
+ m_ctlLangList.SetDroppedWidth(600);
+
+ for (auto&& i : theApp.m_pLangDlg->GetAvailableLanguages())
+ {
+ m_ctlLangList.AddString(i.second.c_str());
+ m_ctlLangList.SetItemData(m_ctlLangList.GetCount() - 1, i.first);
+ if (i.first == theApp.m_pLangDlg->GetLangId())
+ m_ctlLangList.SetCurSel(m_ctlLangList.GetCount() - 1);
+ }
+
return TRUE; // return TRUE unless you set the focus to a control
}
DDX_Check(pDX, IDC_PRESERVE_FILETIME, m_bPreserveFiletime);
DDX_Check(pDX, IDC_STARTUP_FOLDER_SELECT, m_bShowSelectFolderOnStartup);
DDX_Check(pDX, IDC_CLOSE_WITH_OK, m_bCloseWithOK);
+ DDX_Control(pDX, IDC_LANGUAGE_LIST, m_ctlLangList);
//}}AFX_DATA_MAP
}
GetOptionsMgr()->SaveOption(OPT_PRESERVE_FILETIMES, m_bPreserveFiletime);
GetOptionsMgr()->SaveOption(OPT_SHOW_SELECT_FILES_AT_STARTUP, m_bShowSelectFolderOnStartup);
GetOptionsMgr()->SaveOption(OPT_CLOSE_WITH_OK, m_bCloseWithOK);
+ int index = m_ctlLangList.GetCurSel();
+ if (index >= 0)
+ {
+ WORD lang = (WORD)m_ctlLangList.GetItemData(index);
+ GetOptionsMgr()->SaveOption(OPT_SELECTED_LANGUAGE, (int)lang);
+ }
}
/**
BOOL m_bPreserveFiletime;
BOOL m_bShowSelectFolderOnStartup;
BOOL m_bCloseWithOK;
+ CComboBox m_ctlLangList;
//}}AFX_DATA
#define IDB_WINDOW_CHANGEPANE 324
#define IDB_EDIT_GOTO 325
#define IDB_EDIT_REPLACE 326
-#define IDB_VIEW_LANGUAGE 327
#define IDB_VIEW_SELECTFONT 328
#define IDB_FILE_EXIT 329
#define IDB_HELP_CONTENTS 330
#define IDS_TEXT_REPORT_FILES 18540
#define IDS_HTML_REPORT_FILES 18541
#define IDS_XML_REPORT_FILES 18542
-#define IDD_LANGUAGE_SELECT 30000
#define ID_FILE_NEW3 32767
#define IDS_EOL_DOS 30400
#define IDS_EOL_MAC 30401
#define ID_VIEW_DETAIL_BAR 32819
#define ID_VIEW_LOCATION_BAR 32820
#define ID_VIEW_DIR_STATISTICS 32821
-#define ID_VIEW_LANGUAGE 32822
#define ID_VIEW_LINEDIFFS 32823
#define ID_VIEW_WORDWRAP 32824
#define ID_VIEW_LINENUMBERS 32825