diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index 9579fc5e4..307de1f13 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -451,7 +451,7 @@ BEGIN MENUITEM "Document Map", IDM_VIEW_DOC_MAP - //MENUITEM "Function List", IDM_VIEW_FUNC_LIST + MENUITEM "Function List", IDM_VIEW_FUNC_LIST MENUITEM SEPARATOR MENUITEM "Synchronize Vertical Scrolling", IDM_VIEW_SYNSCROLLV MENUITEM "Synchronize Horizontal Scrolling", IDM_VIEW_SYNSCROLLH diff --git a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp index 1fdf4f6ce..d7d1ffe15 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp +++ b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp @@ -253,7 +253,7 @@ void FunctionListPanel::reload() // clean up removeAllEntries(); - generic_string funcBegin = TEXT("^[\\s]*"); + generic_string funcBegin = TEXT("^[\\t ]*"); generic_string qualifier_maybe = TEXT("((static|const)[\\s]+)?"); generic_string returnType = TEXT("[\\w]+"); generic_string space_starMaybe = TEXT("([\\s]+|\\*[\\s]+|[\\s]+\\*|[\\s]+\\*[\\s]+)"); @@ -271,7 +271,7 @@ void FunctionListPanel::reload() secondSearch += TEXT("\\("); - int docLen = (*_ppEditView)->getCurrentDocLen(); + //int docLen = (*_ppEditView)->getCurrentDocLen(); vector fi; vector regExpr1; vector regExpr2; @@ -289,11 +289,18 @@ void FunctionListPanel::reload() generic_string str3 = TEXT("[\\w]+"); classRegExprArray.push_back(str1.c_str()); classRegExprArray.push_back(str2.c_str()); - classRegExprArray.push_back(str3.c_str()); + + //classRegExprArray.push_back(str3.c_str()); //parse(fi, 0, docLen, function.c_str(), regExpr1, regExpr2); + + /* const TCHAR bodyOpenSymbol[] = TEXT("\\{"); const TCHAR bodyCloseSymbol[] = TEXT("\\}"); parse2(fi, 0, docLen, classRegExpr.c_str(), classRegExprArray, bodyOpenSymbol, bodyCloseSymbol, function.c_str(), regExpr1); + */ + generic_string fn = ((*_ppEditView)->getCurrentBuffer())->getFileName(); + TCHAR *ext = ::PathFindExtension(fn.c_str()); + _funcParserMgr.parse(fi, ext); for (size_t i = 0; i < fi.size(); i++) { diff --git a/PowerEditor/src/WinControls/FunctionList/functionListPanel.h b/PowerEditor/src/WinControls/FunctionList/functionListPanel.h index 809cc96fa..c96b3ace2 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionListPanel.h +++ b/PowerEditor/src/WinControls/FunctionList/functionListPanel.h @@ -35,6 +35,7 @@ #endif //DOCKINGDLGINTERFACE_H #include "functionListPanel_rc.h" +#include "functionParser.h" class ScintillaEditView; @@ -64,13 +65,6 @@ root */ -struct foundInfo { - generic_string _data; - generic_string _data2; - int _pos; - int _pos2; - //foundInfo(): /*_data(TEXT("")), _data2(TEXT("")), _pos(-1) _pos2(-1) */{}; -}; class FunctionListPanel : public DockingDlgInterface { public: @@ -79,6 +73,7 @@ public: void init(HINSTANCE hInst, HWND hPere, ScintillaEditView **ppEditView) { DockingDlgInterface::init(hInst, hPere); _ppEditView = ppEditView; + /*_isValidated = */_funcParserMgr.init(TEXT("funcList.xml"), ppEditView); }; virtual void display(bool toShow = true) const { @@ -109,6 +104,7 @@ protected: private: ScintillaEditView **_ppEditView; + FunctionParsersManager _funcParserMgr; std::vector _funcInfos; std::vector< std::pair > _skipZones; generic_string parseSubLevel(size_t begin, size_t end, std::vector< generic_string > dataToSearch, int & foundPos); diff --git a/PowerEditor/src/WinControls/FunctionList/functionParser.cpp b/PowerEditor/src/WinControls/FunctionList/functionParser.cpp new file mode 100644 index 000000000..78980e2d2 --- /dev/null +++ b/PowerEditor/src/WinControls/FunctionList/functionParser.cpp @@ -0,0 +1,171 @@ +// This file is part of Notepad++ project +// Copyright (C)2012 Don HO +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// Note that the GPL places important restrictions on "derived works", yet +// it does not provide a detailed definition of that term. To avoid +// misunderstandings, we consider an application to constitute a +// "derivative work" for the purpose of this license if it does any of the +// following: +// 1. Integrates source code from Notepad++. +// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable +// installer, such as those produced by InstallShield. +// 3. Links to a library or executes a program that does any of the above. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "precompiledHeaders.h" +#include "ScintillaEditView.h" +#include "functionParser.h" + +bool FunctionParsersManager::init(generic_string xmlPath, ScintillaEditView ** ppEditView) +{ + _ppEditView = ppEditView; + bool loadOkay = false; + + if (PathFileExists(xmlPath.c_str())) + { + _pXmlFuncListDoc = new TiXmlDocument(xmlPath); + loadOkay = _pXmlFuncListDoc->LoadFile(); + if (loadOkay) + { + loadOkay = getFuncListFromXmlTree(); + } + } + + return loadOkay; +} + +bool FunctionParsersManager::getFuncListFromXmlTree() +{ + if (!_pXmlFuncListDoc) + return false; + + TiXmlNode *root = _pXmlFuncListDoc->FirstChild(TEXT("NotepadPlus")); + if (!root) + return false; + + root = root->FirstChild(TEXT("functionList")); + if (!root) + return false; + + TiXmlNode *parserRoot = root->FirstChild(TEXT("parsers")); + if (!root) + return false; + + + for (TiXmlNode *childNode = parserRoot->FirstChildElement(TEXT("parser")); + childNode; + childNode = childNode->NextSibling(TEXT("parser")) ) + { + const TCHAR *id = (childNode->ToElement())->Attribute(TEXT("id")); + if (!id || !id[0]) + continue; + + const TCHAR *displayName = (childNode->ToElement())->Attribute(TEXT("displayName")); + if (!displayName || !displayName[0]) + displayName = id; + + TiXmlNode *classRangeParser = childNode->FirstChild(TEXT("classRange")); + if (classRangeParser) + { + const TCHAR *mainExpr = NULL; + const TCHAR *openSymbole = NULL; + const TCHAR *closeSymbole = NULL; + std::vector classNameExprArray; + const TCHAR *functionExpr = NULL; + std::vector functionNameExprArray; + + mainExpr = (classRangeParser->ToElement())->Attribute(TEXT("mainExpr")); + if (!mainExpr) + continue; + + openSymbole = (classRangeParser->ToElement())->Attribute(TEXT("openSymbole")); + closeSymbole = (classRangeParser->ToElement())->Attribute(TEXT("closeSymbole")); + TiXmlNode *classNameParser = childNode->FirstChild(TEXT("className")); + if (classNameParser) + { + for (TiXmlNode *childNode2 = classNameParser->FirstChildElement(TEXT("nameExpr")); + childNode2; + childNode2 = childNode2->NextSibling(TEXT("nameExpr")) ) + { + const TCHAR *expr = (childNode2->ToElement())->Attribute(TEXT("expr")); + if (expr && expr[0]) + classNameExprArray.push_back(expr); + } + } + + TiXmlNode *functionParser = childNode->FirstChild(TEXT("function")); + if (functionParser) + { + functionExpr = (classRangeParser->ToElement())->Attribute(TEXT("mainExpr")); + if (!functionExpr) + continue; + TiXmlNode *functionNameParser = childNode->FirstChild(TEXT("functionName")); + if (functionNameParser) + { + for (TiXmlNode *childNode3 = functionNameParser->FirstChildElement(TEXT("funcNameExpr")); + childNode3; + childNode3 = childNode3->NextSibling(TEXT("funcNameExpr")) ) + { + const TCHAR *expr = (childNode3->ToElement())->Attribute(TEXT("expr")); + if (expr && expr[0]) + functionNameExprArray.push_back(expr); + } + + } + } + + _parsers.push_back(new FunctionZoneParser(id, displayName, mainExpr, openSymbole, closeSymbole, classNameExprArray, functionExpr, functionNameExprArray)); + } + else + { + TiXmlNode *functionParser = childNode->FirstChild(TEXT("fuction")); + if (!functionParser) + { + continue; + } + } + + //_parsers.push_back(); + } + + return (_parsers.size() != 0); +} + +FunctionParser * FunctionParsersManager::getParser(generic_string ext) +{ + return NULL; +} + +void FunctionZoneParser::parse(std::vector & /*foundInfos*/) +{ + +} + +bool FunctionParsersManager::parse(std::vector & foundInfos, generic_string ext) +{ + if (!_pXmlFuncListDoc) + return false; + + // Serch the right parser from the given ext in the map + FunctionParser *fp = getParser(ext); + if (!fp) + return false; + + // parse + fp->parse(foundInfos); + + return true; +} \ No newline at end of file diff --git a/PowerEditor/src/WinControls/FunctionList/functionParser.h b/PowerEditor/src/WinControls/FunctionList/functionParser.h new file mode 100644 index 000000000..550415653 --- /dev/null +++ b/PowerEditor/src/WinControls/FunctionList/functionParser.h @@ -0,0 +1,100 @@ +// This file is part of Notepad++ project +// Copyright (C)2003 Don HO +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// Note that the GPL places important restrictions on "derived works", yet +// it does not provide a detailed definition of that term. To avoid +// misunderstandings, we consider an application to constitute a +// "derivative work" for the purpose of this license if it does any of the +// following: +// 1. Integrates source code from Notepad++. +// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable +// installer, such as those produced by InstallShield. +// 3. Links to a library or executes a program that does any of the above. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef FUNCTIONPARSER_H +#define FUNCTIONPARSER_H + +class ScintillaEditView; +class TiXmlDocument; + +struct foundInfo { + generic_string _data; + generic_string _data2; + int _pos; + int _pos2; + //foundInfo(): /*_data(TEXT("")), _data2(TEXT("")), _pos(-1) _pos2(-1) */{}; +}; + +class FunctionParser { +public: + FunctionParser(const TCHAR *id, const TCHAR *displayName): _id(id), _displayName(displayName){}; + virtual void parse(std::vector & foundInfos) = 0; +protected: + generic_string _id; + generic_string _displayName; +}; + + +class FunctionZoneParser : public FunctionParser { +public: + FunctionZoneParser(const TCHAR *id, const TCHAR *displayName, generic_string rangeExpr, generic_string openSymbole, generic_string closeSymbole, + std::vector classNameExprArray, generic_string functionExpr, std::vector functionNameExprArray): + FunctionParser(id, displayName), _rangeExpr(rangeExpr), _openSymbole(openSymbole), _closeSymbole(closeSymbole), + _classNameExprArray(classNameExprArray), _functionExpr(functionExpr), _functionNameExprArray(functionNameExprArray) {}; + + void parse(std::vector & foundInfos); + +private: + generic_string _rangeExpr; + generic_string _openSymbole; + generic_string _closeSymbole; + std::vector _classNameExprArray; + generic_string _functionExpr; + std::vector _functionNameExprArray; +}; + +class FunctionUnitParser : public FunctionParser { +public: + FunctionUnitParser(TCHAR *id, TCHAR *displayName, + generic_string mainExpr, std::vector functionNameExprArray, + std::vector classNameExprArray): FunctionParser(id, displayName), _functionExpr(mainExpr), + _functionNameExprArray(functionNameExprArray), _classNameExprArray(classNameExprArray){}; + + void parse(std::vector & foundInfos); +private: + generic_string _functionExpr; + std::vector _functionNameExprArray; + std::vector _classNameExprArray; +}; + +class FunctionParsersManager { +public: + FunctionParsersManager() : _ppEditView(NULL), _pXmlFuncListDoc(NULL){}; + bool init(generic_string xmlPath, ScintillaEditView ** ppEditView); + bool parse(std::vector & foundInfos, generic_string ext); + +private: + ScintillaEditView **_ppEditView; + std::vector _parsers; + TiXmlDocument *_pXmlFuncListDoc; + + bool getFuncListFromXmlTree(); + FunctionParser * getParser(generic_string ext); +}; + +#endif //FUNCTIONPARSER_H + diff --git a/PowerEditor/src/functionList.xml b/PowerEditor/src/functionList.xml new file mode 100644 index 000000000..b716a5230 --- /dev/null +++ b/PowerEditor/src/functionList.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PowerEditor/src/winmain.cpp b/PowerEditor/src/winmain.cpp index dcb27bc32..1f780bb0b 100644 --- a/PowerEditor/src/winmain.cpp +++ b/PowerEditor/src/winmain.cpp @@ -180,11 +180,11 @@ const TCHAR FLAG_ALWAYS_ON_TOP[] = TEXT("-alwaysOnTop"); const TCHAR COMMAND_ARG_HELP[] = TEXT("Usage :\r\ \r\ -notepad++ [--help] [-multiInst] [-noPlugins] [-lLanguage] [-nLineNumber] [-cColumnNumber] [-xPos] [-yPos] [-nosession] [-notabbar] [-ro] [-systemtray] [-loadingTime] [fullFilePathName]\r\ +notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-nLineNumber] [-cColumnNumber] [-xPos] [-yPos] [-nosession] [-notabbar] [-ro] [-systemtray] [-loadingTime] [fullFilePathName]\r\ \r\ --help : This help message\r\ -multiInst : Launch another Notepad++ instance\r\ - -noPlugins : Launch Notepad++ without loading any plugin\r\ + -noPlugin : Launch Notepad++ without loading any plugin\r\ -l : Launch Notepad++ by applying indicated language to the file to open\r\ -n : Launch Notepad++ by scrolling indicated line on the file to open\r\ -c : Launch Notepad++ on scrolling indicated column on the file to open\r\ diff --git a/PowerEditor/visual.net/notepadPlus.vcproj b/PowerEditor/visual.net/notepadPlus.vcproj index bf34a02c8..fbd8cbc5a 100644 --- a/PowerEditor/visual.net/notepadPlus.vcproj +++ b/PowerEditor/visual.net/notepadPlus.vcproj @@ -307,6 +307,10 @@ RelativePath="..\src\WinControls\FunctionList\functionListPanel.cpp" > + + @@ -1258,6 +1262,10 @@ RelativePath="..\src\WinControls\FunctionList\functionListPanel_rc.h" > + +