Save folder status (expanded or not).

Related to #287
parent 94010686
......@@ -4233,3 +4233,40 @@ void Bin::checkMissingProxies()
pCore->currentDoc()->slotProxyCurrentItem(true, toProxy);
}
}
void Bin::saveFolderState()
{
// Check folder state (expanded or not)
if (m_itemView == nullptr || m_listType != BinTreeView) {
// Folder state is only valid in tree view mode
return;
}
auto *view = static_cast<QTreeView *>(m_itemView);
QList <std::shared_ptr<ProjectFolder> > folders = m_itemModel->getFolders();
QStringList expandedFolders;
for (const auto &folder : folders) {
QModelIndex ix = m_itemModel->getIndexFromItem(folder);
if (view->isExpanded(m_proxyModel->mapFromSource(ix))) {
// Save expanded state
expandedFolders << folder->clipId();
}
}
m_itemModel->saveProperty(QStringLiteral("kdenlive:expandedFolders"), expandedFolders.join(QLatin1Char(';')));
}
void Bin::loadFolderState(QStringList foldersToExpand)
{
// Check folder state (expanded or not)
if (m_itemView == nullptr || m_listType != BinTreeView) {
// Folder state is only valid in tree view mode
return;
}
auto *view = static_cast<QTreeView *>(m_itemView);
for (const QString &id : foldersToExpand) {
std::shared_ptr<ProjectFolder> folder = m_itemModel->getFolderByBinId(id);
if (folder) {
QModelIndex ix = m_itemModel->getIndexFromItem(folder);
view->setExpanded(m_proxyModel->mapFromSource(ix), true);
}
}
}
......@@ -285,6 +285,10 @@ public:
void invalidateClip(const QString &binId);
/** @brief Recreate missing proxies on document opening */
void checkMissingProxies();
/** @brief Save folder state (expanded or not) */
void saveFolderState();
/** @brief Load folder state (expanded or not) */
void loadFolderState(QStringList foldersToExpand);
// TODO refac: remove this and call directly the function in ProjectItemModel
void cleanup();
......
......@@ -423,6 +423,19 @@ std::shared_ptr<ProjectFolder> ProjectItemModel::getFolderByBinId(const QString
return nullptr;
}
QList <std::shared_ptr<ProjectFolder> > ProjectItemModel::getFolders()
{
READ_LOCK();
QList <std::shared_ptr<ProjectFolder> > folders;
for (const auto &clip : m_allItems) {
auto c = std::static_pointer_cast<AbstractProjectItem>(clip.second.lock());
if (c->itemType() == AbstractProjectItem::FolderItem) {
folders << std::static_pointer_cast<ProjectFolder>(c);
}
}
return folders;
}
const QString ProjectItemModel::getFolderIdByName(const QString &folderName)
{
READ_LOCK();
......@@ -881,7 +894,7 @@ QStringList ProjectItemModel::getClipByUrl(const QFileInfo &url) const
return result;
}
bool ProjectItemModel::loadFolders(Mlt::Properties &folders)
bool ProjectItemModel::loadFolders(Mlt::Properties &folders, std::unordered_map<QString, QString> &binIdCorresp)
{
QWriteLocker locker(&m_lock);
// At this point, we expect the folders properties to have a name of the form "x.y" where x is the id of the parent folder and y the id of the child.
......@@ -938,6 +951,7 @@ bool ProjectItemModel::loadFolders(Mlt::Properties &folders)
Q_ASSERT(undone);
return false;
}
binIdCorresp[QString::number(current)] = id;
newIds[current] = id;
}
for (int c : downLinks[current]) {
......@@ -962,7 +976,7 @@ bool ProjectItemModel::isIdFree(const QString &id) const
return true;
}
void ProjectItemModel::loadBinPlaylist(Mlt::Tractor *documentTractor, Mlt::Tractor *modelTractor, std::unordered_map<QString, QString> &binIdCorresp, QProgressDialog *progressDialog)
void ProjectItemModel::loadBinPlaylist(Mlt::Tractor *documentTractor, Mlt::Tractor *modelTractor, std::unordered_map<QString, QString> &binIdCorresp, QStringList &expandedFolders, QProgressDialog *progressDialog)
{
QWriteLocker locker(&m_lock);
clean();
......@@ -983,8 +997,9 @@ void ProjectItemModel::loadBinPlaylist(Mlt::Tractor *documentTractor, Mlt::Tract
// Load folders
Mlt::Properties folderProperties;
Mlt::Properties playlistProps(playlist.get_properties());
expandedFolders = QString(playlistProps.get("kdenlive:expandedFolders")).split(QLatin1Char(';'));
folderProperties.pass_values(playlistProps, "kdenlive:folder.");
loadFolders(folderProperties);
loadFolders(folderProperties, binIdCorresp);
// Read notes
QString notes = playlistProps.get("kdenlive:documentnotes");
......
......@@ -78,6 +78,8 @@ public:
/** @brief Gets a folder by its id. If none is found, nullptr is returned */
std::shared_ptr<ProjectFolder> getFolderByBinId(const QString &binId);
/** @brief Gets a list of all folders in this project */
QList <std::shared_ptr<ProjectFolder> > getFolders();
/** @brief Gets a id folder by its name. If none is found, empty string returned */
const QString getFolderIdByName(const QString &folderName);
......@@ -105,10 +107,10 @@ public:
std::shared_ptr<AbstractProjectItem> getBinItemByIndex(const QModelIndex &index) const;
/* @brief Load the folders given the property containing them */
bool loadFolders(Mlt::Properties &folders);
bool loadFolders(Mlt::Properties &folders, std::unordered_map<QString, QString> &binIdCorresp);
/* @brief Parse a bin playlist from the document tractor and reconstruct the tree */
void loadBinPlaylist(Mlt::Tractor *documentTractor, Mlt::Tractor *modelTractor, std::unordered_map<QString, QString> &binIdCorresp, QProgressDialog *progressDialog = nullptr);
void loadBinPlaylist(Mlt::Tractor *documentTractor, Mlt::Tractor *modelTractor, std::unordered_map<QString, QString> &binIdCorresp, QStringList &expandedFolders, QProgressDialog *progressDialog = nullptr);
/** @brief Save document properties in MLT's bin playlist */
void saveDocumentProperties(const QMap<QString, QString> &props, const QMap<QString, QString> &metadata, std::shared_ptr<MarkerListModel> guideModel);
......
......@@ -724,6 +724,7 @@ void ProjectManager::prepareSave()
{
pCore->projectItemModel()->saveDocumentProperties(pCore->window()->getMainTimeline()->controller()->documentProperties(), m_project->metadata(),
m_project->getGuideModel());
pCore->bin()->saveFolderState();
pCore->projectItemModel()->saveProperty(QStringLiteral("kdenlive:documentnotes"), documentNotes());
pCore->projectItemModel()->saveProperty(QStringLiteral("kdenlive:docproperties.groups"), m_mainTimelineModel->groupsData());
}
......
......@@ -57,8 +57,17 @@ bool constructTimelineFromMelt(const std::shared_ptr<TimelineItemModel> &timelin
timeline->requestReset(undo, redo);
m_errorMessage.clear();
std::unordered_map<QString, QString> binIdCorresp;
pCore->projectItemModel()->loadBinPlaylist(&tractor, timeline->tractor(), binIdCorresp, progressDialog);
QStringList expandedFolders;
pCore->projectItemModel()->loadBinPlaylist(&tractor, timeline->tractor(), binIdCorresp, expandedFolders, progressDialog);
pCore->bin()->checkMissingProxies();
QStringList foldersToExpand;
// Find updated ids for expanded folders
for (const QString &folderId : expandedFolders) {
if (binIdCorresp.count(folderId) > 0) {
foldersToExpand << binIdCorresp.at(folderId);
}
}
pCore->bin()->loadFolderState(foldersToExpand);
QSet<QString> reserved_names{QLatin1String("playlistmain"), QLatin1String("timeline_preview"), QLatin1String("timeline_overlay"),
QLatin1String("black_track")};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment