From 61b31835933658b6d0489f0edb6ecf9f4819fa4a Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sat, 18 Jun 2011 22:54:32 +0000 Subject: [PATCH] [NEW_FEATURE] Make Recent File List in submenu (in progress). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@778 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 18 ++-- PowerEditor/src/Parameters.h | 33 -------- .../StaticDialog/RunDlg/RunDlg.cpp | 15 ++-- PowerEditor/src/lastRecentFileList.cpp | 74 ++++++++++++----- PowerEditor/src/lastRecentFileList.h | 8 +- PowerEditor/src/localization.cpp | 82 ++++++++++++++++++- PowerEditor/src/localization.h | 2 + 7 files changed, 157 insertions(+), 75 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 3609926ad..201d1431a 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -430,7 +430,7 @@ LRESULT Notepad_plus::init(HWND hwnd) int nbLRFile = pNppParam->getNbLRFile(); int pos = IDM_FILEMENU_LASTONE - IDM_FILE + 2; - _lastRecentFileList.initMenu(hFileMenu, IDM_FILEMENU_LASTONE + 1, pos); + _lastRecentFileList.initMenu(hFileMenu, IDM_FILEMENU_LASTONE + 1, pos, true); _lastRecentFileList.setLangEncoding(_nativeLangSpeaker.getLangEncoding()); for (int i = 0 ; i < nbLRFile ; i++) { @@ -3336,15 +3336,13 @@ bool Notepad_plus::addCurrentMacro() // Insert the separator and modify/delete command ::InsertMenu(hMacroMenu, posBase + nbMacro + 1, MF_BYPOSITION, (unsigned int)-1, 0); - const char * nativeLangShortcutMapperMacro = (NppParameters::getInstance())->getNativeLangMenuStringA(IDM_SETTING_SHORTCUT_MAPPER_MACRO); - const char * shortcutMapperMacroStr = nativeLangShortcutMapperMacro?nativeLangShortcutMapperMacro:"Modify Shortcut/Delete Macro..."; -#ifdef UNICODE - WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); - const wchar_t * shortcutMapperMacroStrW = wmc->char2wchar(shortcutMapperMacroStr, _nativeLangSpeaker.getLangEncoding()); - ::InsertMenu(hMacroMenu, posBase + nbMacro + 2, MF_BYCOMMAND, IDM_SETTING_SHORTCUT_MAPPER_MACRO, shortcutMapperMacroStrW); -#else - ::InsertMenu(hMacroMenu, posBase + nbMacro + 2, MF_BYCOMMAND, IDM_SETTING_SHORTCUT_MAPPER_MACRO, shortcutMapperMacroStr); -#endif + + NativeLangSpeaker *pNativeLangSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker(); + generic_string nativeLangShortcutMapperMacro = pNativeLangSpeaker->getNativeLangMenuString(IDM_SETTING_SHORTCUT_MAPPER_MACRO); + if (nativeLangShortcutMapperMacro == TEXT("")) + nativeLangShortcutMapperMacro = TEXT("Modify Shortcut/Delete Macro..."); + + ::InsertMenu(hMacroMenu, posBase + nbMacro + 2, MF_BYCOMMAND, IDM_SETTING_SHORTCUT_MAPPER_MACRO, nativeLangShortcutMapperMacro.c_str()); } theMacros.push_back(ms); ::InsertMenu(hMacroMenu, posBase + nbMacro, MF_BYPOSITION, cmdID, ms.toMenuItemString().c_str()); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index eaea6bb61..215af55a4 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1361,39 +1361,6 @@ public: FindDlgTabTitiles & getFindDlgTabTitiles() { return _findDlgTabTitiles;}; - const char * getNativeLangMenuStringA(int itemID) { - if (!_pXmlNativeLangDocA) - return NULL; - - TiXmlNodeA * node = _pXmlNativeLangDocA->FirstChild("NotepadPlus"); - if (!node) return NULL; - - node = node->FirstChild("Native-Langue"); - if (!node) return NULL; - - node = node->FirstChild("Menu"); - if (!node) return NULL; - - node = node->FirstChild("Main"); - if (!node) return NULL; - - node = node->FirstChild("Commands"); - if (!node) return NULL; - - for (TiXmlNodeA *childNode = node->FirstChildElement("Item"); - childNode ; - childNode = childNode->NextSibling("Item") ) - { - TiXmlElementA *element = childNode->ToElement(); - int id; - if (element->Attribute("id", &id) && (id == itemID)) - { - return element->Attribute("name"); - } - } - return NULL; - }; - bool asNotepadStyle() const {return _asNotepadStyle;}; bool reloadPluginCmds() { diff --git a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp index 60335772a..7a935e4e6 100644 --- a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp +++ b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp @@ -254,15 +254,12 @@ BOOL CALLBACK RunDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) { // Insert the separator and modify/delete command ::InsertMenu(hRunMenu, posBase + nbCmd + 1, MF_BYPOSITION, (unsigned int)-1, 0); - const char * nativeLangShortcutMapperRun = (NppParameters::getInstance())->getNativeLangMenuStringA(IDM_SETTING_SHORTCUT_MAPPER_RUN); - const char * shortcutMapperRunStr = nativeLangShortcutMapperRun?nativeLangShortcutMapperRun:"Modify Shortcut/Delete Command..."; -#ifdef UNICODE - WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); - const wchar_t * shortcutMapperRunStrW = wmc->char2wchar(shortcutMapperRunStr, ::SendMessage(_hParent, NPPM_GETCURRENTNATIVELANGENCODING, 0, 0)); - ::InsertMenu(hRunMenu, posBase + nbCmd + 2, MF_BYCOMMAND, IDM_SETTING_SHORTCUT_MAPPER_RUN, shortcutMapperRunStrW); -#else - ::InsertMenu(hRunMenu, posBase + nbCmd + 2, MF_BYCOMMAND, IDM_SETTING_SHORTCUT_MAPPER_RUN, shortcutMapperRunStr); -#endif + NativeLangSpeaker *pNativeLangSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker(); + generic_string nativeLangShortcutMapperMacro = pNativeLangSpeaker->getNativeLangMenuString(IDM_SETTING_SHORTCUT_MAPPER_MACRO); + if (nativeLangShortcutMapperMacro == TEXT("")) + nativeLangShortcutMapperMacro = TEXT("Modify Shortcut/Delete Command..."); + + ::InsertMenu(hRunMenu, posBase + nbCmd + 2, MF_BYCOMMAND, IDM_SETTING_SHORTCUT_MAPPER_RUN, nativeLangShortcutMapperMacro.c_str()); } (NppParameters::getInstance())->getAccelerator()->updateShortcuts(); } diff --git a/PowerEditor/src/lastRecentFileList.cpp b/PowerEditor/src/lastRecentFileList.cpp index 8616e8934..dc9dbdc3f 100644 --- a/PowerEditor/src/lastRecentFileList.cpp +++ b/PowerEditor/src/lastRecentFileList.cpp @@ -18,9 +18,21 @@ #include "precompiledHeaders.h" #include "lastRecentFileList.h" #include "menuCmdID.h" +#include "localization.h" + +void LastRecentFileList::initMenu(HMENU hMenu, int idBase, int posBase, bool doSubMenu) +{ + if (doSubMenu) + { + _hParentMenu = hMenu; + _hMenu = ::CreatePopupMenu(); + } + else + { + _hParentMenu = NULL; + _hMenu = hMenu; + } -void LastRecentFileList::initMenu(HMENU hMenu, int idBase, int posBase) { - _hMenu = hMenu; _idBase = idBase; _posBase = posBase; _nativeLangEncoding = NPP_CP_WIN_1252; @@ -29,28 +41,37 @@ void LastRecentFileList::initMenu(HMENU hMenu, int idBase, int posBase) { _idFreeArray[i] = true; }; -void LastRecentFileList::updateMenu() { - if (!_hasSeparators && _size > 0) { //add separators - const char * nativeLangOpenAllFiles = (NppParameters::getInstance())->getNativeLangMenuStringA(IDM_OPEN_ALL_RECENT_FILE); - const char * nativeLangCleanFilesList = (NppParameters::getInstance())->getNativeLangMenuStringA(IDM_CLEAN_RECENT_FILE_LIST); +void LastRecentFileList::updateMenu() +{ + if (!_hasSeparators && _size > 0) + { + //add separators + NativeLangSpeaker *pNativeLangSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker(); - const char * openAllFileStr = nativeLangOpenAllFiles?nativeLangOpenAllFiles:"Open All Recent Files"; - const char * cleanFileListStr = nativeLangCleanFilesList?nativeLangCleanFilesList:"Empty Recent Files List"; - ::InsertMenu(_hMenu, _posBase + 0, MF_BYPOSITION, UINT(-1), 0); -#ifdef UNICODE - WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); - const wchar_t * openAllFileStrW = wmc->char2wchar(openAllFileStr, _nativeLangEncoding); + generic_string recentFileList = pNativeLangSpeaker->getSpecialMenuEntryName("RecentFiles"); + generic_string openAllFiles = pNativeLangSpeaker->getNativeLangMenuString(IDM_OPEN_ALL_RECENT_FILE); + generic_string cleanFileList = pNativeLangSpeaker->getNativeLangMenuString(IDM_CLEAN_RECENT_FILE_LIST); - ::InsertMenu(_hMenu, _posBase + 1, MF_BYPOSITION, IDM_OPEN_ALL_RECENT_FILE, openAllFileStrW); - const wchar_t * cleanFileListStrW = wmc->char2wchar(cleanFileListStr, _nativeLangEncoding); - ::InsertMenu(_hMenu, _posBase + 2, MF_BYPOSITION, IDM_CLEAN_RECENT_FILE_LIST, cleanFileListStrW); -#else - ::InsertMenu(_hMenu, _posBase + 1, MF_BYPOSITION, IDM_OPEN_ALL_RECENT_FILE, openAllFileStr); - ::InsertMenu(_hMenu, _posBase + 2, MF_BYPOSITION, IDM_CLEAN_RECENT_FILE_LIST, cleanFileListStr); -#endif + if (recentFileList == TEXT("")) + recentFileList = TEXT("Recent Files"); + if (openAllFiles == TEXT("")) + openAllFiles = TEXT("Open All Recent Files"); + if (cleanFileList == TEXT("")) + cleanFileList = TEXT("Empty Recent Files List"); + + if (!isSubMenuMode()) + ::InsertMenu(_hMenu, _posBase + 0, MF_BYPOSITION, UINT(-1), 0); + + ::InsertMenu(_hMenu, _posBase + 1, MF_BYPOSITION, IDM_OPEN_ALL_RECENT_FILE, openAllFiles.c_str()); + ::InsertMenu(_hMenu, _posBase + 2, MF_BYPOSITION, IDM_CLEAN_RECENT_FILE_LIST, cleanFileList.c_str()); ::InsertMenu(_hMenu, _posBase + 3, MF_BYPOSITION, UINT(-1), 0); _hasSeparators = true; + if (isSubMenuMode()) + { + ::InsertMenu(_hParentMenu, _posBase + 0, MF_BYPOSITION | MF_POPUP, UINT(_hMenu), (LPCTSTR)recentFileList.c_str()); + ::InsertMenu(_hParentMenu, _posBase + 1, MF_BYPOSITION, UINT(-1), 0); + } } else if (_hasSeparators && _size == 0) //remove separators { @@ -60,15 +81,26 @@ void LastRecentFileList::updateMenu() { ::RemoveMenu(_hMenu, _posBase + 0, MF_BYPOSITION); _hasSeparators = false; + if (isSubMenuMode()) + { + // Remove "Recent Files" Entry and the separator from the main menu + ::RemoveMenu(_hParentMenu, _posBase + 1, MF_BYPOSITION); + ::RemoveMenu(_hParentMenu, _posBase + 0, MF_BYPOSITION); + + // Remove the last left separator from the submenu + ::RemoveMenu(_hMenu, 0, MF_BYPOSITION); + } } //Remove all menu items - for(int i = 0; i < _size; i++) { + for(int i = 0; i < _size; i++) + { ::RemoveMenu(_hMenu, _lrfl.at(i)._id, MF_BYCOMMAND); } //Then readd them, so everything stays in sync TCHAR buffer[MAX_PATH]; - for(int j = 0; j < _size; j++) { + for(int j = 0; j < _size; j++) + { BuildMenuFileName(buffer, 100, j, _lrfl.at(j)._name.c_str()); ::InsertMenu(_hMenu, _posBase + j, MF_BYPOSITION, _lrfl.at(j)._id, buffer); } diff --git a/PowerEditor/src/lastRecentFileList.h b/PowerEditor/src/lastRecentFileList.h index 0ec3f539e..db22ff90f 100644 --- a/PowerEditor/src/lastRecentFileList.h +++ b/PowerEditor/src/lastRecentFileList.h @@ -37,7 +37,7 @@ public : _userMax = (NppParameters::getInstance())->getNbMaxFile(); }; - void initMenu(HMENU hMenu, int idBase, int posBase); + void initMenu(HMENU hMenu, int idBase, int posBase, bool doSubMenu = false); void updateMenu(); @@ -50,6 +50,7 @@ public : return _size; }; + int getMaxNbLRF() const { return NB_MAX_LRF_FILE; }; @@ -73,6 +74,10 @@ public : _nativeLangEncoding = nativeLangEncoding; }; + bool isSubMenuMode() const { + return (_hParentMenu != NULL); + } + private: recentList _lrfl; int _userMax; @@ -80,6 +85,7 @@ private: int _nativeLangEncoding; // For the menu + HMENU _hParentMenu; HMENU _hMenu; int _posBase; int _idBase; diff --git a/PowerEditor/src/localization.cpp b/PowerEditor/src/localization.cpp index 0da298d22..1c0d66a8f 100644 --- a/PowerEditor/src/localization.cpp +++ b/PowerEditor/src/localization.cpp @@ -62,6 +62,86 @@ void NativeLangSpeaker::init(TiXmlDocumentA *nativeLangDocRootA, bool loadIfEngl } } +generic_string NativeLangSpeaker::getSpecialMenuEntryName(const char *entryName) +{ + if (!_nativeLangA) return TEXT(""); + TiXmlNodeA *mainMenu = _nativeLangA->FirstChild("Menu"); + if (!mainMenu) return TEXT(""); + mainMenu = mainMenu->FirstChild("Main"); + if (!mainMenu) return TEXT(""); + TiXmlNodeA *entriesRoot = mainMenu->FirstChild("Entries"); + if (!entriesRoot) return TEXT(""); + const char *idName = NULL; + +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); +#endif + + for (TiXmlNodeA *childNode = entriesRoot->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + + idName = element->Attribute("idName"); + if (idName) + { + const char *name = element->Attribute("name"); + if (!strcmp(idName, entryName)) + { +#ifdef UNICODE + return wmc->char2wchar(name, _nativeLangEncoding); +#else + return name; +#endif + } + } + } + return TEXT(""); +} + +generic_string NativeLangSpeaker::getNativeLangMenuString(int itemID) +{ + if (!_nativeLangA) + return TEXT(""); + + TiXmlNodeA *node = _nativeLangA->FirstChild("Menu"); + if (!node) return TEXT(""); + + node = node->FirstChild("Main"); + if (!node) return TEXT(""); + + node = node->FirstChild("Commands"); + if (!node) return TEXT(""); + +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); +#endif + + for (TiXmlNodeA *childNode = node->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int id; + if (element->Attribute("id", &id) && (id == itemID)) + { + const char *name = element->Attribute("name"); + if (name) + { +#ifdef UNICODE + return wmc->char2wchar(name, _nativeLangEncoding); +#else + return name; +#endif + } + } + } + return TEXT(""); +} + + + void NativeLangSpeaker::changeMenuLang(HMENU menuHandle, generic_string & pluginsTrans, generic_string & windowTrans) { if (!_nativeLangA) return; @@ -119,7 +199,7 @@ void NativeLangSpeaker::changeMenuLang(HMENU menuHandle, generic_string & plugin #endif } } - } + } } TiXmlNodeA *menuCommandsRoot = mainMenu->FirstChild("Commands"); diff --git a/PowerEditor/src/localization.h b/PowerEditor/src/localization.h index 531c44b43..549aa7e60 100644 --- a/PowerEditor/src/localization.h +++ b/PowerEditor/src/localization.h @@ -34,6 +34,8 @@ public: TiXmlNodeA * searchDlgNode(TiXmlNodeA *node, const char *dlgTagName); bool changeDlgLang(HWND hDlg, const char *dlgTagName, char *title = NULL); void changeLangTabDrapContextMenu(HMENU hCM); + generic_string getSpecialMenuEntryName(const char *entryName); + generic_string getNativeLangMenuString(int itemID); void changeMenuLang(HMENU menuHandle, generic_string & pluginsTrans, generic_string & windowTrans); void changeShortcutLang(); void changeShortcutmapperLang(ShortcutMapper * sm);