Scrolling Document List automatically to make the selected tab item visible
Scrolling "Document List" to make the selected item visible after: - selecting - opening a file or files - the program startup - adding/removing columns This commit doesn't cover the case of the selected item becoming invisible after resizing of the window. Fix #11204, close #11471
This commit is contained in:
parent
b4a58429c3
commit
7fa6fb083b
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Buffer *>(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<LPARAM>(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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -70,6 +70,9 @@ public:
|
|||
|
||||
std::vector<SwitcherFileInfo> 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);
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue