Skip to content

Commit

Permalink
[NEW_FEATURE] Make Recent File List totally customizable (in progress).
Browse files Browse the repository at this point in the history
- Notepad-plus svn trunk @ 781
  • Loading branch information
donho committed Jun 27, 2011
1 parent 680ceec commit 4a4f14a
Show file tree
Hide file tree
Showing 15 changed files with 275 additions and 240 deletions.
29 changes: 17 additions & 12 deletions PowerEditor/src/MISC/Common/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,13 @@ static TCHAR* convertFileName(TCHAR *buffer, const TCHAR *filename)
return buffer;
}

// Build Recent File menu entries from given
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;
TCHAR *end = buffer + MAX_PATH - 1;
if (pos < 9)
{
*itr++ = '&';
Expand All @@ -423,10 +421,23 @@ TCHAR *BuildMenuFileName(TCHAR *buffer, int len, int pos, const TCHAR *filename)
}
*itr++ = ':';
*itr++ = ' ';
if (0 == generic_strnicmp(filename, cwd, lstrlen(cwd)))

if (len > 0)
{
TCHAR cnvName[MAX_PATH*2];
convertFileName(cnvName, filename);
::PathCompactPathEx(itr, filename, len - (itr-buffer), 0);
}
else
{
TCHAR cnvName[MAX_PATH];
const TCHAR *s1 = PathFindFileName(filename);
const TCHAR *s1;

if (len == 0)
s1 = PathFindFileName(filename);
else // (len < 0)
s1 = filename;

int len = lstrlen(s1);
if (len < (end-itr))
{
Expand All @@ -441,12 +452,6 @@ TCHAR *BuildMenuFileName(TCHAR *buffer, int len, int pos, const TCHAR *filename)
}
convertFileName(itr, cnvName);
}
else
{
TCHAR cnvName[MAX_PATH*2];
convertFileName(cnvName, filename);
PathCompactPathEx(itr, filename, len - (itr-buffer), 0);
}
return buffer;
}

Expand Down
25 changes: 2 additions & 23 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, true);
_lastRecentFileList.initMenu(hFileMenu, IDM_FILEMENU_LASTONE + 1, pos, pNppParam->putRecentFileInSubMenu());
_lastRecentFileList.setLangEncoding(_nativeLangSpeaker.getLangEncoding());
for (int i = 0 ; i < nbLRFile ; i++)
{
Expand Down Expand Up @@ -1992,6 +1992,7 @@ void Notepad_plus::MaintainIndentation(TCHAR ch)
}
}
}

void Notepad_plus::specialCmd(int id)
{
NppParameters *pNppParam = NppParameters::getInstance();
Expand Down Expand Up @@ -2070,28 +2071,6 @@ void Notepad_plus::specialCmd(int id)
break;
}

case IDM_SETTING_EDGE_SIZE :
{
ValueDlg nbColumnEdgeDlg;

ScintillaViewParams & svp = (ScintillaViewParams &)pNppParam->getSVP();
nbColumnEdgeDlg.init(_pPublicInterface->getHinst(), _preference.getHSelf(), svp._edgeNbColumn, TEXT("Nb of column:"));
nbColumnEdgeDlg.setNBNumber(3);

POINT p;
::GetCursorPos(&p);
::ScreenToClient(_pPublicInterface->getHParent(), &p);
int size = nbColumnEdgeDlg.doDialog(p, _nativeLangSpeaker.isRTL());

if (size != -1)
{
svp._edgeNbColumn = size;
_mainEditView.execute(SCI_SETEDGECOLUMN, size);
_subEditView.execute(SCI_SETEDGECOLUMN, size);
}
break;
}

case IDM_VIEW_LWDEF:
case IDM_VIEW_LWALIGN:
case IDM_VIEW_LWINDENT:
Expand Down
38 changes: 38 additions & 0 deletions PowerEditor/src/NppBigSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,44 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
return langDesc.length();
}

//
// These are sent by Preferences Dialog
//
case NPPM_INTERNAL_SETTING_HISTORY_SIZE:
{
NppParameters *pNppParam = NppParameters::getInstance();
_lastRecentFileList.setUserMaxNbLRF(pNppParam->getNbMaxRecentFile());
break;
}

case NPPM_INTERNAL_SETTING_EDGE_SIZE :
{
ScintillaViewParams & svp = (ScintillaViewParams &)(NppParameters::getInstance())->getSVP();
_mainEditView.execute(SCI_SETEDGECOLUMN, svp._edgeNbColumn);
_subEditView.execute(SCI_SETEDGECOLUMN, svp._edgeNbColumn);
break;
}

case NPPM_INTERNAL_SETTING_TAB_REPLCESPACE:
case NPPM_INTERNAL_SETTING_TAB_SIZE:
{
_pEditView->setTabSettings(_pEditView->getCurrentBuffer()->getCurrentLang());
break;
}

case NPPM_INTERNAL_RECENTFILELIST_UPDATE:
{
_lastRecentFileList.updateMenu();
break;
}

case NPPM_INTERNAL_RECENTFILELIST_SWITCH:
{
_lastRecentFileList.switchMode();
_lastRecentFileList.updateMenu();
break;
}

case WM_INITMENUPOPUP:
{
_windowsMenu.initPopupMenu((HMENU)wParam, _pDocTab);
Expand Down
51 changes: 0 additions & 51 deletions PowerEditor/src/NppCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1758,57 +1758,6 @@ void Notepad_plus::command(int id)
break;
}
*/
case IDM_SETTING_TAB_REPLCESPACE:
case IDM_SETTING_TAB_SIZE:
{
_pEditView->setTabSettings(_pEditView->getCurrentBuffer()->getCurrentLang());
break;
}

case IDM_SETTING_AUTOCNBCHAR:
{
const int NB_MIN_CHAR = 1;
const int NB_MAX_CHAR = 9;

ValueDlg valDlg;
NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI());
valDlg.init(_pPublicInterface->getHinst(), _preference.getHSelf(), nppGUI._autocFromLen, TEXT("Nb char : "));
POINT p;
::GetCursorPos(&p);
::ScreenToClient(_pPublicInterface->getHParent(), &p);
int size = valDlg.doDialog(p, _nativeLangSpeaker.isRTL());

if (size != -1)
{
if (size > NB_MAX_CHAR)
size = NB_MAX_CHAR;
else if (size < NB_MIN_CHAR)
size = NB_MIN_CHAR;

nppGUI._autocFromLen = size;
}
break;
}

case IDM_SETTING_HISTORY_SIZE :
{
ValueDlg nbHistoryDlg;
NppParameters *pNppParam = NppParameters::getInstance();
nbHistoryDlg.init(_pPublicInterface->getHinst(), _preference.getHSelf(), pNppParam->getNbMaxRecentFile(), TEXT("Max File : "));
POINT p;
::GetCursorPos(&p);
::ScreenToClient(_pPublicInterface->getHParent(), &p);
int size = nbHistoryDlg.doDialog(p, _nativeLangSpeaker.isRTL());

if (size != -1)
{
if (size > NB_MAX_LRF_FILE)
size = NB_MAX_LRF_FILE;
pNppParam->setNbMaxRecentFile(size);
_lastRecentFileList.setUserMaxNbLRF(size);
}
break;
}

case IDM_SETTING_IMPORTPLUGIN :
{
Expand Down
34 changes: 29 additions & 5 deletions PowerEditor/src/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1696,14 +1696,22 @@ void NppParameters::feedFileListParameters(TiXmlNode *node)
TiXmlNode *historyRoot = node->FirstChildElement(TEXT("History"));
if (!historyRoot) return;

// nbMaxFile value
int nbMaxFile;
const TCHAR *nbMaxFileStr = (historyRoot->ToElement())->Attribute(TEXT("nbMaxFile"), &nbMaxFile);
const TCHAR *strVal = (historyRoot->ToElement())->Attribute(TEXT("nbMaxFile"), &nbMaxFile);
if (strVal && (nbMaxFile > 0) && (nbMaxFile <= 50))
_nbMaxRecentFile = nbMaxFile;

if ((nbMaxFile < 0) || (nbMaxFile > 50))
return;
// customLen value
int customLen;
strVal = (historyRoot->ToElement())->Attribute(TEXT("customLength"), &customLen);
if (strVal)
_recentFileCustomLength = customLen;

if (nbMaxFileStr)
_nbMaxRecentFile = nbMaxFile;
// inSubMenu value
strVal = (historyRoot->ToElement())->Attribute(TEXT("inSubMenu"));
if (lstrcmp(strVal, TEXT("yes")) == 0)
_putRecentFileInSubMenu = true;

for (TiXmlNode *childNode = historyRoot->FirstChildElement(TEXT("File"));
childNode && (_nbRecentFile < NB_MAX_LRF_FILE);
Expand Down Expand Up @@ -2717,6 +2725,22 @@ void StyleArray::addStyler(int styleID, TiXmlNode *styleNode)
_nbStyler++;
}

bool NppParameters::writeRecentFileHistorySettings(int nbMaxFile) const
{
if (!_pXmlUserDoc) return false;

TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild(TEXT("NotepadPlus"));
if (!nppRoot) return false;

TiXmlNode *historyNode = nppRoot->FirstChildElement(TEXT("History"));
if (!historyNode) return false;

(historyNode->ToElement())->SetAttribute(TEXT("nbMaxFile"), nbMaxFile!=-1?nbMaxFile:_nbMaxRecentFile);
(historyNode->ToElement())->SetAttribute(TEXT("inSubMenu"), _putRecentFileInSubMenu?TEXT("yes"):TEXT("no"));
(historyNode->ToElement())->SetAttribute(TEXT("customLength"), _recentFileCustomLength);
return true;
}

bool NppParameters::writeHistory(const TCHAR *fullpath)
{
TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild(TEXT("NotepadPlus"));
Expand Down
18 changes: 2 additions & 16 deletions PowerEditor/src/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ class NppParameters
_putRecentFileInSubMenu = doSubmenu;
};

int putRecentFileInSubMenu() const {return _putRecentFileInSubMenu;};
bool putRecentFileInSubMenu() const {return _putRecentFileInSubMenu;};

void setRecentFileCustomLength(int len) {
_recentFileCustomLength = len;
Expand All @@ -1181,19 +1181,7 @@ class NppParameters
return _svp;
};

bool writeNbHistoryFile(int nb) {
if (!_pXmlUserDoc) return false;

TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild(TEXT("NotepadPlus"));
if (!nppRoot) return false;

TiXmlNode *historyNode = nppRoot->FirstChildElement(TEXT("History"));
if (!historyNode) return false;

(historyNode->ToElement())->SetAttribute(TEXT("nbMaxFile"), nb);
return true;
};

bool writeRecentFileHistorySettings(int nbMaxFile = -1) const;
bool writeHistory(const TCHAR *fullpath);

TiXmlNode * getChildElementByAttribut(TiXmlNode *pere, const TCHAR *childName,\
Expand Down Expand Up @@ -1304,8 +1292,6 @@ class NppParameters

int addExternalLangToEnd(ExternalLangContainer * externalLang);

//TiXmlDocument * getNativeLang() const {return _pXmlNativeLangDoc;};

TiXmlDocumentA * getNativeLangA() const {return _pXmlNativeLangDocA;};

TiXmlDocument * getToolIcons() const {return _pXmlToolIconsDoc;};
Expand Down
2 changes: 0 additions & 2 deletions PowerEditor/src/ScitillaComponent/Printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,6 @@ size_t Printer::doPrint(bool justDoIt)
break;
}

//TCHAR toto[10];
//::MessageBox(NULL, itoa(pageNum, toto, 10), TEXT("page total"), MB_OK);
if (!nppGUI._printSettings._printLineNumber)
_pSEView->showMargin(ScintillaEditView::_SC_MARGE_LINENUMBER, isShown);

Expand Down

0 comments on commit 4a4f14a

Please sign in to comment.