[NEW_FEATURE] Change language on the run time for Unicode version (Finished).
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@386 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
43bf9f4c9e
commit
7a137760e5
|
@ -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<wstring> fileNames;
|
||||
vector<wstring> 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;
|
||||
|
@ -2674,11 +2696,6 @@ 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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<wstring, wstring>(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)
|
||||
{
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#define PARAMETERS_H
|
||||
|
||||
#include <string>
|
||||
#include <shlwapi.h>
|
||||
#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<wstring, wstring> getElementFromIndex(size_t index) {
|
||||
if (index >= _localizationList.size())
|
||||
return pair<wstring, wstring>(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<wstring> & 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<TiXmlDocument *> _pXmlExternalLexerDoc;
|
||||
|
||||
|
@ -1185,7 +1219,8 @@ private:
|
|||
vector<ScintillaKeyMap> _scintillaKeyCommands; //scintilla keycommands. Static size
|
||||
vector<int> _scintillaModifiedKeyIndices; //modified scintilla keys. Indices static, determined by searching for commandId. Needed when saving alterations
|
||||
#ifdef UNICODE
|
||||
vector<wstring> _localizationList;
|
||||
LocalizationSwicher _localizationSwitcher;
|
||||
|
||||
#endif
|
||||
//vector<generic_string> _noMenuCmdNames;
|
||||
vector<MenuItemUnit> _contextMenuItems;
|
||||
|
|
|
@ -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<wstring> & 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<wstring, wstring> 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue