mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +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,
|
VDirectory::VDirectory(VNotebook *p_notebook,
|
||||||
const QString &p_name, QObject *p_parent)
|
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;
|
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 retrivePath() const;
|
||||||
inline QString retriveRelativePath() const;
|
inline QString retriveRelativePath() const;
|
||||||
inline QString getNotebook() const;
|
inline QString getNotebook() const;
|
||||||
|
inline bool isExpanded() const;
|
||||||
|
void setExpanded(bool p_expanded);
|
||||||
|
|
||||||
static QJsonObject createDirectoryJson();
|
static QJsonObject createDirectoryJson();
|
||||||
|
|
||||||
@ -73,6 +75,8 @@ private:
|
|||||||
// Owner of the files
|
// Owner of the files
|
||||||
QVector<VFile *> m_files;
|
QVector<VFile *> m_files;
|
||||||
bool m_opened;
|
bool m_opened;
|
||||||
|
// Whether expanded in the directory tree.
|
||||||
|
bool m_expanded;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const QVector<VDirectory *> &VDirectory::getSubDirs() const
|
inline const QVector<VDirectory *> &VDirectory::getSubDirs() const
|
||||||
@ -125,4 +129,9 @@ inline QString VDirectory::retriveRelativePath() const
|
|||||||
return retriveRelativePath(this);
|
return retriveRelativePath(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool VDirectory::isExpanded() const
|
||||||
|
{
|
||||||
|
return m_expanded;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // VDIRECTORY_H
|
#endif // VDIRECTORY_H
|
||||||
|
@ -17,7 +17,9 @@ VDirectoryTree::VDirectoryTree(VNote *vnote, QWidget *parent)
|
|||||||
initActions();
|
initActions();
|
||||||
|
|
||||||
connect(this, SIGNAL(itemExpanded(QTreeWidgetItem*)),
|
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)),
|
connect(this, SIGNAL(customContextMenuRequested(QPoint)),
|
||||||
this, SLOT(contextMenuRequested(QPoint)));
|
this, SLOT(contextMenuRequested(QPoint)));
|
||||||
connect(this, &VDirectoryTree::currentItemChanged,
|
connect(this, &VDirectoryTree::currentItemChanged,
|
||||||
@ -145,6 +147,22 @@ void VDirectoryTree::updateDirectoryTreeOne(QTreeWidgetItem *p_parent, int depth
|
|||||||
|
|
||||||
updateDirectoryTreeOne(item, depth - 1);
|
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
|
// Update @p_item's children items
|
||||||
|
@ -30,7 +30,8 @@ public slots:
|
|||||||
void updateDirectoryTree();
|
void updateDirectoryTree();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateChildren(QTreeWidgetItem *p_item);
|
void handleItemExpanded(QTreeWidgetItem *p_item);
|
||||||
|
void handleItemCollapsed(QTreeWidgetItem *p_item);
|
||||||
void contextMenuRequested(QPoint pos);
|
void contextMenuRequested(QPoint pos);
|
||||||
void newSubDirectory();
|
void newSubDirectory();
|
||||||
void currentDirectoryItemChanged(QTreeWidgetItem *currentItem);
|
void currentDirectoryItemChanged(QTreeWidgetItem *currentItem);
|
||||||
@ -57,6 +58,7 @@ private:
|
|||||||
void pasteDirectories(VDirectory *p_destDir);
|
void pasteDirectories(VDirectory *p_destDir);
|
||||||
bool copyDirectory(VDirectory *p_destDir, const QString &p_destName,
|
bool copyDirectory(VDirectory *p_destDir, const QString &p_destName,
|
||||||
VDirectory *p_srcDir, bool p_cut);
|
VDirectory *p_srcDir, bool p_cut);
|
||||||
|
void updateChildren(QTreeWidgetItem *p_item);
|
||||||
|
|
||||||
VNote *vnote;
|
VNote *vnote;
|
||||||
QPointer<VNotebook> m_notebook;
|
QPointer<VNotebook> m_notebook;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user