mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00
preserve the expand/collapse state while switching notebook
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
52af2ef9e9
commit
d4fe99b8bb
@ -9,7 +9,8 @@
|
||||
|
||||
VDirectory::VDirectory(VNotebook *p_notebook,
|
||||
const QString &p_name, QObject *p_parent)
|
||||
: QObject(p_parent), m_notebook(p_notebook), m_name(p_name), m_opened(false)
|
||||
: QObject(p_parent), m_notebook(p_notebook), m_name(p_name), m_opened(false),
|
||||
m_expanded(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -572,3 +573,12 @@ VDirectory *VDirectory::copyDirectory(VDirectory *p_destDir, const QString &p_de
|
||||
}
|
||||
return destDir;
|
||||
}
|
||||
|
||||
void VDirectory::setExpanded(bool p_expanded)
|
||||
{
|
||||
if (p_expanded) {
|
||||
Q_ASSERT(m_opened);
|
||||
}
|
||||
m_expanded = p_expanded;
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,8 @@ public:
|
||||
inline QString retrivePath() const;
|
||||
inline QString retriveRelativePath() const;
|
||||
inline QString getNotebook() const;
|
||||
inline bool isExpanded() const;
|
||||
void setExpanded(bool p_expanded);
|
||||
|
||||
static QJsonObject createDirectoryJson();
|
||||
|
||||
@ -73,6 +75,8 @@ private:
|
||||
// Owner of the files
|
||||
QVector<VFile *> m_files;
|
||||
bool m_opened;
|
||||
// Whether expanded in the directory tree.
|
||||
bool m_expanded;
|
||||
};
|
||||
|
||||
inline const QVector<VDirectory *> &VDirectory::getSubDirs() const
|
||||
@ -125,4 +129,9 @@ inline QString VDirectory::retriveRelativePath() const
|
||||
return retriveRelativePath(this);
|
||||
}
|
||||
|
||||
inline bool VDirectory::isExpanded() const
|
||||
{
|
||||
return m_expanded;
|
||||
}
|
||||
|
||||
#endif // VDIRECTORY_H
|
||||
|
@ -17,7 +17,9 @@ VDirectoryTree::VDirectoryTree(VNote *vnote, QWidget *parent)
|
||||
initActions();
|
||||
|
||||
connect(this, SIGNAL(itemExpanded(QTreeWidgetItem*)),
|
||||
this, SLOT(updateChildren(QTreeWidgetItem*)));
|
||||
this, SLOT(handleItemExpanded(QTreeWidgetItem*)));
|
||||
connect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)),
|
||||
this, SLOT(handleItemCollapsed(QTreeWidgetItem*)));
|
||||
connect(this, SIGNAL(customContextMenuRequested(QPoint)),
|
||||
this, SLOT(contextMenuRequested(QPoint)));
|
||||
connect(this, &VDirectoryTree::currentItemChanged,
|
||||
@ -145,6 +147,22 @@ void VDirectoryTree::updateDirectoryTreeOne(QTreeWidgetItem *p_parent, int depth
|
||||
|
||||
updateDirectoryTreeOne(item, depth - 1);
|
||||
}
|
||||
if (dir->isExpanded()) {
|
||||
expandItem(p_parent);
|
||||
}
|
||||
}
|
||||
|
||||
void VDirectoryTree::handleItemCollapsed(QTreeWidgetItem *p_item)
|
||||
{
|
||||
VDirectory *dir = getVDirectory(p_item);
|
||||
dir->setExpanded(false);
|
||||
}
|
||||
|
||||
void VDirectoryTree::handleItemExpanded(QTreeWidgetItem *p_item)
|
||||
{
|
||||
updateChildren(p_item);
|
||||
VDirectory *dir = getVDirectory(p_item);
|
||||
dir->setExpanded(true);
|
||||
}
|
||||
|
||||
// Update @p_item's children items
|
||||
|
@ -30,7 +30,8 @@ public slots:
|
||||
void updateDirectoryTree();
|
||||
|
||||
private slots:
|
||||
void updateChildren(QTreeWidgetItem *p_item);
|
||||
void handleItemExpanded(QTreeWidgetItem *p_item);
|
||||
void handleItemCollapsed(QTreeWidgetItem *p_item);
|
||||
void contextMenuRequested(QPoint pos);
|
||||
void newSubDirectory();
|
||||
void currentDirectoryItemChanged(QTreeWidgetItem *currentItem);
|
||||
@ -57,6 +58,7 @@ private:
|
||||
void pasteDirectories(VDirectory *p_destDir);
|
||||
bool copyDirectory(VDirectory *p_destDir, const QString &p_destName,
|
||||
VDirectory *p_srcDir, bool p_cut);
|
||||
void updateChildren(QTreeWidgetItem *p_item);
|
||||
|
||||
VNote *vnote;
|
||||
QPointer<VNotebook> m_notebook;
|
||||
|
Loading…
x
Reference in New Issue
Block a user