diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 367003a25..6ff77b9d9 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -217,7 +217,8 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLine, CmdL RECT workAreaRect; ::SystemParametersInfo(SPI_GETWORKAREA, 0, &workAreaRect, 0); - const NppGUI & nppGUI = (NppParameters::getInstance())->getNppGUI(); + NppParameters *pNppParams = NppParameters::getInstance(); + const NppGUI & nppGUI = pNppParams->getNppGUI(); if (cmdLineParams->_isNoPlugin) _pluginsManager.disable(); @@ -290,6 +291,27 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLine, CmdL loadCommandlineParams(cmdLine, cmdLineParams); } +#ifdef UNICODE + LocalizationSwicher & localizationSwitcher = pNppParams->getLocalizationSwitcher(); + vector fileNames; + vector patterns; + patterns.push_back(TEXT("*.xml")); + + wchar_t tmp[MAX_PATH]; + lstrcpyW(tmp, _nppPath); + ::PathRemoveFileSpec(tmp); + wstring localizationDir = tmp; + + localizationDir += TEXT("\\localization\\"); + getMatchedFileNames(localizationDir.c_str(), patterns, fileNames, false, false); + for (size_t i = 0 ; i < fileNames.size() ; i++) + { + //wchar_t fullpath[MAX_PATH]; + //lstrcpyW(fn, localizationDir[i]); + localizationSwitcher.addLanguageFromXml(fileNames[i].c_str()); + } +#endif + // Notify plugins that Notepad++ is ready SCNotification scnN; scnN.nmhdr.code = NPPN_READY; @@ -2673,12 +2695,7 @@ void Notepad_plus::command(int id) { NppParameters *pNppParam = NppParameters::getInstance(); switch (id) - { - case IDM_VIEW_TOOLBAR_HIDE: - { - reloadLang(); - } - break; + { case IDM_FILE_NEW: { fileNew(); @@ -4582,12 +4599,13 @@ bool Notepad_plus::reloadLang() generic_string pluginsTrans, windowTrans; changeMenuLang(pluginsTrans, windowTrans); + int indexWindow = ::GetMenuItemCount(_mainMenuHandle) - 3; + if (_pluginsManager.hasPlugins() && pluginsTrans != TEXT("")) { - ::ModifyMenu(_mainMenuHandle, MENUINDEX_PLUGINS, MF_BYPOSITION, 0, pluginsTrans.c_str()); + ::ModifyMenu(_mainMenuHandle, indexWindow - 1, MF_BYPOSITION, 0, pluginsTrans.c_str()); } - - int indexWindow = ::GetMenuItemCount(_mainMenuHandle) - 2; + ::ModifyMenu(_mainMenuHandle, indexWindow, MF_BYPOSITION, 0, windowTrans.c_str()); windowTrans += TEXT("..."); ::ModifyMenu(_mainMenuHandle, IDM_WINDOW_WINDOWS, MF_BYCOMMAND, IDM_WINDOW_WINDOWS, windowTrans.c_str()); @@ -7293,6 +7311,12 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa } return TRUE; + case NPPM_INTERNAL_RELOADNATIVELANG: + { + reloadLang(); + } + return TRUE; + case NPPM_MENUCOMMAND : command(lParam); return TRUE; diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index d669b453b..e29b1a62a 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -176,7 +176,6 @@ IDR_M30_MENU MENU BEGIN POPUP "&File" BEGIN - MENUITEM "reload lang", IDM_VIEW_TOOLBAR_HIDE MENUITEM "&New", IDM_FILE_NEW MENUITEM "&Open...", IDM_FILE_OPEN MENUITEM "Re&load from Disk", IDM_FILE_RELOAD diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index ec424f9a0..95690d704 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -119,6 +119,7 @@ WinMenuKeyDefinition winKeyDefs[] = { //array of accelerator keys for all std me {VK_F11, IDM_VIEW_FULLSCREENTOGGLE, false, false, false, NULL}, {VK_NULL, IDM_VIEW_ALWAYSONTOP, false, false, false, NULL}, + {VK_F12, IDM_VIEW_POSTIT, false, false, false, NULL}, {VK_NULL, IDM_VIEW_TAB_SPACE, false, false, false, NULL}, {VK_NULL, IDM_VIEW_EOL, false, false, false, NULL}, {VK_NULL, IDM_VIEW_ALL_CHARACTERS, false, false, false, NULL}, @@ -181,8 +182,6 @@ WinMenuKeyDefinition winKeyDefs[] = { //array of accelerator keys for all std me {VK_F5, IDM_EXECUTE, false, false, false, NULL}, - {VK_F12, IDM_VIEW_POSTIT, false, false, false, NULL}, - {VK_NULL, IDM_HOMESWEETHOME, false, false, false, NULL}, {VK_NULL, IDM_PROJECTPAGE, false, false, false, NULL}, {VK_NULL, IDM_ONLINEHELP, false, false, false, NULL}, @@ -327,6 +326,86 @@ ScintillaKeyDefinition scintKeyDefs[] = { //array of accelerator keys for all po //{TEXT("SCI_STYLECLEARALL"), SCI_STYLECLEARALL, false, false, false, 0, 0}, // }; +#ifdef UNICODE +#include "localizationString.h" + +LocalizationSwicher::LocalizationSwicher() +{ + TCHAR userPath[MAX_PATH]; + + // Make localConf.xml path + TCHAR localConfPath[MAX_PATH]; + TCHAR nppPath[MAX_PATH]; + ::GetModuleFileName(NULL, nppPath, MAX_PATH); + + lstrcpy(localConfPath, nppPath); + PathAppend(localConfPath, localConfFile); + + // Test if localConf.xml exist + bool isLocal = (PathFileExists(localConfPath) == TRUE); + + if (isLocal) + { + lstrcpy(userPath, nppPath); + } + else + { + ITEMIDLIST *pidl; + SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl); + SHGetPathFromIDList(pidl, userPath); + PathAppend(userPath, TEXT("Notepad++")); + } + + TCHAR nativeLangPath[MAX_PATH]; + lstrcpy(nativeLangPath, userPath); + PathAppend(nativeLangPath, TEXT("nativeLang.xml")); + + _nativeLangPath = nativeLangPath; +} + +wstring LocalizationSwicher::getLangFromXmlFileName(wchar_t *fn) const +{ + size_t nbItem = sizeof(localizationDefs)/sizeof(LocalizationSwicher::LocalizationDefinition); + for (size_t i = 0 ; i < nbItem ; i++) + { + if (wcsicmp(fn, localizationDefs[i]._xmlFileName) == 0) + return localizationDefs[i]._langName; + } + return TEXT(""); +} + +wstring LocalizationSwicher::getXmlFilePathFromLangName(wchar_t *langName) const +{ + for (size_t i = 0 ; i < _localizationList.size() ; i++) + { + if (wcsicmp(langName, _localizationList[i].first.c_str()) == 0) + return _localizationList[i].second; + } + return TEXT(""); +} + +bool LocalizationSwicher::addLanguageFromXml(wstring xmlFullPath) +{ + wchar_t * fn = ::PathFindFileNameW(xmlFullPath.c_str()); + wstring foundLang = getLangFromXmlFileName(fn); + if (foundLang != TEXT("")) + { + _localizationList.push_back(pair(foundLang ,xmlFullPath)); + return true; + } + return false; +} + +bool LocalizationSwicher::switchToLang(wchar_t *lang2switch) const +{ + wstring langPath = getXmlFilePathFromLangName(lang2switch); + if (langPath == TEXT("")) + return false; + + return ::CopyFileW(langPath.c_str(), _nativeLangPath.c_str(), FALSE) != FALSE; +} + +#endif typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); @@ -744,7 +823,7 @@ bool NppParameters::load() isAllLaoded = false; } - +/* //----------------------------------------------// // english.xml : for every user // // Always in the Notepad++ Dir. // @@ -765,6 +844,7 @@ bool NppParameters::load() isAllLaoded = false; } } +*/ //---------------------------------// @@ -2164,7 +2244,7 @@ void StyleArray::addStyler(int styleID, TiXmlNode *styleNode) // Pour _fgColor, _bgColor : // RGB() | (result & 0xFF000000) c'est pour le cas de -1 (0xFFFFFFFF) - // retourné par hexStrVal(str) + // retourné par hexStrVal(str) const TCHAR *str = element->Attribute(TEXT("name")); if (str) { diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index d1a1aa470..491686b62 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -19,6 +19,7 @@ #define PARAMETERS_H #include +#include #include "tinyxmlA.h" #include "tinyxml.h" @@ -800,6 +801,39 @@ struct FindHistory { }; +#ifdef UNICODE + +class LocalizationSwicher { +public : + LocalizationSwicher(); + + struct LocalizationDefinition { + wchar_t *_langName; + wchar_t *_xmlFileName; + }; + + bool addLanguageFromXml(wstring xmlFullPath); + wstring getLangFromXmlFileName(wchar_t *fn) const; + + wstring getXmlFilePathFromLangName(wchar_t *langName) const; + bool switchToLang(wchar_t *lang2switch) const; + + size_t size() const { + return _localizationList.size(); + }; + + pair getElementFromIndex(size_t index) { + if (index >= _localizationList.size()) + return pair(TEXT(""), TEXT("")); + return _localizationList[index]; + }; + +private : + vector< pair< wstring, wstring > > _localizationList; + wstring _nativeLangPath; +}; +#endif + const int NB_LANG = 80; const bool DUP = true; @@ -1121,8 +1155,8 @@ public: FindHistory & getFindHistory() {return _findHistory;}; #ifdef UNICODE - const vector & getLocalizationList() const { - return _localizationList; + LocalizationSwicher & getLocalizationSwitcher() { + return _localizationSwitcher; }; #endif @@ -1137,7 +1171,7 @@ private: *_pXmlToolIconsDoc, *_pXmlShortcutDoc, *_pXmlContextMenuDoc, *_pXmlSessionDoc; TiXmlDocumentA *_pXmlNativeLangDocA; - TiXmlDocumentA *_pXmlEnglishDocA; + //TiXmlDocumentA *_pXmlEnglishDocA; vector _pXmlExternalLexerDoc; @@ -1185,7 +1219,8 @@ private: vector _scintillaKeyCommands; //scintilla keycommands. Static size vector _scintillaModifiedKeyIndices; //modified scintilla keys. Indices static, determined by searching for commandId. Needed when saving alterations #ifdef UNICODE - vector _localizationList; + LocalizationSwicher _localizationSwitcher; + #endif //vector _noMenuCmdNames; vector _contextMenuItems; diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index 979b4f8e3..ce75b13a1 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -174,9 +174,13 @@ BOOL CALLBACK BarsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) ::EnableWindow(::GetDlgItem(_hSelf, IDC_LOCALIZATION_GB_STATIC), FALSE); ::EnableWindow(::GetDlgItem(_hSelf, IDC_COMBO_LOCALIZATION), FALSE); #else - const vector & localList = pNppParam->getLocalizationList(); - for (size_t i = 0 ; i < localList.size() ; i++) - ::SendDlgItemMessage(_hSelf, IDC_COMBO_LOCALIZATION, CB_ADDSTRING, 0, (LPARAM)localList[i].c_str()); + LocalizationSwicher & localizationSwitcher = pNppParam->getLocalizationSwitcher(); + + for (size_t i = 0 ; i < localizationSwitcher.size() ; i++) + { + pair localizationInfo = localizationSwitcher.getElementFromIndex(i); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_LOCALIZATION, CB_ADDSTRING, 0, (LPARAM)localizationInfo.first.c_str()); + } #endif ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture(); @@ -272,6 +276,42 @@ BOOL CALLBACK BarsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) case IDC_RADIO_STANDARD : ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_STANDARD, 0); return TRUE; +#ifdef UNICODE + default : + switch (HIWORD(wParam)) + { + case CBN_SELCHANGE : // == case LBN_SELCHANGE : + { + switch (LOWORD(wParam)) + { + case IDC_COMBO_LOCALIZATION : + { + LocalizationSwicher & localizationSwitcher = pNppParam->getLocalizationSwitcher(); + int index = ::SendDlgItemMessage(_hSelf, IDC_COMBO_LOCALIZATION, CB_GETCURSEL, 0, 0); + wchar_t langName[MAX_PATH]; + ::SendDlgItemMessage(_hSelf, IDC_COMBO_LOCALIZATION, CB_GETLBTEXT, index, (LPARAM)langName); + if (langName[0]) + { + // Make English as basic language + if (localizationSwitcher.switchToLang(TEXT("English"))) + { + ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_RELOADNATIVELANG, 0, 0); + } + // Change the language + if (localizationSwitcher.switchToLang(langName)) + { + ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_RELOADNATIVELANG, 0, 0); + ::InvalidateRect(_hParent, NULL, TRUE); + } + } + } + return TRUE; + default: + break; + } + } + } +#endif } } } diff --git a/PowerEditor/src/localizationString.h b/PowerEditor/src/localizationString.h new file mode 100644 index 000000000..222f59f25 Binary files /dev/null and b/PowerEditor/src/localizationString.h differ diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index 2876fd613..2b4e652f8 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -111,7 +111,7 @@ #define IDM_SEARCH_DELETEMARKEDLINES (IDM_SEARCH + 21) #define IDM_VIEW (IDM + 4000) - #define IDM_VIEW_TOOLBAR_HIDE (IDM_VIEW + 1) + //#define IDM_VIEW_TOOLBAR_HIDE (IDM_VIEW + 1) #define IDM_VIEW_TOOLBAR_REDUCE (IDM_VIEW + 2) #define IDM_VIEW_TOOLBAR_ENLARGE (IDM_VIEW + 3) #define IDM_VIEW_TOOLBAR_STANDARD (IDM_VIEW + 4) diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index 54ae9a787..74f71c801 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -300,6 +300,7 @@ #define NPPM_INTERNAL_SWITCHVIEWFROMHWND (NOTEPADPLUS_USER_INTERNAL + 22) #define NPPM_INTERNAL_UPDATETITLEBAR (NOTEPADPLUS_USER_INTERNAL + 23) #define NPPM_INTERNAL_CANCEL_FIND_IN_FILES (NOTEPADPLUS_USER_INTERNAL + 24) + #define NPPM_INTERNAL_RELOADNATIVELANG (NOTEPADPLUS_USER_INTERNAL + 24) // See Notepad_plus_msgs.h //#define NOTEPADPLUS_USER (WM_USER + 1000)