From a724cc49a663f336b0a124c2a5969c489b70da62 Mon Sep 17 00:00:00 2001 From: GaryBloom Date: Mon, 22 Jan 2018 14:01:52 -0500 Subject: [PATCH] Function List enhancement: Highlight the current function based on cursor position Closes #715, close #4113 --- PowerEditor/src/NppNotification.cpp | 3 + .../FunctionList/functionListPanel.cpp | 65 +++++++++++++++++++ .../FunctionList/functionListPanel.h | 6 ++ 3 files changed, 74 insertions(+) diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index 632db905..4ee7ac81 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -28,6 +28,7 @@ #include "Notepad_plus_Window.h" +#include "functionListPanel.h" #include "xmlMatchedTagsHighlighter.h" #include "VerticalFileSwitcher.h" #include "ProjectPanel.h" @@ -847,6 +848,8 @@ BOOL Notepad_plus::notify(SCNotification *notification) } updateStatusBar(); + if (_pFuncList && (!_pFuncList->isClosed()) && _pFuncList->isVisible()) + _pFuncList->markEntry(); AutoCompletion * autoC = isFromPrimary?&_autoCompleteMain:&_autoCompleteSub; autoC->update(0); diff --git a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp index ca6a8f53..81bd47fb 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp +++ b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp @@ -304,6 +304,8 @@ bool FunctionListPanel::serialize(const generic_string & outputFilename) void FunctionListPanel::reload() { // clean up + _findLine = -1; + _findEndLine = -1; TreeStateNode currentTree; bool isOK = _treeView.retrieveFoldingStateTo(currentTree, _treeView.getRoot()); if (isOK) @@ -393,6 +395,68 @@ void FunctionListPanel::reload() ::InvalidateRect(_hSearchEdit, NULL, TRUE); } +void FunctionListPanel::markEntry() +{ + LONG lineNr = static_cast((*_ppEditView)->getCurrentLineNumber()); + HTREEITEM root = _treeView.getRoot(); + if (_findLine != -1 && _findEndLine != -1 && lineNr >= _findLine && lineNr < _findEndLine) + return; + _findLine = -1; + _findEndLine = -1; + findMarkEntry(root, lineNr); + if (_findLine != -1) + { + _treeView.selectItem(_findItem); + } + else + { + _treeView.selectItem(root); + } + +} + +void FunctionListPanel::findMarkEntry(HTREEITEM htItem, LONG line) +{ + HTREEITEM cItem; + TVITEM tvItem; + for (; htItem != NULL; htItem = _treeView.getNextSibling(htItem)) + { + cItem = _treeView.getChildFrom(htItem); + if (cItem != NULL) + { + findMarkEntry(cItem, line); + } + else + { + tvItem.hItem = htItem; + tvItem.mask = TVIF_IMAGE | TVIF_PARAM; + ::SendMessage(_treeViewSearchResult.getHSelf(), TVM_GETITEM, 0, reinterpret_cast(&tvItem)); + + generic_string *posStr = reinterpret_cast(tvItem.lParam); + if (posStr) + { + int pos = generic_atoi(posStr->c_str()); + if (pos != -1) + { + LONG sci_line = static_cast((*_ppEditView)->execute(SCI_LINEFROMPOSITION, pos)); + if (line >= sci_line) + { + if (sci_line > _findLine || _findLine == -1) + { + _findLine = sci_line; + _findItem = htItem; + } + } + else + { + if (sci_line < _findEndLine) + _findEndLine = sci_line; + } + } + } + } + } +} void FunctionListPanel::init(HINSTANCE hInst, HWND hPere, ScintillaEditView **ppEditView) { @@ -710,6 +774,7 @@ INT_PTR CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LPA _treeViewSearchResult.init(_hInst, _hSelf, IDC_LIST_FUNCLIST_AUX); _treeView.init(_hInst, _hSelf, IDC_LIST_FUNCLIST); + _treeView.makeLabelEditable(false); setTreeViewImageList(IDI_FUNCLIST_ROOT, IDI_FUNCLIST_NODE, IDI_FUNCLIST_LEAF); _treeView.display(); diff --git a/PowerEditor/src/WinControls/FunctionList/functionListPanel.h b/PowerEditor/src/WinControls/FunctionList/functionListPanel.h index e0ed8c34..e5d852a2 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionListPanel.h +++ b/PowerEditor/src/WinControls/FunctionList/functionListPanel.h @@ -108,6 +108,7 @@ public: // functionalities void sortOrUnsort(); void reload(); + void markEntry(); bool serialize(const generic_string & outputFilename = TEXT("")); void addEntry(const TCHAR *node, const TCHAR *displayText, size_t pos); void removeAllEntries(); @@ -124,6 +125,10 @@ private: TreeView _treeView; TreeView _treeViewSearchResult; + long _findLine = -1; + long _findEndLine = -1; + HTREEITEM _findItem; + generic_string _sortTipStr; generic_string _reloadTipStr; @@ -143,5 +148,6 @@ private: bool openSelection(const TreeView &treeView); bool shouldSort(); void setSort(bool isEnabled); + void findMarkEntry(HTREEITEM htItem, LONG line); };