diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 637bfb76c..d27965882 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -5171,11 +5171,8 @@ void Notepad_plus::launchFunctionList() ::SendMessage(_pPublicInterface->getHSelf(), NPPM_DMMREGASDCKDLG, 0, (LPARAM)&data); } - - //_pDocMap->initWrapMap(); - //_pDocMap->wrapMap(); _pFuncList->display(); - + _pFuncList->reload(); _pEditView->getFocus(); } diff --git a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp index 08cded4b9..835fdf63e 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp +++ b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp @@ -194,10 +194,12 @@ void FunctionListPanel::reload() vector fi; const TCHAR *fn = ((*_ppEditView)->getCurrentBuffer())->getFileName(); - + LangType langID = ((*_ppEditView)->getCurrentBuffer())->getLangType(); TCHAR *ext = ::PathFindExtension(fn); - if (_funcParserMgr.parse(fi, ext)) + if (_funcParserMgr.parse(fi, langID) || _funcParserMgr.parse(fi, ext)) + { _treeView.addItem(fn, NULL, INDEX_ROOT, TEXT("-1")); + } for (size_t i = 0; i < fi.size(); i++) { @@ -244,6 +246,33 @@ void FunctionListPanel::init(HINSTANCE hInst, HWND hPere, ScintillaEditView **pp _funcParserMgr.init(funcListXmlPath, ppEditView); } +bool FunctionListPanel::openSelection() +{ + TVITEM tvItem; + tvItem.mask = TVIF_IMAGE | TVIF_PARAM; + tvItem.hItem = _treeView.getSelection(); + ::SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem); + + if (tvItem.iImage == INDEX_ROOT || tvItem.iImage == INDEX_NODE) + { + return false; + } + + generic_string *posStr = (generic_string *)tvItem.lParam; + if (!posStr) + return false; + + int pos = generic_atoi(posStr->c_str()); + if (pos == -1) + return false; + + int sci_line = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, pos); + (*_ppEditView)->execute(SCI_ENSUREVISIBLE, sci_line); + (*_ppEditView)->execute(SCI_GOTOPOS, pos); + + return true; +} + void FunctionListPanel::notified(LPNMHDR notification) { if((notification->hwndFrom == _treeView.getHSelf())) @@ -252,25 +281,27 @@ void FunctionListPanel::notified(LPNMHDR notification) { case NM_DBLCLK: { - TVITEM tvItem; - tvItem.mask = TVIF_PARAM; - tvItem.hItem = _treeView.getSelection(); - ::SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem); - - //NodeType nType = getNodeType(tvItem.hItem); - generic_string *posStr = (generic_string *)tvItem.lParam; - if (posStr) + openSelection(); + } + break; + + case TVN_KEYDOWN: + { + //tvItem.hItem = _treeView.getSelection(); + //::SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem); + LPNMTVKEYDOWN ptvkd = (LPNMTVKEYDOWN)notification; + + if (ptvkd->wVKey == VK_RETURN) { - int pos = generic_atoi(posStr->c_str()); - if (pos != -1) + if (!openSelection()) { - int sci_line = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, pos); - (*_ppEditView)->execute(SCI_ENSUREVISIBLE, sci_line); - (*_ppEditView)->execute(SCI_GOTOPOS, pos); + HTREEITEM hItem = _treeView.getSelection(); + _treeView.toggleExpandCollapse(hItem); } } } break; + } } diff --git a/PowerEditor/src/WinControls/FunctionList/functionListPanel.h b/PowerEditor/src/WinControls/FunctionList/functionListPanel.h index ec80e509e..0092d4ab0 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionListPanel.h +++ b/PowerEditor/src/WinControls/FunctionList/functionListPanel.h @@ -109,5 +109,6 @@ private: void addInTreeStateArray(TreeStateNode tree2Update); TreeStateNode* getFromTreeStateArray(generic_string fullFilePath); BOOL setImageList(int root_id, int node_id, int leaf_id); + bool openSelection(); }; #endif // FUNCLISTPANEL_H diff --git a/PowerEditor/src/WinControls/FunctionList/functionParser.cpp b/PowerEditor/src/WinControls/FunctionList/functionParser.cpp index 202d533a0..5aad3d047 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionParser.cpp +++ b/PowerEditor/src/WinControls/FunctionList/functionParser.cpp @@ -195,15 +195,17 @@ bool FunctionParsersManager::getFuncListFromXmlTree() childNode; childNode = childNode->NextSibling(TEXT("association")) ) { - const TCHAR *ext = (childNode->ToElement())->Attribute(TEXT("ext")); + int langID; + const TCHAR *langIDStr = (childNode->ToElement())->Attribute(TEXT("langID"), &langID); + const TCHAR *exts = (childNode->ToElement())->Attribute(TEXT("ext")); const TCHAR *id = (childNode->ToElement())->Attribute(TEXT("id")); - if (ext && ext[0] && id && id[0]) + if ((langIDStr || (exts && exts[0])) && (id && id[0])) { for (size_t i = 0; i < _parsers.size(); i++) { if (_parsers[i]->_id == id) { - _associationMap.push_back(std::pair(ext, i)); + _associationMap.push_back(AssociationInfo(i, langID, exts?exts:TEXT(""))); break; } } @@ -214,12 +216,22 @@ bool FunctionParsersManager::getFuncListFromXmlTree() return (_parsers.size() != 0); } +FunctionParser * FunctionParsersManager::getParser(int langID) +{ + for (size_t i = 0; i < _associationMap.size(); i++) + { + if (langID == _associationMap[i]._langID) + return _parsers[_associationMap[i]._id]; + } + return NULL; +} + FunctionParser * FunctionParsersManager::getParser(generic_string ext) { for (size_t i = 0; i < _associationMap.size(); i++) { - if (ext == _associationMap[i].first) - return _parsers[_associationMap[i].second]; + if (ext == _associationMap[i]._ext) + return _parsers[_associationMap[i]._id]; } return NULL; } @@ -331,6 +343,23 @@ generic_string FunctionParser::parseSubLevel(size_t begin, size_t end, std::vect } } +bool FunctionParsersManager::parse(std::vector & foundInfos, int langID) +{ + if (!_pXmlFuncListDoc) + return false; + + // Serch the right parser from the given ext in the map + FunctionParser *fp = getParser(langID); + if (!fp) + return false; + + // parse + int docLen = (*_ppEditView)->getCurrentDocLen(); + fp->parse(foundInfos, 0, docLen, _ppEditView); + + return true; +} + bool FunctionParsersManager::parse(std::vector & foundInfos, generic_string ext) { if (!_pXmlFuncListDoc) diff --git a/PowerEditor/src/WinControls/FunctionList/functionParser.h b/PowerEditor/src/WinControls/FunctionList/functionParser.h index d36b6f674..9afb24213 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionParser.h +++ b/PowerEditor/src/WinControls/FunctionList/functionParser.h @@ -91,20 +91,30 @@ public: }; +struct AssociationInfo { + int _id; + int _langID; + generic_string _ext; + + AssociationInfo(int id, int langID, const TCHAR *ext): _id(id), _langID(langID), _ext(ext){}; +}; + class FunctionParsersManager { public: FunctionParsersManager() : _ppEditView(NULL), _pXmlFuncListDoc(NULL){}; bool init(generic_string xmlPath, ScintillaEditView ** ppEditView); + bool parse(std::vector & foundInfos, int langID); bool parse(std::vector & foundInfos, generic_string ext); private: ScintillaEditView **_ppEditView; std::vector _parsers; - std::vector> _associationMap; + std::vector _associationMap; TiXmlDocument *_pXmlFuncListDoc; bool getFuncListFromXmlTree(); FunctionParser * getParser(generic_string ext); + FunctionParser * getParser(int langID); }; #endif //FUNCTIONPARSER_H