From 88958a855eb83aa718a2e62338cf9c0c92042421 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Fri, 4 Dec 2009 00:27:29 +0000 Subject: [PATCH] [BUG_FIXED] Fix localization combo box unselected in preference dialog bug after startup (when a localization file is in use). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@581 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 18 +++++++++++++++++- PowerEditor/src/Parameters.cpp | 4 ++-- PowerEditor/src/Parameters.h | 16 +++++++++++++--- .../WinControls/Preference/preferenceDlg.cpp | 7 +++++++ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 26dfb0ca8..02bb9ba36 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -85,6 +85,22 @@ Notepad_plus::Notepad_plus(): Window(), _mainWindowStatus(0), _pDocTab(NULL), _p if (rtl) _isRTL = (strcmp(rtl, "yes") == 0); + // get original file name (defined by Notpad++) from the attribute + LocalizationSwitcher & localizationSwitcher = (NppParameters::getInstance())->getLocalizationSwitcher(); + const char *fn = element->Attribute("fileName"); +#ifdef UNICODE + if (fn) + { + localizationSwitcher.setFileName(fn); + } +#endif + if (stricmp("english.xml", fn) == 0) + { + _nativeLangA = NULL; + _toolIcons = NULL; + return; + } + // get encoding TiXmlDeclarationA *declaration = _nativeLangA->GetDocument()->FirstChild()->ToDeclaration(); if (declaration) @@ -95,7 +111,7 @@ Notepad_plus::Notepad_plus(): Window(), _mainWindowStatus(0), _pDocTab(NULL), _p } } } - } + } else _nativeLangA = NULL; diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 20b19d1b4..9c8975de4 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -446,7 +446,7 @@ static int getKwClassFromName(const TCHAR *str) { #ifdef UNICODE #include "localizationString.h" -wstring LocalizationSwitcher::getLangFromXmlFileName(wchar_t *fn) const +wstring LocalizationSwitcher::getLangFromXmlFileName(const wchar_t *fn) const { size_t nbItem = sizeof(localizationDefs)/sizeof(LocalizationSwitcher::LocalizationDefinition); for (size_t i = 0 ; i < nbItem ; i++) @@ -457,7 +457,7 @@ wstring LocalizationSwitcher::getLangFromXmlFileName(wchar_t *fn) const return TEXT(""); } -wstring LocalizationSwitcher::getXmlFilePathFromLangName(wchar_t *langName) const +wstring LocalizationSwitcher::getXmlFilePathFromLangName(const wchar_t *langName) const { for (size_t i = 0 ; i < _localizationList.size() ; i++) { diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index c3187e199..cb7469e9a 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -985,7 +985,7 @@ struct FindHistory { class LocalizationSwitcher { friend class NppParameters; public : - LocalizationSwitcher() {}; + LocalizationSwitcher() : _fileName("") {}; struct LocalizationDefinition { wchar_t *_langName; @@ -993,9 +993,9 @@ public : }; bool addLanguageFromXml(wstring xmlFullPath); - wstring getLangFromXmlFileName(wchar_t *fn) const; + wstring getLangFromXmlFileName(const wchar_t *fn) const; - wstring getXmlFilePathFromLangName(wchar_t *langName) const; + wstring getXmlFilePathFromLangName(const wchar_t *langName) const; bool switchToLang(wchar_t *lang2switch) const; size_t size() const { @@ -1008,9 +1008,19 @@ public : return _localizationList[index]; }; + void setFileName(const char *fn) { + if (fn) + _fileName = fn; + }; + + string getFileName() const { + return _fileName; + }; + private : vector< pair< wstring, wstring > > _localizationList; wstring _nativeLangPath; + string _fileName; }; #endif diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index ce04b3eb8..a2a61f320 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -182,6 +182,13 @@ BOOL CALLBACK BarsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM) pair localizationInfo = localizationSwitcher.getElementFromIndex(i); ::SendDlgItemMessage(_hSelf, IDC_COMBO_LOCALIZATION, CB_ADDSTRING, 0, (LPARAM)localizationInfo.first.c_str()); } + string fn = localizationSwitcher.getFileName(); + wstring fnW(fn.begin(), fn.end()); + fnW.assign(fn.begin(), fn.end()); + wstring lang = localizationSwitcher.getLangFromXmlFileName(fnW.c_str()); + int index = ::SendDlgItemMessage(_hSelf, IDC_COMBO_LOCALIZATION, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)lang.c_str()); + if (index != CB_ERR) + ::SendDlgItemMessage(_hSelf, IDC_COMBO_LOCALIZATION, CB_SETCURSEL, index, 0); #endif ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture();