[UPDATE] refactoring (in progress).

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@622 f5eea248-9336-0410-98b8-ebc06183d4e3
remotes/x64
Don Ho 2010-03-05 00:15:06 +00:00
parent 40eb02ab1f
commit fd02b9df00
10 changed files with 360 additions and 313 deletions

Binary file not shown.

View File

@ -42,60 +42,24 @@ enum tb_stat {tb_saved, tb_unsaved, tb_ro};
Notepad_plus::Notepad_plus(): Window(), _mainWindowStatus(0), _pDocTab(NULL), _pEditView(NULL),
_pMainSplitter(NULL),
_recordingMacro(false), _pTrayIco(NULL), _isUDDocked(false), _isRTL(false),
_recordingMacro(false), _pTrayIco(NULL), _isUDDocked(false),
_linkTriggered(true), _isDocModifing(false), _isHotspotDblClicked(false), _sysMenuEntering(false),
_autoCompleteMain(&_mainEditView), _autoCompleteSub(&_subEditView), _smartHighlighter(&_findReplaceDlg),
_nativeLangEncoding(CP_ACP), _isFileOpening(false), _rememberThisSession(true)
_isFileOpening(false), _rememberThisSession(true)
{
ZeroMemory(&_prevSelectedRange, sizeof(_prevSelectedRange));
_winVersion = (NppParameters::getInstance())->getWinVersion();
TiXmlDocumentA *nativeLangDocRootA = (NppParameters::getInstance())->getNativeLangA();
if (nativeLangDocRootA)
{
_nativeLangA = nativeLangDocRootA->FirstChild("NotepadPlus");
if (_nativeLangA)
{
_nativeLangA = _nativeLangA->FirstChild("Native-Langue");
if (_nativeLangA)
{
TiXmlElementA *element = _nativeLangA->ToElement();
const char *rtl = element->Attribute("RTL");
if (rtl)
_isRTL = (strcmp(rtl, "yes") == 0);
// get original file name (defined by Notpad++) from the attribute
const char *fn = element->Attribute("filename");
_nativeLangSpeaker.init(nativeLangDocRootA);
#ifdef UNICODE
LocalizationSwitcher & localizationSwitcher = (NppParameters::getInstance())->getLocalizationSwitcher();
if (fn)
{
localizationSwitcher.setFileName(fn);
}
#endif
if (fn && stricmp("english.xml", fn) == 0)
{
_nativeLangA = NULL;
_toolIcons = NULL;
return;
}
// get encoding
TiXmlDeclarationA *declaration = _nativeLangA->GetDocument()->FirstChild()->ToDeclaration();
if (declaration)
{
const char * encodingStr = declaration->Encoding();
EncodingMapper *em = EncodingMapper::getInstance();
int enc = em->getEncodingFromString(encodingStr);
if (enc != -1)
_nativeLangEncoding = enc;
}
}
}
LocalizationSwitcher & localizationSwitcher = (NppParameters::getInstance())->getLocalizationSwitcher();
const char *fn = _nativeLangSpeaker.getFileName();
if (fn)
{
localizationSwitcher.setFileName(fn);
}
else
_nativeLangA = NULL;
#endif
TiXmlDocument *toolIconsDocRoot = (NppParameters::getInstance())->getToolIcons();
if (toolIconsDocRoot)
@ -221,7 +185,7 @@ void Notepad_plus::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLine, CmdL
_pluginsManager.disable();
_hSelf = ::CreateWindowEx(
WS_EX_ACCEPTFILES | (_isRTL?WS_EX_LAYOUTRTL:0),\
WS_EX_ACCEPTFILES | (_nativeLangSpeaker.isRTL()?WS_EX_LAYOUTRTL:0),\
_className,\
TEXT("Notepad++"),\
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,\
@ -1644,7 +1608,7 @@ void Notepad_plus::addHotSpot(bool docIsModifing)
TCHAR *generic_fontname = new TCHAR[128];
#ifdef UNICODE
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
const wchar_t * fontNameW = wmc->char2wchar(fontNameA, _nativeLangEncoding);
const wchar_t * fontNameW = wmc->char2wchar(fontNameA, _nativeLangSpeaker.getLangEncoding());
lstrcpy(generic_fontname, fontNameW);
#else
lstrcpy(generic_fontname, fontNameA);
@ -1800,7 +1764,7 @@ void Notepad_plus::specialCmd(int id, int param)
POINT p;
::GetCursorPos(&p);
::ScreenToClient(_hParent, &p);
int size = nbColumnEdgeDlg.doDialog(p, _isRTL);
int size = nbColumnEdgeDlg.doDialog(p, _nativeLangSpeaker.isRTL());
if (size != -1)
{
@ -3267,7 +3231,7 @@ void Notepad_plus::fullScreenToggle()
::SetForegroundWindow(_hSelf);
// show restore button
_restoreButton.doDialog(_isRTL);
_restoreButton.doDialog(_nativeLangSpeaker.isRTL());
RECT rect;
GetWindowRect(_restoreButton.getHSelf(), &rect);
@ -3387,7 +3351,7 @@ void Notepad_plus::postItToggle()
}
// show restore button
_restoreButton.doDialog(_isRTL);
_restoreButton.doDialog(_nativeLangSpeaker.isRTL());
RECT rect;
GetWindowRect(_restoreButton.getHSelf(), &rect);
@ -4097,4 +4061,126 @@ bool Notepad_plus::noOpenedDoc() const
return true;
}
return false;
}
}
bool Notepad_plus::reloadLang()
{
NppParameters *pNppParam = NppParameters::getInstance();
if (!pNppParam->reloadLang())
{
return false;
}
TiXmlDocumentA *nativeLangDocRootA = pNppParam->getNativeLangA();
if (!nativeLangDocRootA)
{
return false;
}
_nativeLangSpeaker.init(nativeLangDocRootA);
pNppParam->reloadContextMenuFromXmlTree(_mainMenuHandle);
generic_string pluginsTrans, windowTrans;
_nativeLangSpeaker.changeMenuLang(_mainMenuHandle, pluginsTrans, windowTrans);
::DrawMenuBar(_hSelf);
int indexWindow = ::GetMenuItemCount(_mainMenuHandle) - 3;
if (_pluginsManager.hasPlugins() && pluginsTrans != TEXT(""))
{
::ModifyMenu(_mainMenuHandle, indexWindow - 1, MF_BYPOSITION, 0, pluginsTrans.c_str());
}
if (windowTrans != TEXT(""))
{
::ModifyMenu(_mainMenuHandle, indexWindow, MF_BYPOSITION, 0, windowTrans.c_str());
windowTrans += TEXT("...");
::ModifyMenu(_mainMenuHandle, IDM_WINDOW_WINDOWS, MF_BYCOMMAND, IDM_WINDOW_WINDOWS, windowTrans.c_str());
}
// Update scintilla context menu strings
vector<MenuItemUnit> & tmp = pNppParam->getContextMenuItems();
size_t len = tmp.size();
TCHAR menuName[64];
for (size_t i = 0 ; i < len ; i++)
{
if (tmp[i]._itemName == TEXT(""))
{
::GetMenuString(_mainMenuHandle, tmp[i]._cmdID, menuName, 64, MF_BYCOMMAND);
tmp[i]._itemName = purgeMenuItemString(menuName);
}
}
vector<CommandShortcut> & shortcuts = pNppParam->getUserShortcuts();
len = shortcuts.size();
for(size_t i = 0; i < len; i++)
{
CommandShortcut & csc = shortcuts[i];
::GetMenuString(_mainMenuHandle, csc.getID(), menuName, 64, MF_BYCOMMAND);
csc.setName(purgeMenuItemString(menuName, true).c_str());
}
_accelerator.updateFullMenu();
_scintaccelerator.updateKeys();
if (_tabPopupMenu.isCreated())
{
_nativeLangSpeaker.changeLangTabContextMenu(_tabPopupMenu.getMenuHandle());
}
if (_tabPopupDropMenu.isCreated())
{
_nativeLangSpeaker.changeLangTabDrapContextMenu(_tabPopupDropMenu.getMenuHandle());
}
if (_preference.isCreated())
{
_nativeLangSpeaker.changePrefereceDlgLang(_preference);
}
if (_configStyleDlg.isCreated())
{
_nativeLangSpeaker.changeConfigLang(_configStyleDlg.getHSelf());
}
if (_findReplaceDlg.isCreated())
{
_nativeLangSpeaker.changeFindReplaceDlgLang(_findReplaceDlg);
}
if (_goToLineDlg.isCreated())
{
_nativeLangSpeaker.changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine");
}
if (_runDlg.isCreated())
{
_nativeLangSpeaker.changeDlgLang(_runDlg.getHSelf(), "Run");
}
if (_runMacroDlg.isCreated())
{
_nativeLangSpeaker.changeDlgLang(_runMacroDlg.getHSelf(), "MultiMacro");
}
if (_goToLineDlg.isCreated())
{
_nativeLangSpeaker.changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine");
}
if (_colEditorDlg.isCreated())
{
_nativeLangSpeaker.changeDlgLang(_colEditorDlg.getHSelf(), "ColumnEditor");
}
UserDefineDialog *udd = _pEditView->getUserDefineDlg();
if (udd->isCreated())
{
_nativeLangSpeaker.changeUserDefineLang(udd);
}
_lastRecentFileList.setLangEncoding(_nativeLangSpeaker.getLangEncoding());
return true;
}

View File

@ -110,9 +110,15 @@
#include "lesDlgs.h"
#endif //SIZE_DLG_H
#include "localization.h"
#define MENU 0x01
#define TOOLBAR 0x02
namespace Translator {
}
#define URL_REG_EXPR "[A-Za-z]+://[A-Za-z0-9_\\-\\+~.:?&@=/%#,;\\{\\}\\(\\)\\[\\]\\|\\*\\!\\\\]+"
enum FileTransferMode {
@ -256,20 +262,6 @@ public:
bool fileLoadSession(const TCHAR *fn = NULL);
const TCHAR * fileSaveSession(size_t nbFile, TCHAR ** fileNames, const TCHAR *sessionFile2save);
const TCHAR * fileSaveSession(size_t nbFile = 0, TCHAR ** fileNames = NULL);
TiXmlNodeA * searchDlgNode(TiXmlNodeA *node, const char *dlgTagName);
bool changeDlgLang(HWND hDlg, const char *dlgTagName, char *title = NULL);
void changeFindReplaceDlgLang();
void changeConfigLang();
void changeUserDefineLang();
void changeMenuLang(generic_string & pluginsTrans, generic_string & windowTrans);
void changeLangTabContextMenu();
void changeLangTabDrapContextMenu();
void changePrefereceDlgLang();
void changeShortcutLang();
void changeShortcutmapperLang(ShortcutMapper * sm);
const TCHAR * getNativeTip(int btnID);
void changeToolBarIcons();
bool doBlockComment(comment_mode currCommentMode);
@ -309,12 +301,8 @@ private:
AutoCompletion _autoCompleteSub; //each Scintilla has its own autoComplete
SmartHighlighter _smartHighlighter;
TiXmlNode *_toolIcons;
TiXmlNodeA *_nativeLangA;
int _nativeLangEncoding;
NativeLangSpeaker _nativeLangSpeaker;
DocTabView _mainDocTab;
DocTabView _subDocTab;
DocTabView *_pDocTab;
@ -411,9 +399,7 @@ private:
PluginsManager _pluginsManager;
ButtonDlg _restoreButton;
bool _isRTL;
winVer _winVersion;
bool _isFileOpening;
ScintillaCtrls _scintillaCtrls4Plugins;
@ -582,7 +568,7 @@ private:
void autoCompFromCurrentFile(bool autoInsert = true);
void showFunctionComp();
void changeStyleCtrlsLang(HWND hDlg, int *idArray, const char **translatedText);
//void changeStyleCtrlsLang(HWND hDlg, int *idArray, const char **translatedText);
bool replaceAllFiles();
bool findInOpenedFiles();
bool findInCurrentFile();

View File

@ -398,7 +398,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
int pos = IDM_FILEMENU_LASTONE - IDM_FILE + 2;
_lastRecentFileList.initMenu(hFileMenu, IDM_FILEMENU_LASTONE + 1, pos);
_lastRecentFileList.setLangEncoding(_nativeLangEncoding);
_lastRecentFileList.setLangEncoding(_nativeLangSpeaker.getLangEncoding());
for (int i = 0 ; i < nbLRFile ; i++)
{
generic_string * stdStr = pNppParam->getLRFile(i);
@ -421,8 +421,9 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
}
generic_string pluginsTrans, windowTrans;
changeMenuLang(pluginsTrans, windowTrans);
_nativeLangSpeaker.changeMenuLang(_mainMenuHandle, pluginsTrans, windowTrans);
::DrawMenuBar(_hSelf);
if (_pluginsManager.hasPlugins() && pluginsTrans != TEXT(""))
{
::ModifyMenu(_mainMenuHandle, MENUINDEX_PLUGINS, MF_BYPOSITION, 0, pluginsTrans.c_str());
@ -458,7 +459,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
}
}
//Translate non-menu shortcuts
changeShortcutLang();
_nativeLangSpeaker.changeShortcutLang();
//Update plugin shortcuts, all plugin commands should be available now
pNppParam->reloadPluginCmds();
@ -501,7 +502,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
//--Init dialogs--//
_findReplaceDlg.init(_hInst, hwnd, &_pEditView);
_incrementFindDlg.init(_hInst, hwnd, &_findReplaceDlg, _isRTL);
_incrementFindDlg.init(_hInst, hwnd, &_findReplaceDlg, _nativeLangSpeaker.isRTL());
_incrementFindDlg.addToRebar(&_rebarBottom);
_goToLineDlg.init(_hInst, hwnd, &_pEditView);
_colEditorDlg.init(_hInst, hwnd, &_pEditView);
@ -517,16 +518,16 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
switch (uddStatus)
{
case UDD_SHOW : // show & undocked
udd->doDialog(true, _isRTL);
changeUserDefineLang();
udd->doDialog(true, _nativeLangSpeaker.isRTL());
_nativeLangSpeaker.changeUserDefineLang(udd);
uddShow = true;
break;
case UDD_DOCKED : { // hide & docked
_isUDDocked = true;
break;}
case (UDD_SHOW | UDD_DOCKED) : // show & docked
udd->doDialog(true, _isRTL);
changeUserDefineLang();
udd->doDialog(true, _nativeLangSpeaker.isRTL());
_nativeLangSpeaker.changeUserDefineLang(udd);
::SendMessage(udd->getHSelf(), WM_COMMAND, IDC_DOCK_BUTTON, 0);
uddShow = true;
break;
@ -671,12 +672,12 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
TCHAR str[strSize];
bool isFirstTime = !_findReplaceDlg.isCreated();
_findReplaceDlg.doDialog(FIND_DLG, _isRTL);
_findReplaceDlg.doDialog(FIND_DLG, _nativeLangSpeaker.isRTL());
_pEditView->getGenericSelectedText(str, strSize);
_findReplaceDlg.setSearchText(str);
if (isFirstTime)
changeDlgLang(_findReplaceDlg.getHSelf(), "Find");
_nativeLangSpeaker.changeDlgLang(_findReplaceDlg.getHSelf(), "Find");
_findReplaceDlg.launchFindInFilesDlg();
setFindReplaceFolderFilter((const TCHAR*) wParam, (const TCHAR*) lParam);
return TRUE;

View File

@ -176,11 +176,11 @@ void Notepad_plus::command(int id)
if (!_recordingMacro) // if we're not currently recording, then playback the recorded keystrokes
{
bool isFirstTime = !_runMacroDlg.isCreated();
_runMacroDlg.doDialog(_isRTL);
_runMacroDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
{
changeDlgLang(_runMacroDlg.getHSelf(), "MultiMacro");
_nativeLangSpeaker.changeDlgLang(_runMacroDlg.getHSelf(), "MultiMacro");
}
break;
@ -224,14 +224,14 @@ void Notepad_plus::command(int id)
bool isFirstTime = !_findReplaceDlg.isCreated();
_findReplaceDlg.doDialog((id == IDM_SEARCH_FIND)?FIND_DLG:REPLACE_DLG, _isRTL);
_findReplaceDlg.doDialog((id == IDM_SEARCH_FIND)?FIND_DLG:REPLACE_DLG, _nativeLangSpeaker.isRTL());
_pEditView->getGenericSelectedText(str, strSize);
_findReplaceDlg.setSearchText(str);
setFindReplaceFolderFilter(NULL, NULL);
if (isFirstTime)
changeFindReplaceDlgLang();
_nativeLangSpeaker.changeFindReplaceDlgLang(_findReplaceDlg);
break;
}
@ -273,7 +273,7 @@ void Notepad_plus::command(int id)
{
bool isFirstTime = !_findReplaceDlg.isCreated();
if (isFirstTime)
_findReplaceDlg.doDialog(FIND_DLG, _isRTL, false);
_findReplaceDlg.doDialog(FIND_DLG, _nativeLangSpeaker.isRTL(), false);
const int strSize = FINDREPLACE_MAXLENGTH;
TCHAR str[strSize];
@ -281,7 +281,7 @@ void Notepad_plus::command(int id)
_findReplaceDlg.setSearchText(str);
setFindReplaceFolderFilter(NULL, NULL);
if (isFirstTime)
changeFindReplaceDlgLang();
_nativeLangSpeaker.changeFindReplaceDlgLang(_findReplaceDlg);
FindOption op = _findReplaceDlg.getCurrentOptions();
op._whichDirection = (id == IDM_SEARCH_SETANDFINDNEXT?DIR_DOWN:DIR_UP);
@ -439,18 +439,18 @@ void Notepad_plus::command(int id)
case IDM_SEARCH_GOTOLINE :
{
bool isFirstTime = !_goToLineDlg.isCreated();
_goToLineDlg.doDialog(_isRTL);
_goToLineDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine");
_nativeLangSpeaker.changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine");
break;
}
case IDM_EDIT_COLUMNMODE :
{
bool isFirstTime = !_colEditorDlg.isCreated();
_colEditorDlg.doDialog(_isRTL);
_colEditorDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
changeDlgLang(_colEditorDlg.getHSelf(), "ColumnEditor");
_nativeLangSpeaker.changeDlgLang(_colEditorDlg.getHSelf(), "ColumnEditor");
break;
}
@ -489,8 +489,8 @@ void Notepad_plus::command(int id)
if (!udd->isCreated())
{
_pEditView->doUserDefineDlg(true, _isRTL);
changeUserDefineLang();
_pEditView->doUserDefineDlg(true, _nativeLangSpeaker.isRTL());
_nativeLangSpeaker.changeUserDefineLang(udd);
if (_isUDDocked)
::SendMessage(udd->getHSelf(), WM_COMMAND, IDC_DOCK_BUTTON, 0);
@ -942,9 +942,9 @@ void Notepad_plus::command(int id)
case IDM_EXECUTE:
{
bool isFirstTime = !_runDlg.isCreated();
_runDlg.doDialog(_isRTL);
_runDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
changeDlgLang(_runDlg.getHSelf(), "Run");
_nativeLangSpeaker.changeDlgLang(_runDlg.getHSelf(), "Run");
break;
}
@ -1394,7 +1394,7 @@ void Notepad_plus::command(int id)
POINT p;
::GetCursorPos(&p);
::ScreenToClient(_hParent, &p);
int size = valDlg.doDialog(p, _isRTL);
int size = valDlg.doDialog(p, _nativeLangSpeaker.isRTL());
if (size != -1)
{
@ -1416,7 +1416,7 @@ void Notepad_plus::command(int id)
POINT p;
::GetCursorPos(&p);
::ScreenToClient(_hParent, &p);
int size = nbHistoryDlg.doDialog(p, _isRTL);
int size = nbHistoryDlg.doDialog(p, _nativeLangSpeaker.isRTL());
if (size != -1)
{
@ -1482,8 +1482,8 @@ void Notepad_plus::command(int id)
{
ShortcutMapper shortcutMapper;
shortcutMapper.init(_hInst, _hSelf);
changeShortcutmapperLang(&shortcutMapper);
shortcutMapper.doDialog(_isRTL);
_nativeLangSpeaker.changeShortcutmapperLang(&shortcutMapper);
shortcutMapper.doDialog(_nativeLangSpeaker.isRTL());
shortcutMapper.destroy();
break;
}
@ -1491,11 +1491,11 @@ void Notepad_plus::command(int id)
case IDM_SETTING_PREFERECE :
{
bool isFirstTime = !_preference.isCreated();
_preference.doDialog(_isRTL);
_preference.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
{
changePrefereceDlgLang();
_nativeLangSpeaker.changePrefereceDlgLang(_preference);
}
break;
}
@ -1539,9 +1539,9 @@ void Notepad_plus::command(int id)
{
bool isFirstTime = !_aboutDlg.isCreated();
_aboutDlg.doDialog();
if (isFirstTime && _nativeLangA)
if (isFirstTime && _nativeLangSpeaker.getNativeLangA())
{
if (_nativeLangEncoding == NPP_CP_BIG5)
if (_nativeLangSpeaker.getLangEncoding() == NPP_CP_BIG5)
{
char *authorName = "«J¤µ§^";
HWND hItem = ::GetDlgItem(_aboutDlg.getHSelf(), IDC_AUTHOR_NAME);
@ -1633,9 +1633,9 @@ void Notepad_plus::command(int id)
case IDM_LANGSTYLE_CONFIG_DLG :
{
bool isFirstTime = !_configStyleDlg.isCreated();
_configStyleDlg.doDialog(_isRTL);
_configStyleDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
changeConfigLang();
_nativeLangSpeaker.changeConfigLang(_configStyleDlg.getHSelf());
break;
}
@ -1759,12 +1759,13 @@ void Notepad_plus::command(int id)
WindowsDlg _windowsDlg;
_windowsDlg.init(_hInst, _hSelf, _pDocTab);
const TiXmlNodeA *nativeLangA = _nativeLangSpeaker.getNativeLangA();
TiXmlNodeA *dlgNode = NULL;
if (_nativeLangA)
if (nativeLangA)
{
dlgNode = _nativeLangA->FirstChild("Dialog");
dlgNode = nativeLangA->FirstChild("Dialog");
if (dlgNode)
dlgNode = searchDlgNode(dlgNode, "Window");
dlgNode = _nativeLangSpeaker.searchDlgNode(dlgNode, "Window");
}
_windowsDlg.doDialog(dlgNode);
}

View File

@ -247,7 +247,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_GOTO_ANOTHER_VIEW, goToView));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_CLONE_TO_ANOTHER_VIEW, cloneToView));
_tabPopupDropMenu.create(_hSelf, itemUnitArray);
changeLangTabDrapContextMenu();
_nativeLangSpeaker.changeLangTabDrapContextMenu(_tabPopupDropMenu.getMenuHandle());
}
_tabPopupDropMenu.display(p);
}
@ -388,9 +388,9 @@ BOOL Notepad_plus::notify(SCNotification *notification)
if (lpnm->dwItemSpec == DWORD(STATUSBAR_CUR_POS))
{
bool isFirstTime = !_goToLineDlg.isCreated();
_goToLineDlg.doDialog(_isRTL);
_goToLineDlg.doDialog(_nativeLangSpeaker.isRTL());
if (isFirstTime)
changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine");
_nativeLangSpeaker.changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine");
}
}
break;
@ -437,7 +437,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_LOAD_IN_NEW_INSTANCE, TEXT("Open in New Instance")));
_tabPopupMenu.create(_hSelf, itemUnitArray);
changeLangTabContextMenu();
_nativeLangSpeaker.changeLangTabContextMenu(_tabPopupMenu.getMenuHandle());
}
bool isEnable = ((::GetMenuState(_mainMenuHandle, IDM_FILE_SAVE, MF_BYCOMMAND)&MF_DISABLED) == 0);

View File

@ -160,7 +160,8 @@ private :
class PreferenceDlg : public StaticDialog
{
friend class Notepad_plus;
//friend class Notepad_plus;
friend class NativeLangSpeaker;
public :
PreferenceDlg(){};

View File

@ -20,7 +20,49 @@
#include "ShortcutMapper.h"
#include "EncodingMapper.h"
void Notepad_plus::changeMenuLang(generic_string & pluginsTrans, generic_string & windowTrans)
#include "localization.h"
void NativeLangSpeaker::init(TiXmlDocumentA *nativeLangDocRootA)
{
if (nativeLangDocRootA)
{
_nativeLangA = nativeLangDocRootA->FirstChild("NotepadPlus");
if (_nativeLangA)
{
_nativeLangA = _nativeLangA->FirstChild("Native-Langue");
if (_nativeLangA)
{
TiXmlElementA *element = _nativeLangA->ToElement();
const char *rtl = element->Attribute("RTL");
if (rtl)
_isRTL = (strcmp(rtl, "yes") == 0);
else
_isRTL = false;
// get original file name (defined by Notpad++) from the attribute
_fileName = element->Attribute("filename");
if (_fileName && stricmp("english.xml", _fileName) == 0)
{
_nativeLangA = NULL;
return;
}
// get encoding
TiXmlDeclarationA *declaration = _nativeLangA->GetDocument()->FirstChild()->ToDeclaration();
if (declaration)
{
const char * encodingStr = declaration->Encoding();
EncodingMapper *em = EncodingMapper::getInstance();
int enc = em->getEncodingFromString(encodingStr);
_nativeLangEncoding = (enc != -1)?enc:CP_ACP;
}
}
}
}
}
void NativeLangSpeaker::changeMenuLang(HMENU menuHandle, generic_string & pluginsTrans, generic_string & windowTrans)
{
if (!_nativeLangA) return;
TiXmlNodeA *mainMenu = _nativeLangA->FirstChild("Menu");
@ -47,9 +89,9 @@ void Notepad_plus::changeMenuLang(generic_string & pluginsTrans, generic_string
#ifdef UNICODE
const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding);
::ModifyMenu(_mainMenuHandle, id, MF_BYPOSITION, 0, nameW);
::ModifyMenu(menuHandle, id, MF_BYPOSITION, 0, nameW);
#else
::ModifyMenu(_mainMenuHandle, id, MF_BYPOSITION, 0, name);
::ModifyMenu(menuHandle, id, MF_BYPOSITION, 0, name);
#endif
}
else
@ -92,9 +134,9 @@ void Notepad_plus::changeMenuLang(generic_string & pluginsTrans, generic_string
#ifdef UNICODE
const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding);
::ModifyMenu(_mainMenuHandle, id, MF_BYCOMMAND, id, nameW);
::ModifyMenu(menuHandle, id, MF_BYCOMMAND, id, nameW);
#else
::ModifyMenu(_mainMenuHandle, id, MF_BYCOMMAND, id, name);
::ModifyMenu(menuHandle, id, MF_BYCOMMAND, id, name);
#endif
}
@ -112,7 +154,7 @@ void Notepad_plus::changeMenuLang(generic_string & pluginsTrans, generic_string
if (!xStr || !yStr || !name)
continue;
HMENU hSubMenu = ::GetSubMenu(_mainMenuHandle, x);
HMENU hSubMenu = ::GetSubMenu(menuHandle, x);
if (!hSubMenu)
continue;
HMENU hSubMenu2 = ::GetSubMenu(hSubMenu, y);
@ -139,10 +181,9 @@ void Notepad_plus::changeMenuLang(generic_string & pluginsTrans, generic_string
::ModifyMenu(hMenu, pos, MF_BYPOSITION, 0, name);
#endif
}
::DrawMenuBar(_hSelf);
}
void Notepad_plus::changeLangTabContextMenu()
void NativeLangSpeaker::changeLangTabContextMenu(HMENU hCM)
{
const int POS_CLOSE = 0;
const int POS_CLOSEBUT = 1;
@ -234,7 +275,7 @@ void Notepad_plus::changeLangTabContextMenu()
}
}
}
HMENU hCM = _tabPopupMenu.getMenuHandle();
//HMENU hCM = _tabPopupMenu.getMenuHandle();
#ifdef UNICODE
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
@ -418,7 +459,7 @@ void Notepad_plus::changeLangTabContextMenu()
#endif
}
void Notepad_plus::changeLangTabDrapContextMenu()
void NativeLangSpeaker::changeLangTabDrapContextMenu(HMENU hCM)
{
const int POS_GO2VIEW = 0;
const int POS_CLONE2VIEW = 1;
@ -445,7 +486,7 @@ void Notepad_plus::changeLangTabDrapContextMenu()
cloneToViewA = element->Attribute("name");
}
}
HMENU hCM = _tabPopupDropMenu.getMenuHandle();
//HMENU hCM = _tabPopupDropMenu.getMenuHandle();
#ifdef UNICODE
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
if (goToViewA && goToViewA[0])
@ -475,7 +516,7 @@ void Notepad_plus::changeLangTabDrapContextMenu()
}
}
void Notepad_plus::changeConfigLang()
void NativeLangSpeaker::changeConfigLang(HWND hDlg)
{
if (!_nativeLangA) return;
@ -485,7 +526,7 @@ void Notepad_plus::changeConfigLang()
styleConfDlgNode = styleConfDlgNode->FirstChild("StyleConfig");
if (!styleConfDlgNode) return;
HWND hDlg = _configStyleDlg.getHSelf();
//HWND hDlg = _configStyleDlg.getHSelf();
#ifdef UNICODE
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
@ -525,7 +566,6 @@ void Notepad_plus::changeConfigLang()
}
}
}
hDlg = _configStyleDlg.getHSelf();
styleConfDlgNode = styleConfDlgNode->FirstChild("SubDialog");
for (TiXmlNodeA *childNode = styleConfDlgNode->FirstChildElement("Item");
@ -553,7 +593,7 @@ void Notepad_plus::changeConfigLang()
}
void Notepad_plus::changeStyleCtrlsLang(HWND hDlg, int *idArray, const char **translatedText)
void NativeLangSpeaker::changeStyleCtrlsLang(HWND hDlg, int *idArray, const char **translatedText)
{
const int iColorStyle = 0;
const int iUnderline = 8;
@ -579,7 +619,7 @@ void Notepad_plus::changeStyleCtrlsLang(HWND hDlg, int *idArray, const char **tr
}
}
void Notepad_plus::changeUserDefineLang()
void NativeLangSpeaker::changeUserDefineLang(UserDefineDialog *userDefineDlg)
{
if (!_nativeLangA) return;
@ -589,7 +629,7 @@ void Notepad_plus::changeUserDefineLang()
userDefineDlgNode = userDefineDlgNode->FirstChild("UserDefine");
if (!userDefineDlgNode) return;
UserDefineDialog *userDefineDlg = _pEditView->getUserDefineDlg();
//UserDefineDialog *userDefineDlg = _pEditView->getUserDefineDlg();
HWND hDlg = userDefineDlg->getHSelf();
#ifdef UNICODE
@ -742,7 +782,7 @@ void Notepad_plus::changeUserDefineLang()
}
}
void Notepad_plus::changeFindReplaceDlgLang()
void NativeLangSpeaker::changeFindReplaceDlgLang(FindReplaceDlg & findReplaceDlg)
{
if (_nativeLangA)
{
@ -777,17 +817,17 @@ void Notepad_plus::changeFindReplaceDlgLang()
}
}
_findReplaceDlg.changeTabName(FIND_DLG, pNppParam->getFindDlgTabTitiles()._find.c_str());
_findReplaceDlg.changeTabName(REPLACE_DLG, pNppParam->getFindDlgTabTitiles()._replace.c_str());
_findReplaceDlg.changeTabName(FINDINFILES_DLG, pNppParam->getFindDlgTabTitiles()._findInFiles.c_str());
findReplaceDlg.changeTabName(FIND_DLG, pNppParam->getFindDlgTabTitiles()._find.c_str());
findReplaceDlg.changeTabName(REPLACE_DLG, pNppParam->getFindDlgTabTitiles()._replace.c_str());
findReplaceDlg.changeTabName(FINDINFILES_DLG, pNppParam->getFindDlgTabTitiles()._findInFiles.c_str());
}
}
changeDlgLang(_findReplaceDlg.getHSelf(), "Find");
changeDlgLang(findReplaceDlg.getHSelf(), "Find");
}
void Notepad_plus::changePrefereceDlgLang()
void NativeLangSpeaker::changePrefereceDlgLang(PreferenceDlg & preference)
{
changeDlgLang(_preference.getHSelf(), "Preference");
changeDlgLang(preference.getHSelf(), "Preference");
char titre[128];
@ -795,93 +835,93 @@ void Notepad_plus::changePrefereceDlgLang()
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
#endif
changeDlgLang(_preference._barsDlg.getHSelf(), "Global", titre);
changeDlgLang(preference._barsDlg.getHSelf(), "Global", titre);
if (*titre)
{
#ifdef UNICODE
const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding);
_preference._ctrlTab.renameTab(TEXT("Global"), nameW);
preference._ctrlTab.renameTab(TEXT("Global"), nameW);
#else
_preference._ctrlTab.renameTab("Global", titre);
preference._ctrlTab.renameTab("Global", titre);
#endif
}
changeDlgLang(_preference._marginsDlg.getHSelf(), "Scintillas", titre);
changeDlgLang(preference._marginsDlg.getHSelf(), "Scintillas", titre);
if (*titre)
{
#ifdef UNICODE
const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding);
_preference._ctrlTab.renameTab(TEXT("Scintillas"), nameW);
preference._ctrlTab.renameTab(TEXT("Scintillas"), nameW);
#else
_preference._ctrlTab.renameTab("Scintillas", titre);
preference._ctrlTab.renameTab("Scintillas", titre);
#endif
}
changeDlgLang(_preference._defaultNewDocDlg.getHSelf(), "NewDoc", titre);
changeDlgLang(preference._defaultNewDocDlg.getHSelf(), "NewDoc", titre);
if (*titre)
{
#ifdef UNICODE
const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding);
_preference._ctrlTab.renameTab(TEXT("NewDoc"), nameW);
preference._ctrlTab.renameTab(TEXT("NewDoc"), nameW);
#else
_preference._ctrlTab.renameTab("NewDoc", titre);
preference._ctrlTab.renameTab("NewDoc", titre);
#endif
}
changeDlgLang(_preference._fileAssocDlg.getHSelf(), "FileAssoc", titre);
changeDlgLang(preference._fileAssocDlg.getHSelf(), "FileAssoc", titre);
if (*titre)
{
#ifdef UNICODE
const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding);
_preference._ctrlTab.renameTab(TEXT("FileAssoc"), nameW);
preference._ctrlTab.renameTab(TEXT("FileAssoc"), nameW);
#else
_preference._ctrlTab.renameTab("FileAssoc", titre);
preference._ctrlTab.renameTab("FileAssoc", titre);
#endif
}
changeDlgLang(_preference._langMenuDlg.getHSelf(), "LangMenu", titre);
changeDlgLang(preference._langMenuDlg.getHSelf(), "LangMenu", titre);
if (*titre)
{
#ifdef UNICODE
const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding);
_preference._ctrlTab.renameTab(TEXT("LangMenu"), nameW);
preference._ctrlTab.renameTab(TEXT("LangMenu"), nameW);
#else
_preference._ctrlTab.renameTab("LangMenu", titre);
preference._ctrlTab.renameTab("LangMenu", titre);
#endif
}
changeDlgLang(_preference._printSettingsDlg.getHSelf(), "Print", titre);
changeDlgLang(preference._printSettingsDlg.getHSelf(), "Print", titre);
if (*titre)
{
#ifdef UNICODE
const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding);
_preference._ctrlTab.renameTab(TEXT("Print"), nameW);
preference._ctrlTab.renameTab(TEXT("Print"), nameW);
#else
_preference._ctrlTab.renameTab("Print", titre);
preference._ctrlTab.renameTab("Print", titre);
#endif
}
changeDlgLang(_preference._settingsDlg.getHSelf(), "MISC", titre);
changeDlgLang(preference._settingsDlg.getHSelf(), "MISC", titre);
if (*titre)
{
#ifdef UNICODE
const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding);
_preference._ctrlTab.renameTab(TEXT("MISC"), nameW);
preference._ctrlTab.renameTab(TEXT("MISC"), nameW);
#else
_preference._ctrlTab.renameTab("MISC", titre);
preference._ctrlTab.renameTab("MISC", titre);
#endif
}
changeDlgLang(_preference._backupDlg.getHSelf(), "Backup", titre);
changeDlgLang(preference._backupDlg.getHSelf(), "Backup", titre);
if (*titre)
{
#ifdef UNICODE
const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding);
_preference._ctrlTab.renameTab(TEXT("Backup"), nameW);
preference._ctrlTab.renameTab(TEXT("Backup"), nameW);
#else
_preference._ctrlTab.renameTab("Backup", titre);
preference._ctrlTab.renameTab("Backup", titre);
#endif
}
}
void Notepad_plus::changeShortcutLang()
void NativeLangSpeaker::changeShortcutLang()
{
if (!_nativeLangA) return;
@ -959,7 +999,7 @@ void Notepad_plus::changeShortcutLang()
}
void Notepad_plus::changeShortcutmapperLang(ShortcutMapper * sm)
void NativeLangSpeaker::changeShortcutmapperLang(ShortcutMapper * sm)
{
if (!_nativeLangA) return;
@ -994,7 +1034,7 @@ void Notepad_plus::changeShortcutmapperLang(ShortcutMapper * sm)
}
TiXmlNodeA * Notepad_plus::searchDlgNode(TiXmlNodeA *node, const char *dlgTagName)
TiXmlNodeA * NativeLangSpeaker::searchDlgNode(TiXmlNodeA *node, const char *dlgTagName)
{
TiXmlNodeA *dlgNode = node->FirstChild(dlgTagName);
if (dlgNode) return dlgNode;
@ -1008,7 +1048,7 @@ TiXmlNodeA * Notepad_plus::searchDlgNode(TiXmlNodeA *node, const char *dlgTagNam
return NULL;
}
bool Notepad_plus::changeDlgLang(HWND hDlg, const char *dlgTagName, char *title)
bool NativeLangSpeaker::changeDlgLang(HWND hDlg, const char *dlgTagName, char *title)
{
if (title)
title[0] = '\0';
@ -1065,145 +1105,4 @@ bool Notepad_plus::changeDlgLang(HWND hDlg, const char *dlgTagName, char *title)
return true;
}
bool Notepad_plus::reloadLang()
{
NppParameters *pNppParam = NppParameters::getInstance();
if (!pNppParam->reloadLang())
{
return false;
}
TiXmlDocumentA *nativeLangDocRootA = pNppParam->getNativeLangA();
if (!nativeLangDocRootA)
{
return false;
}
_nativeLangA = nativeLangDocRootA->FirstChild("NotepadPlus");
if (!_nativeLangA)
{
return false;
}
_nativeLangA = _nativeLangA->FirstChild("Native-Langue");
if (!_nativeLangA)
{
return false;
}
TiXmlElementA *element = _nativeLangA->ToElement();
const char *rtl = element->Attribute("RTL");
if (rtl)
_isRTL = (strcmp(rtl, "yes") == 0);
// get encoding
TiXmlDeclarationA *declaration = _nativeLangA->GetDocument()->FirstChild()->ToDeclaration();
if (declaration)
{
const char * encodingStr = declaration->Encoding();
EncodingMapper *em = EncodingMapper::getInstance();
_nativeLangEncoding = em->getEncodingFromString(encodingStr);
}
pNppParam->reloadContextMenuFromXmlTree(_mainMenuHandle);
generic_string pluginsTrans, windowTrans;
changeMenuLang(pluginsTrans, windowTrans);
int indexWindow = ::GetMenuItemCount(_mainMenuHandle) - 3;
if (_pluginsManager.hasPlugins() && pluginsTrans != TEXT(""))
{
::ModifyMenu(_mainMenuHandle, indexWindow - 1, MF_BYPOSITION, 0, pluginsTrans.c_str());
}
if (windowTrans != TEXT(""))
{
::ModifyMenu(_mainMenuHandle, indexWindow, MF_BYPOSITION, 0, windowTrans.c_str());
windowTrans += TEXT("...");
::ModifyMenu(_mainMenuHandle, IDM_WINDOW_WINDOWS, MF_BYCOMMAND, IDM_WINDOW_WINDOWS, windowTrans.c_str());
}
// Update scintilla context menu strings
vector<MenuItemUnit> & tmp = pNppParam->getContextMenuItems();
size_t len = tmp.size();
TCHAR menuName[64];
for (size_t i = 0 ; i < len ; i++)
{
if (tmp[i]._itemName == TEXT(""))
{
::GetMenuString(_mainMenuHandle, tmp[i]._cmdID, menuName, 64, MF_BYCOMMAND);
tmp[i]._itemName = purgeMenuItemString(menuName);
}
}
vector<CommandShortcut> & shortcuts = pNppParam->getUserShortcuts();
len = shortcuts.size();
for(size_t i = 0; i < len; i++)
{
CommandShortcut & csc = shortcuts[i];
::GetMenuString(_mainMenuHandle, csc.getID(), menuName, 64, MF_BYCOMMAND);
csc.setName(purgeMenuItemString(menuName, true).c_str());
}
_accelerator.updateFullMenu();
_scintaccelerator.updateKeys();
if (_tabPopupMenu.isCreated())
{
changeLangTabContextMenu();
}
if (_tabPopupDropMenu.isCreated())
{
changeLangTabDrapContextMenu();
}
if (_preference.isCreated())
{
changePrefereceDlgLang();
}
if (_configStyleDlg.isCreated())
{
changeConfigLang();
}
if (_findReplaceDlg.isCreated())
{
changeFindReplaceDlgLang();
}
if (_goToLineDlg.isCreated())
{
changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine");
}
if (_runDlg.isCreated())
{
changeDlgLang(_runDlg.getHSelf(), "Run");
}
if (_runMacroDlg.isCreated())
{
changeDlgLang(_runMacroDlg.getHSelf(), "MultiMacro");
}
if (_goToLineDlg.isCreated())
{
changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine");
}
if (_colEditorDlg.isCreated())
{
changeDlgLang(_colEditorDlg.getHSelf(), "ColumnEditor");
}
UserDefineDialog *udd = _pEditView->getUserDefineDlg();
if (udd->isCreated())
{
changeUserDefineLang();
}
_lastRecentFileList.setLangEncoding(_nativeLangEncoding);
return true;
}

View File

@ -0,0 +1,69 @@
//this file is part of notepad++
//Copyright (C)2010 Don HO <don.h@free.fr>
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifndef LOCALIZATION_H
#define LOCALIZATION_H
#ifndef TINYXMLA_INCLUDED
#include "tinyxmlA.h"
#endif //TINYXMLA_INCLUDED
class NativeLangSpeaker {
public:
NativeLangSpeaker():_nativeLangA(NULL), _nativeLangEncoding(CP_ACP), _isRTL(false), _fileName(NULL){};
void init(TiXmlDocumentA *nativeLangDocRootA);
/*
void set(TiXmlNodeA *nativeLangA, int nativeLangEncoding) {
_nativeLangA = nativeLangA;
_nativeLangEncoding = nativeLangEncoding;
};
*/
void changeConfigLang(HWND hDlg);
void changeLangTabContextMenu(HMENU hCM);
TiXmlNodeA * searchDlgNode(TiXmlNodeA *node, const char *dlgTagName);
bool changeDlgLang(HWND hDlg, const char *dlgTagName, char *title = NULL);
void changeLangTabDrapContextMenu(HMENU hCM);
void changeMenuLang(HMENU menuHandle, generic_string & pluginsTrans, generic_string & windowTrans);
void changeShortcutLang();
void changeShortcutmapperLang(ShortcutMapper * sm);
void changeStyleCtrlsLang(HWND hDlg, int *idArray, const char **translatedText);
void changeUserDefineLang(UserDefineDialog *userDefineDlg);
void changeFindReplaceDlgLang(FindReplaceDlg & findReplaceDlg);
void changePrefereceDlgLang(PreferenceDlg & preference);
bool isRTL() const {
return _isRTL;
};
const char * getFileName() const {
return _fileName;
};
const TiXmlNodeA * getNativeLangA() {
return _nativeLangA;
};
int getLangEncoding() const {
return _nativeLangEncoding;
};
private:
TiXmlNodeA *_nativeLangA;
int _nativeLangEncoding;
bool _isRTL;
const char *_fileName;
};
#endif // LOCALIZATION_H

View File

@ -490,6 +490,10 @@
RelativePath="..\src\lesDlgs.cpp"
>
</File>
<File
RelativePath="..\src\localization.cpp"
>
</File>
<File
RelativePath="..\src\MISC\Exception\MiniDumper.cpp"
>
@ -510,10 +514,6 @@
RelativePath="..\src\NppIO.cpp"
>
</File>
<File
RelativePath="..\src\NppLocalization.cpp"
>
</File>
<File
RelativePath="..\src\NppNotification.cpp"
>
@ -815,6 +815,10 @@
RelativePath="..\src\lesDlgs.h"
>
</File>
<File
RelativePath="..\src\localization.h"
>
</File>
<File
RelativePath="..\src\localizationstring.h"
>