mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-06 06:19:52 +08:00
restore last active item in directory tree after switching notebook
This commit is contained in:
parent
de4e5fef8e
commit
c2c70368da
@ -129,8 +129,27 @@ void VDirectoryTree::updateDirectoryTree()
|
||||
|
||||
updateDirectoryTreeOne(item, 1);
|
||||
}
|
||||
|
||||
if (!restoreCurrentItem()) {
|
||||
setCurrentItem(topLevelItem(0));
|
||||
}
|
||||
}
|
||||
|
||||
bool VDirectoryTree::restoreCurrentItem()
|
||||
{
|
||||
qDebug() << m_notebook << m_notebookCurrentDirMap;
|
||||
auto it = m_notebookCurrentDirMap.find(m_notebook);
|
||||
if (it != m_notebookCurrentDirMap.end()) {
|
||||
bool rootDirectory;
|
||||
QTreeWidgetItem *item = findVDirectory(it.value(), rootDirectory);
|
||||
if (item) {
|
||||
setCurrentItem(item);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void VDirectoryTree::updateDirectoryTreeOne(QTreeWidgetItem *p_parent, int depth)
|
||||
{
|
||||
@ -401,7 +420,10 @@ void VDirectoryTree::currentDirectoryItemChanged(QTreeWidgetItem *currentItem)
|
||||
emit currentDirectoryChanged(NULL);
|
||||
return;
|
||||
}
|
||||
emit currentDirectoryChanged(getVDirectory(currentItem));
|
||||
|
||||
QPointer<VDirectory> dir = getVDirectory(currentItem);
|
||||
m_notebookCurrentDirMap[m_notebook] = dir;
|
||||
emit currentDirectoryChanged(dir);
|
||||
}
|
||||
|
||||
void VDirectoryTree::editDirectoryInfo()
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <QVector>
|
||||
#include <QMap>
|
||||
#include <QList>
|
||||
#include <QHash>
|
||||
#include "vdirectory.h"
|
||||
#include "vnotebook.h"
|
||||
#include "vnavigationmode.h"
|
||||
@ -77,12 +78,15 @@ private:
|
||||
void expandItemTree(QTreeWidgetItem *p_item);
|
||||
QList<QTreeWidgetItem *> getVisibleItems() const;
|
||||
QList<QTreeWidgetItem *> getVisibleChildItems(const QTreeWidgetItem *p_item) const;
|
||||
bool restoreCurrentItem();
|
||||
|
||||
VNote *vnote;
|
||||
QPointer<VNotebook> m_notebook;
|
||||
QVector<QPointer<VDirectory> > m_copiedDirs;
|
||||
VEditArea *m_editArea;
|
||||
|
||||
QHash<VNotebook *, VDirectory *> m_notebookCurrentDirMap;
|
||||
|
||||
// Actions
|
||||
QAction *newRootDirAct;
|
||||
QAction *newSiblingDirAct;
|
||||
|
Loading…
x
Reference in New Issue
Block a user