Skip to content

Commit

Permalink
[NEW_FEATURE] Make Recent File List in submenu (in progress).
Browse files Browse the repository at this point in the history
- Notepad-plus svn trunk @ 778
  • Loading branch information
donho committed Jun 18, 2011
1 parent 2286eef commit 6bd466e
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 77 deletions.
18 changes: 8 additions & 10 deletions PowerEditor/src/Notepad_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down Expand Up @@ -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());
Expand Down
33 changes: 0 additions & 33 deletions PowerEditor/src/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -1361,39 +1361,6 @@ class NppParameters

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() {
Expand Down
15 changes: 6 additions & 9 deletions PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
78 changes: 55 additions & 23 deletions PowerEditor/src/lastRecentFileList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

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);

::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
void LastRecentFileList::updateMenu()
{
if (!_hasSeparators && _size > 0)
{
//add separators
NativeLangSpeaker *pNativeLangSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker();

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);

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
{
Expand All @@ -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);
}
Expand Down
8 changes: 7 additions & 1 deletion PowerEditor/src/lastRecentFileList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -50,6 +50,7 @@ public :
return _size;
};


int getMaxNbLRF() const {
return NB_MAX_LRF_FILE;
};
Expand All @@ -73,13 +74,18 @@ public :
_nativeLangEncoding = nativeLangEncoding;
};

bool isSubMenuMode() const {
return (_hParentMenu != NULL);
}

private:
recentList _lrfl;
int _userMax;
int _size;
int _nativeLangEncoding;

// For the menu
HMENU _hParentMenu;
HMENU _hMenu;
int _posBase;
int _idBase;
Expand Down
82 changes: 81 additions & 1 deletion PowerEditor/src/localization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -119,7 +199,7 @@ void NativeLangSpeaker::changeMenuLang(HMENU menuHandle, generic_string & plugin
#endif
}
}
}
}
}

TiXmlNodeA *menuCommandsRoot = mainMenu->FirstChild("Commands");
Expand Down
2 changes: 2 additions & 0 deletions PowerEditor/src/localization.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class NativeLangSpeaker {
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);
Expand Down

0 comments on commit 6bd466e

Please sign in to comment.