Add function list export feature

"notepad++.exe -export=functionList -lcpp c:\funcListTests\whatever.cpp"
will open whatever.cpp as cpp file, then parse this file to write the
funcLst result on disk, then exit Notepad++.
The result will write into c:\funcListTests\whatever.cpp.result.
pull/3279/merge
Don HO 2017-08-06 00:03:18 +02:00
parent 3fbd537371
commit 1d58c1d3d3
9 changed files with 114 additions and 34 deletions

View File

@ -297,6 +297,9 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
// Make this call later to take effect
::SendMessage(_hSelf, NPPM_INTERNAL_SETWORDCHARS, 0, 0);
if (pNppParams->doFunctionListExport())
::SendMessage(_hSelf, NPPM_INTERNAL_EXPORTFUNCLISTANDQUIT, 0, 0);
}

View File

@ -469,6 +469,18 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
return TRUE;
}
case NPPM_INTERNAL_EXPORTFUNCLISTANDQUIT:
{
checkMenuItem(IDM_VIEW_FUNC_LIST, true);
_toolBar.setCheck(IDM_VIEW_FUNC_LIST, true);
launchFunctionList();
_pFuncList->setClosed(false);
_pFuncList->serialize();
::PostMessage(_pPublicInterface->getHSelf(), WM_COMMAND, IDM_FILE_EXIT, 0);
}
break;
case NPPM_DISABLEAUTOUPDATE:
{
NppGUI & nppGUI = const_cast<NppGUI &>(pNppParam->getNppGUI());

View File

@ -247,7 +247,7 @@ BufferID Notepad_plus::doOpen(const generic_string& fileName, bool isRecursive,
else
{
wsprintf(str2display, TEXT("\"%s\" cannot be opened:\nFolder \"%s\" doesn't exist."), longFileName, longFileDir.c_str());
::MessageBox(_pPublicInterface->getHSelf(), str2display, TEXT("Cannot opened"), MB_OK);
::MessageBox(_pPublicInterface->getHSelf(), str2display, TEXT("Cannot open file"), MB_OK);
}
if (!isCreateFileSuccessful)

View File

@ -1470,10 +1470,16 @@ public:
void setWorkingDir(const TCHAR * newPath);
void setStartWithLocFileName(generic_string locPath)
{
void setStartWithLocFileName(generic_string locPath) {
_startWithLocFileName = locPath;
}
};
void setFunctionListExportBoolean(bool doIt) {
_doFunctionListExport = doIt;
};
bool doFunctionListExport() const {
return _doFunctionListExport;
};
bool loadSession(Session & session, const TCHAR *sessionFileName);
int langTypeToCommandID(LangType lt) const;
@ -1659,6 +1665,7 @@ private:
LocalizationSwitcher _localizationSwitcher;
generic_string _startWithLocFileName;
bool _doFunctionListExport = false;
ThemeSwitcher _themeSwitcher;
@ -1722,17 +1729,11 @@ private:
void feedFindHistoryParameters(TiXmlNode *node);
void feedProjectPanelsParameters(TiXmlNode *node);
void feedFileBrowserParameters(TiXmlNode *node);
bool feedStylerArray(TiXmlNode *node);
void getAllWordStyles(TCHAR *lexerName, TiXmlNode *lexerNode);
bool feedUserLang(TiXmlNode *node);
int getIndexFromKeywordListName(const TCHAR *name);
void feedUserStyles(TiXmlNode *node);
void feedUserKeywordList(TiXmlNode *node);
void feedUserSettings(TiXmlNode *node);
void feedShortcut(TiXmlNode *node);
void feedMacros(TiXmlNode *node);
void feedUserCmds(TiXmlNode *node);

View File

@ -224,6 +224,56 @@ void FunctionListPanel::sortOrUnsort()
}
}
bool FunctionListPanel::serialize(const generic_string & outputFilename)
{
generic_string fname;
if (outputFilename.empty()) // if outputFilename is not given, get the current file path by adding the file extension
{
Buffer* currentBuf = (*_ppEditView)->getCurrentBuffer();
const TCHAR *fullFilePath = currentBuf->getFullPathName();
// Export function list from an existing file
bool exportFuncntionList = (NppParameters::getInstance())->doFunctionListExport();
if (exportFuncntionList && ::PathFileExists(fullFilePath))
{
fname = fullFilePath;
fname += TEXT(".result");
}
else
return false;
}
else
{
fname = outputFilename;
}
FILE * f = generic_fopen(fname.c_str(), TEXT("w+"));
if (!f)
return false;
for (const auto & info : _funcinfos)
{
generic_string entryName;
if (info._pos2 != -1)
{
entryName = info._data2;
entryName += TEXT("=>");
}
entryName += info._data;
entryName += TEXT("\n");
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
UINT cp = static_cast<UINT>((*_ppEditView)->execute(SCI_GETCODEPAGE));
const char *textA = wmc->wchar2char(entryName.c_str(), cp);
string entryNameA = textA;
fwrite(entryNameA.c_str(), sizeof(entryNameA.c_str()[0]), entryNameA.length(), f);
}
fflush(f);
fclose(f);
return true;
}
void FunctionListPanel::reload()
{
// clean up
@ -240,50 +290,55 @@ void FunctionListPanel::reload()
::SendMessage(_hSearchEdit, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(TEXT("")));
setSort(false);
vector<foundInfo> fi;
_funcinfos.clear();
const TCHAR *fn = ((*_ppEditView)->getCurrentBuffer())->getFileName();
LangType langID = ((*_ppEditView)->getCurrentBuffer())->getLangType();
Buffer* currentBuf = (*_ppEditView)->getCurrentBuffer();
const TCHAR *fn = currentBuf->getFileName();
LangType langID = currentBuf->getLangType();
if (langID == L_JAVASCRIPT)
langID = L_JS;
const TCHAR *udln = NULL;
if (langID == L_USER)
{
udln = ((*_ppEditView)->getCurrentBuffer())->getUserDefineLangName();
udln = currentBuf->getUserDefineLangName();
}
TCHAR *ext = ::PathFindExtension(fn);
if (_funcParserMgr.parse(fi, AssociationInfo(-1, langID, ext, udln)))
bool parsedOK = _funcParserMgr.parse(_funcinfos, AssociationInfo(-1, langID, ext, udln));
if (parsedOK)
{
_treeView.addItem(fn, NULL, INDEX_ROOT, TEXT("-1"));
}
for (size_t i = 0, len = fi.size(); i < len; ++i)
for (size_t i = 0, len = _funcinfos.size(); i < len; ++i)
{
// no 2 level
bool b = false;
if (b)
{
generic_string entryName = TEXT("");
if (fi[i]._pos2 != -1)
if (_funcinfos[i]._pos2 != -1)
{
entryName = fi[i]._data2;
entryName = _funcinfos[i]._data2;
entryName += TEXT("=>");
}
entryName += fi[i]._data;
addEntry(NULL, entryName.c_str(), fi[i]._pos);
entryName += _funcinfos[i]._data;
addEntry(NULL, entryName.c_str(), _funcinfos[i]._pos);
}
else
{
addEntry(fi[i]._data2.c_str(), fi[i]._data.c_str(), fi[i]._pos);
addEntry(_funcinfos[i]._data2.c_str(), _funcinfos[i]._data.c_str(), _funcinfos[i]._pos);
}
}
HTREEITEM root = _treeView.getRoot();
const TCHAR *fullFilePath = ((*_ppEditView)->getCurrentBuffer())->getFullPathName();
if (root)
{
Buffer* currentBuf = (*_ppEditView)->getCurrentBuffer();
const TCHAR *fullFilePath = currentBuf->getFullPathName();
_treeView.setItemParam(root, fullFilePath);
TreeParams *previousParams = getFromStateArray(fullFilePath);
if (!previousParams)

View File

@ -25,15 +25,9 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#pragma once
#ifndef FUNCLISTPANEL_H
#define FUNCLISTPANEL_H
//#include <windows.h>
#ifndef DOCKINGDLGINTERFACE_H
#include "DockingDlgInterface.h"
#endif //DOCKINGDLGINTERFACE_H
#include "functionListPanel_rc.h"
#include "functionParser.h"
#include "TreeView.h"
@ -118,6 +112,7 @@ public:
// functionalities
void sortOrUnsort();
void reload();
bool serialize(const generic_string & outputFilename = TEXT(""));
void addEntry(const TCHAR *node, const TCHAR *displayText, size_t pos);
void removeAllEntries();
void removeEntry();
@ -138,6 +133,8 @@ private:
generic_string _sortTipStr;
generic_string _reloadTipStr;
std::vector<foundInfo> _funcinfos;
ScintillaEditView **_ppEditView;
FunctionParsersManager _funcParserMgr;
std::vector<FuncInfo> _funcInfos;
@ -154,4 +151,4 @@ private:
bool shouldSort();
void setSort(bool isEnabled);
};
#endif // FUNCLISTPANEL_H

View File

@ -323,6 +323,7 @@
#define IDM_VIEW_FILESWITCHER_PANEL (IDM_VIEW + 70)
#define IDM_VIEW_SWITCHTO_OTHER_VIEW (IDM_VIEW + 72)
#define IDM_EXPORT_FUNC_LIST_AND_QUIT (IDM_VIEW + 73)
#define IDM_VIEW_DOC_MAP (IDM_VIEW + 80)

View File

@ -417,6 +417,7 @@
#define NPPM_INTERNAL_FINDKEYCONFLICTS (NOTEPADPLUS_USER_INTERNAL + 43)
#define NPPM_INTERNAL_SCROLLBEYONDLASTLINE (NOTEPADPLUS_USER_INTERNAL + 44)
#define NPPM_INTERNAL_SETWORDCHARS (NOTEPADPLUS_USER_INTERNAL + 45)
#define NPPM_INTERNAL_EXPORTFUNCLISTANDQUIT (NOTEPADPLUS_USER_INTERNAL + 46)
//wParam: 0
//lParam: document new index

View File

@ -306,6 +306,8 @@ const TCHAR FLAG_HELP[] = TEXT("--help");
const TCHAR FLAG_ALWAYS_ON_TOP[] = TEXT("-alwaysOnTop");
const TCHAR FLAG_OPENSESSIONFILE[] = TEXT("-openSession");
const TCHAR FLAG_RECURSIVE[] = TEXT("-r");
const TCHAR FLAG_FUNCLSTEXPORT[] = TEXT("-export=functionList");
void doException(Notepad_plus_Window & notepad_plus_plus)
@ -352,6 +354,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
bool isParamePresent;
bool showHelp = isInList(FLAG_HELP, params);
bool isMultiInst = isInList(FLAG_MULTI_INSTANCE, params);
bool doFunctionListExport = isInList(FLAG_FUNCLSTEXPORT, params);
CmdLineParams cmdLineParams;
cmdLineParams._isNoTab = isInList(FLAG_NOTABBAR, params);
@ -377,6 +380,15 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
::MessageBox(NULL, COMMAND_ARG_HELP, TEXT("Notepad++ Command Argument Help"), MB_OK);
NppParameters *pNppParameters = NppParameters::getInstance();
NppGUI & nppGui = const_cast<NppGUI &>(pNppParameters->getNppGUI());
bool doUpdate = nppGui._autoUpdateOpt._doAutoUpdate;
if (doFunctionListExport) // export functionlist feature will serialize fuctionlist on the disk, then exit Notepad++. So it's important to not launch into existing instance, and keep it silent.
{
isMultiInst = true;
doUpdate = false;
cmdLineParams._isNoSession = true;
}
if (cmdLineParams._localizationPath != TEXT(""))
{
@ -384,6 +396,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
}
pNppParameters->load();
pNppParameters->setFunctionListExportBoolean(doFunctionListExport);
// override the settings if notepad style is present
if (pNppParameters->asNotepadStyle())
{
@ -470,8 +484,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
Notepad_plus_Window notepad_plus_plus;
NppGUI & nppGui = const_cast<NppGUI &>(pNppParameters->getNppGUI());
generic_string updaterDir = pNppParameters->getNppPath();
updaterDir += TEXT("\\updater\\");
@ -482,8 +494,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
bool isUpExist = nppGui._doesExistUpdater = (::PathFileExists(updaterFullPath.c_str()) == TRUE);
bool doUpdate = nppGui._autoUpdateOpt._doAutoUpdate;
if (doUpdate) // check more detail
{
Date today(0);