[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
This commit is contained in:
Don Ho 2011-06-18 22:54:32 +00:00
parent 9ea90c6449
commit 61b3183593
7 changed files with 157 additions and 75 deletions

View File

@ -430,7 +430,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
int nbLRFile = pNppParam->getNbLRFile(); int nbLRFile = pNppParam->getNbLRFile();
int pos = IDM_FILEMENU_LASTONE - IDM_FILE + 2; 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()); _lastRecentFileList.setLangEncoding(_nativeLangSpeaker.getLangEncoding());
for (int i = 0 ; i < nbLRFile ; i++) for (int i = 0 ; i < nbLRFile ; i++)
{ {
@ -3336,15 +3336,13 @@ bool Notepad_plus::addCurrentMacro()
// Insert the separator and modify/delete command // Insert the separator and modify/delete command
::InsertMenu(hMacroMenu, posBase + nbMacro + 1, MF_BYPOSITION, (unsigned int)-1, 0); ::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..."; NativeLangSpeaker *pNativeLangSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker();
#ifdef UNICODE generic_string nativeLangShortcutMapperMacro = pNativeLangSpeaker->getNativeLangMenuString(IDM_SETTING_SHORTCUT_MAPPER_MACRO);
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); if (nativeLangShortcutMapperMacro == TEXT(""))
const wchar_t * shortcutMapperMacroStrW = wmc->char2wchar(shortcutMapperMacroStr, _nativeLangSpeaker.getLangEncoding()); nativeLangShortcutMapperMacro = TEXT("Modify Shortcut/Delete Macro...");
::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, nativeLangShortcutMapperMacro.c_str());
::InsertMenu(hMacroMenu, posBase + nbMacro + 2, MF_BYCOMMAND, IDM_SETTING_SHORTCUT_MAPPER_MACRO, shortcutMapperMacroStr);
#endif
} }
theMacros.push_back(ms); theMacros.push_back(ms);
::InsertMenu(hMacroMenu, posBase + nbMacro, MF_BYPOSITION, cmdID, ms.toMenuItemString().c_str()); ::InsertMenu(hMacroMenu, posBase + nbMacro, MF_BYPOSITION, cmdID, ms.toMenuItemString().c_str());

View File

@ -1361,39 +1361,6 @@ public:
FindDlgTabTitiles & getFindDlgTabTitiles() { return _findDlgTabTitiles;}; 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 asNotepadStyle() const {return _asNotepadStyle;};
bool reloadPluginCmds() { bool reloadPluginCmds() {

View File

@ -254,15 +254,12 @@ BOOL CALLBACK RunDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM)
{ {
// Insert the separator and modify/delete command // Insert the separator and modify/delete command
::InsertMenu(hRunMenu, posBase + nbCmd + 1, MF_BYPOSITION, (unsigned int)-1, 0); ::InsertMenu(hRunMenu, posBase + nbCmd + 1, MF_BYPOSITION, (unsigned int)-1, 0);
const char * nativeLangShortcutMapperRun = (NppParameters::getInstance())->getNativeLangMenuStringA(IDM_SETTING_SHORTCUT_MAPPER_RUN); NativeLangSpeaker *pNativeLangSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker();
const char * shortcutMapperRunStr = nativeLangShortcutMapperRun?nativeLangShortcutMapperRun:"Modify Shortcut/Delete Command..."; generic_string nativeLangShortcutMapperMacro = pNativeLangSpeaker->getNativeLangMenuString(IDM_SETTING_SHORTCUT_MAPPER_MACRO);
#ifdef UNICODE if (nativeLangShortcutMapperMacro == TEXT(""))
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); nativeLangShortcutMapperMacro = TEXT("Modify Shortcut/Delete Command...");
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); ::InsertMenu(hRunMenu, posBase + nbCmd + 2, MF_BYCOMMAND, IDM_SETTING_SHORTCUT_MAPPER_RUN, nativeLangShortcutMapperMacro.c_str());
#else
::InsertMenu(hRunMenu, posBase + nbCmd + 2, MF_BYCOMMAND, IDM_SETTING_SHORTCUT_MAPPER_RUN, shortcutMapperRunStr);
#endif
} }
(NppParameters::getInstance())->getAccelerator()->updateShortcuts(); (NppParameters::getInstance())->getAccelerator()->updateShortcuts();
} }

View File

@ -18,9 +18,21 @@
#include "precompiledHeaders.h" #include "precompiledHeaders.h"
#include "lastRecentFileList.h" #include "lastRecentFileList.h"
#include "menuCmdID.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; _idBase = idBase;
_posBase = posBase; _posBase = posBase;
_nativeLangEncoding = NPP_CP_WIN_1252; _nativeLangEncoding = NPP_CP_WIN_1252;
@ -29,28 +41,37 @@ void LastRecentFileList::initMenu(HMENU hMenu, int idBase, int posBase) {
_idFreeArray[i] = true; _idFreeArray[i] = true;
}; };
void LastRecentFileList::updateMenu() { void LastRecentFileList::updateMenu()
if (!_hasSeparators && _size > 0) { //add separators {
const char * nativeLangOpenAllFiles = (NppParameters::getInstance())->getNativeLangMenuStringA(IDM_OPEN_ALL_RECENT_FILE); if (!_hasSeparators && _size > 0)
const char * nativeLangCleanFilesList = (NppParameters::getInstance())->getNativeLangMenuStringA(IDM_CLEAN_RECENT_FILE_LIST); {
//add separators
NativeLangSpeaker *pNativeLangSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker();
const char * openAllFileStr = nativeLangOpenAllFiles?nativeLangOpenAllFiles:"Open All Recent Files"; generic_string recentFileList = pNativeLangSpeaker->getSpecialMenuEntryName("RecentFiles");
const char * cleanFileListStr = nativeLangCleanFilesList?nativeLangCleanFilesList:"Empty Recent Files List"; generic_string openAllFiles = pNativeLangSpeaker->getNativeLangMenuString(IDM_OPEN_ALL_RECENT_FILE);
::InsertMenu(_hMenu, _posBase + 0, MF_BYPOSITION, UINT(-1), 0); generic_string cleanFileList = pNativeLangSpeaker->getNativeLangMenuString(IDM_CLEAN_RECENT_FILE_LIST);
#ifdef UNICODE
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
const wchar_t * openAllFileStrW = wmc->char2wchar(openAllFileStr, _nativeLangEncoding);
::InsertMenu(_hMenu, _posBase + 1, MF_BYPOSITION, IDM_OPEN_ALL_RECENT_FILE, openAllFileStrW); if (recentFileList == TEXT(""))
const wchar_t * cleanFileListStrW = wmc->char2wchar(cleanFileListStr, _nativeLangEncoding); recentFileList = TEXT("Recent Files");
::InsertMenu(_hMenu, _posBase + 2, MF_BYPOSITION, IDM_CLEAN_RECENT_FILE_LIST, cleanFileListStrW); if (openAllFiles == TEXT(""))
#else openAllFiles = TEXT("Open All Recent Files");
::InsertMenu(_hMenu, _posBase + 1, MF_BYPOSITION, IDM_OPEN_ALL_RECENT_FILE, openAllFileStr); if (cleanFileList == TEXT(""))
::InsertMenu(_hMenu, _posBase + 2, MF_BYPOSITION, IDM_CLEAN_RECENT_FILE_LIST, cleanFileListStr); cleanFileList = TEXT("Empty Recent Files List");
#endif
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); ::InsertMenu(_hMenu, _posBase + 3, MF_BYPOSITION, UINT(-1), 0);
_hasSeparators = true; _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 else if (_hasSeparators && _size == 0) //remove separators
{ {
@ -60,15 +81,26 @@ void LastRecentFileList::updateMenu() {
::RemoveMenu(_hMenu, _posBase + 0, MF_BYPOSITION); ::RemoveMenu(_hMenu, _posBase + 0, MF_BYPOSITION);
_hasSeparators = false; _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 //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); ::RemoveMenu(_hMenu, _lrfl.at(i)._id, MF_BYCOMMAND);
} }
//Then readd them, so everything stays in sync //Then readd them, so everything stays in sync
TCHAR buffer[MAX_PATH]; 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()); BuildMenuFileName(buffer, 100, j, _lrfl.at(j)._name.c_str());
::InsertMenu(_hMenu, _posBase + j, MF_BYPOSITION, _lrfl.at(j)._id, buffer); ::InsertMenu(_hMenu, _posBase + j, MF_BYPOSITION, _lrfl.at(j)._id, buffer);
} }

View File

@ -37,7 +37,7 @@ public :
_userMax = (NppParameters::getInstance())->getNbMaxFile(); _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(); void updateMenu();
@ -50,6 +50,7 @@ public :
return _size; return _size;
}; };
int getMaxNbLRF() const { int getMaxNbLRF() const {
return NB_MAX_LRF_FILE; return NB_MAX_LRF_FILE;
}; };
@ -73,6 +74,10 @@ public :
_nativeLangEncoding = nativeLangEncoding; _nativeLangEncoding = nativeLangEncoding;
}; };
bool isSubMenuMode() const {
return (_hParentMenu != NULL);
}
private: private:
recentList _lrfl; recentList _lrfl;
int _userMax; int _userMax;
@ -80,6 +85,7 @@ private:
int _nativeLangEncoding; int _nativeLangEncoding;
// For the menu // For the menu
HMENU _hParentMenu;
HMENU _hMenu; HMENU _hMenu;
int _posBase; int _posBase;
int _idBase; int _idBase;

View File

@ -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) void NativeLangSpeaker::changeMenuLang(HMENU menuHandle, generic_string & pluginsTrans, generic_string & windowTrans)
{ {
if (!_nativeLangA) return; if (!_nativeLangA) return;
@ -119,7 +199,7 @@ void NativeLangSpeaker::changeMenuLang(HMENU menuHandle, generic_string & plugin
#endif #endif
} }
} }
} }
} }
TiXmlNodeA *menuCommandsRoot = mainMenu->FirstChild("Commands"); TiXmlNodeA *menuCommandsRoot = mainMenu->FirstChild("Commands");

View File

@ -34,6 +34,8 @@ public:
TiXmlNodeA * searchDlgNode(TiXmlNodeA *node, const char *dlgTagName); TiXmlNodeA * searchDlgNode(TiXmlNodeA *node, const char *dlgTagName);
bool changeDlgLang(HWND hDlg, const char *dlgTagName, char *title = NULL); bool changeDlgLang(HWND hDlg, const char *dlgTagName, char *title = NULL);
void changeLangTabDrapContextMenu(HMENU hCM); 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 changeMenuLang(HMENU menuHandle, generic_string & pluginsTrans, generic_string & windowTrans);
void changeShortcutLang(); void changeShortcutLang();
void changeShortcutmapperLang(ShortcutMapper * sm); void changeShortcutmapperLang(ShortcutMapper * sm);