[UPDATE] MRU file list under the File menu is limited to 100 characters per file. Longer files are fitted to 100 characters by replacing path components with ellipses. (code reuse - Window menu)
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@466 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
83ac50e3dd
commit
3067f9f93c
@ -16,6 +16,7 @@
|
||||
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
//#include "Common.h" //use force include
|
||||
#include <shlwapi.h>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include "Common.h"
|
||||
@ -375,3 +376,70 @@ std::string wstring2string(const std::wstring & rwString, UINT codepage)
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
static TCHAR* convertFileName(TCHAR *buffer, const TCHAR *filename)
|
||||
{
|
||||
TCHAR *b = buffer;
|
||||
const TCHAR *p = filename;
|
||||
while (*p)
|
||||
{
|
||||
if (*p == '&') *b++ = '&';
|
||||
*b++ = *p++;
|
||||
}
|
||||
*b = 0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
TCHAR *BuildMenuFileName(TCHAR *buffer, int len, int pos, const TCHAR *filename)
|
||||
{
|
||||
TCHAR cwd[MAX_PATH];
|
||||
buffer[0] = 0;
|
||||
GetCurrentDirectory(_countof(cwd), cwd);
|
||||
lstrcat(cwd, TEXT("\\"));
|
||||
|
||||
TCHAR *itr = buffer;
|
||||
TCHAR *end = buffer + len - 1;
|
||||
if (pos < 9)
|
||||
{
|
||||
*itr++ = '&';
|
||||
*itr++ = '1' + pos;
|
||||
}
|
||||
else if (pos == 9)
|
||||
{
|
||||
*itr++ = '1';
|
||||
*itr++ = '&';
|
||||
*itr++ = '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintf(itr, TEXT("%d"), pos+1);
|
||||
itr = itr + lstrlen(itr);
|
||||
}
|
||||
*itr++ = ':';
|
||||
*itr++ = ' ';
|
||||
if (0 == generic_strnicmp(filename, cwd, lstrlen(cwd)))
|
||||
{
|
||||
TCHAR cnvName[MAX_PATH];
|
||||
const TCHAR *s1 = PathFindFileName(filename);
|
||||
int len = lstrlen(s1);
|
||||
if (len < (end-itr))
|
||||
{
|
||||
lstrcpy(cnvName, s1);
|
||||
}
|
||||
else
|
||||
{
|
||||
int n = (len-3-(itr-buffer))/2;
|
||||
generic_strncpy(cnvName, s1, n);
|
||||
lstrcpy(cnvName+n, TEXT("..."));
|
||||
lstrcat(cnvName, s1 + lstrlen(s1) - n);
|
||||
}
|
||||
convertFileName(itr, cnvName);
|
||||
}
|
||||
else
|
||||
{
|
||||
TCHAR cnvName[MAX_PATH*2];
|
||||
const TCHAR *s1 = convertFileName(cnvName, filename);
|
||||
PathCompactPathEx(itr, filename, len - (itr-buffer), 0);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
@ -103,6 +103,8 @@ void ScreenRectToClientRect(HWND hWnd, RECT* rect);
|
||||
std::wstring string2wstring(const std::string & rString, UINT codepage);
|
||||
std::string wstring2string(const std::wstring & rwString, UINT codepage);
|
||||
|
||||
TCHAR *BuildMenuFileName(TCHAR *buffer, int len, int pos, const TCHAR *filename);
|
||||
|
||||
class WcharMbcsConvertor {
|
||||
public:
|
||||
static WcharMbcsConvertor * getInstance() {return _pSelf;};
|
||||
|
@ -7206,14 +7206,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
|
||||
for (int i = 0 ; i < nbLRFile ; i++)
|
||||
{
|
||||
generic_string * stdStr = pNppParam->getLRFile(i);
|
||||
if (nppGUI._checkHistoryFiles)
|
||||
{
|
||||
if (PathFileExists(stdStr->c_str()))
|
||||
{
|
||||
_lastRecentFileList.add(stdStr->c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
if (!nppGUI._checkHistoryFiles || PathFileExists(stdStr->c_str()))
|
||||
{
|
||||
_lastRecentFileList.add(stdStr->c_str());
|
||||
}
|
||||
|
@ -787,7 +787,7 @@ void WindowsMenu::initPopupMenu(HMENU hMenu, DocTabView *pTab)
|
||||
memset(&mii, 0, sizeof(mii));
|
||||
mii.cbSize = sizeof(mii);
|
||||
mii.fMask = MIIM_STRING|MIIM_STATE|MIIM_ID;
|
||||
mii.dwTypeData = buildFileName(buffer, 60, pos, buf->getFileName());
|
||||
mii.dwTypeData = BuildMenuFileName(buffer, 60, pos, buf->getFileName());
|
||||
mii.fState &= ~(MF_GRAYED|MF_DISABLED|MF_CHECKED);
|
||||
if (pos == curDoc)
|
||||
mii.fState |= MF_CHECKED;
|
||||
@ -814,69 +814,3 @@ void WindowsMenu::uninitPopupMenu(HMENU hMenu, ScintillaEditView *pView)
|
||||
}
|
||||
}
|
||||
*/
|
||||
static TCHAR* convertFileName(TCHAR *buffer, const TCHAR *filename)
|
||||
{
|
||||
TCHAR *b = buffer;
|
||||
const TCHAR *p = filename;
|
||||
while (*p)
|
||||
{
|
||||
if (*p == '&') *b++ = '&';
|
||||
*b++ = *p++;
|
||||
}
|
||||
*b = 0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
TCHAR *WindowsMenu::buildFileName(TCHAR *buffer, int len, int pos, const TCHAR *filename)
|
||||
{
|
||||
TCHAR cwd[MAX_PATH];
|
||||
buffer[0] = 0;
|
||||
GetCurrentDirectory(_countof(cwd), cwd);
|
||||
lstrcat(cwd, TEXT("\\"));
|
||||
|
||||
TCHAR *itr = buffer;
|
||||
TCHAR *end = buffer + len - 1;
|
||||
if (pos < 9)
|
||||
{
|
||||
*itr++ = '&';
|
||||
*itr++ = '1' + pos;
|
||||
}
|
||||
else if (pos == 9)
|
||||
{
|
||||
*itr++ = '1';
|
||||
*itr++ = '&';
|
||||
*itr++ = '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
wsprintf(itr, TEXT("%d"), pos+1);
|
||||
itr = itr + lstrlen(itr);
|
||||
}
|
||||
*itr++ = ':';
|
||||
*itr++ = ' ';
|
||||
if (0 == generic_strnicmp(filename, cwd, lstrlen(cwd)))
|
||||
{
|
||||
TCHAR cnvName[MAX_PATH];
|
||||
const TCHAR *s1 = PathFindFileName(filename);
|
||||
int len = lstrlen(s1);
|
||||
if (len < (end-itr))
|
||||
{
|
||||
lstrcpy(cnvName, s1);
|
||||
}
|
||||
else
|
||||
{
|
||||
int n = (len-3-(itr-buffer))/2;
|
||||
generic_strncpy(cnvName, s1, n);
|
||||
lstrcpy(cnvName+n, TEXT("..."));
|
||||
lstrcat(cnvName, s1 + lstrlen(s1) - n);
|
||||
}
|
||||
convertFileName(itr, cnvName);
|
||||
}
|
||||
else
|
||||
{
|
||||
TCHAR cnvName[MAX_PATH*2];
|
||||
const TCHAR *s1 = convertFileName(cnvName, filename);
|
||||
PathCompactPathEx(itr, filename, len - (itr-buffer), 0);
|
||||
}
|
||||
return buffer;
|
||||
}
|
@ -106,7 +106,6 @@ public:
|
||||
void initPopupMenu(HMENU hMenu, DocTabView *pTab);
|
||||
//void uninitPopupMenu(HMENU hMenu, ScintillaEditView *pView);
|
||||
private:
|
||||
TCHAR *buildFileName(TCHAR *buffer, int len, int pos, const TCHAR *filename);
|
||||
HMENU _hMenu;
|
||||
};
|
||||
|
||||
|
@ -65,17 +65,10 @@ void LastRecentFileList::updateMenu() {
|
||||
::RemoveMenu(_hMenu, _lrfl.at(i)._id, MF_BYCOMMAND);
|
||||
}
|
||||
//Then readd them, so everything stays in sync
|
||||
TCHAR indexBuffer[4];
|
||||
TCHAR buffer[MAX_PATH];
|
||||
for(int j = 0; j < _size; j++) {
|
||||
std::generic_string menuString = TEXT("");
|
||||
if (j < 9) { //first 9 have accelerator (0 unused)
|
||||
menuString += TEXT("&");
|
||||
}
|
||||
wsprintf(indexBuffer, TEXT("%d"), j+1);//one based numbering
|
||||
menuString += indexBuffer;
|
||||
menuString += TEXT(" ");
|
||||
menuString += _lrfl.at(j)._name;
|
||||
::InsertMenu(_hMenu, _posBase + j, MF_BYPOSITION, _lrfl.at(j)._id, menuString.c_str());
|
||||
BuildMenuFileName(buffer, 100, j, _lrfl.at(j)._name.c_str());
|
||||
::InsertMenu(_hMenu, _posBase + j, MF_BYPOSITION, _lrfl.at(j)._id, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user