diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp index 644eb0a21..92cdf9112 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp @@ -330,6 +330,12 @@ void VerticalFileSwitcher::popupMenuCmd(int cmdID) } } +void VerticalFileSwitcher::display(bool toShow) const +{ + DockingDlgInterface::display(toShow); + _fileListView.ensureVisibleCurrentItem(); // without this call the current item may stay above visible area after the program startup +}; + void VerticalFileSwitcher::activateDoc(TaskLstFnStatus *tlfs) const { int view = tlfs->_iView; diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h index fb9f06f35..8f432795d 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h @@ -38,9 +38,7 @@ public: _hImaLst = hImaLst; }; - virtual void display(bool toShow = true) const { - DockingDlgInterface::display(toShow); - }; + virtual void display(bool toShow = true) const; void setParent(HWND parent2set){ _hParent = parent2set; diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp index 6e9ce4f2e..143e4bd60 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp @@ -183,7 +183,9 @@ void VerticalFileSwitcherListView::initList() ListView_SetItemText(_hSelf, i, ++colIndex, drive); } } - ListView_SetItemState(_hSelf, taskListInfo._currentIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); + _currentIndex = taskListInfo._currentIndex; + selectCurrentItem(); + ensureVisibleCurrentItem(); // without this call the current item may become invisible after adding/removing columns } void VerticalFileSwitcherListView::reload() @@ -298,13 +300,14 @@ void VerticalFileSwitcherListView::activateItem(BufferID bufferID, int iView) for (int i = 0; i < nbItem; ++i) ListView_SetItemState(_hSelf, i, 0, LVIS_FOCUSED|LVIS_SELECTED); - int i = newItem(bufferID, iView); - ListView_SetItemState(_hSelf, i, LVIS_FOCUSED|LVIS_SELECTED, LVIS_FOCUSED|LVIS_SELECTED); + _currentIndex = newItem(bufferID, iView); + selectCurrentItem(); + ensureVisibleCurrentItem(); } int VerticalFileSwitcherListView::add(BufferID bufferID, int iView) { - int index = ListView_GetItemCount(_hSelf); + _currentIndex = ListView_GetItemCount(_hSelf); Buffer *buf = static_cast(bufferID); const TCHAR *fileName = buf->getFileName(); NppGUI& nppGUI = NppParameters::getInstance().getNppGUI(); @@ -322,7 +325,7 @@ int VerticalFileSwitcherListView::add(BufferID bufferID, int iView) item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM; item.pszText = fn; - item.iItem = index; + item.iItem = _currentIndex; item.iSubItem = 0; item.iImage = buf->isMonitoringOn()?3:(buf->isReadOnly()?2:(buf->isDirty()?1:0)); item.lParam = reinterpret_cast(tl); @@ -330,18 +333,18 @@ int VerticalFileSwitcherListView::add(BufferID bufferID, int iView) int colIndex = 0; if (isExtColumn) { - ListView_SetItemText(_hSelf, index, ++colIndex, ::PathFindExtension(fileName)); + ListView_SetItemText(_hSelf, _currentIndex, ++colIndex, ::PathFindExtension(fileName)); } if (isPathColumn) { TCHAR dir[MAX_PATH], drive[MAX_PATH]; _wsplitpath_s(buf->getFullPathName(), drive, MAX_PATH, dir, MAX_PATH, NULL, 0, NULL, 0); wcscat_s(drive, dir); - ListView_SetItemText(_hSelf, index, ++colIndex, drive); + ListView_SetItemText(_hSelf, _currentIndex, ++colIndex, drive); } - ListView_SetItemState(_hSelf, index, LVIS_FOCUSED|LVIS_SELECTED, LVIS_FOCUSED|LVIS_SELECTED); + selectCurrentItem(); - return index; + return _currentIndex; } diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h index 87c569515..ffc1cc6e7 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h @@ -70,6 +70,9 @@ public: std::vector getSelectedFiles(bool reverse = false) const; void reload(); + void ensureVisibleCurrentItem() const { + ListView_EnsureVisible(_hSelf, _currentIndex, false); + }; void setBackgroundColor(COLORREF bgColour) { ListView_SetBkColor(_hSelf, bgColour); @@ -85,6 +88,9 @@ public: protected: HIMAGELIST _hImaLst = nullptr; WNDPROC _defaultProc = nullptr; + + int _currentIndex = 0; + LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { @@ -95,4 +101,7 @@ protected: int add(BufferID bufferID, int iView); void remove(int index); void removeAll(); + void selectCurrentItem() const { + ListView_SetItemState(_hSelf, _currentIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); + }; };