Commit a747bf59 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Correctly select a clip in clip monitor after it is added to project.

Fixes #1152
parent f6774b8e
......@@ -69,7 +69,10 @@ QString ClipCreator::createTitleClip(const std::unordered_map<QString, QString>
Xml::addXmlProperties(prod, properties);
QString id;
bool res = model->requestAddBinClip(id, xml.documentElement(), parentFolder, i18n("Create title clip"));
std::function<void(const QString &)> callBack = [](const QString &binId) {
pCore->bin()->selectClipById(binId);
};
bool res = model->requestAddBinClip(id, xml.documentElement(), parentFolder, i18n("Create title clip"), callBack);
return res ? id : QStringLiteral("-1");
}
......@@ -81,7 +84,10 @@ QString ClipCreator::createColorClip(const QString &color, int duration, const Q
auto prod = createProducer(xml, ClipType::Color, color, name, duration, QStringLiteral("color"));
QString id;
bool res = model->requestAddBinClip(id, xml.documentElement(), parentFolder, i18n("Create color clip"));
std::function<void(const QString &)> callBack = [](const QString &binId) {
pCore->bin()->selectClipById(binId);
};
bool res = model->requestAddBinClip(id, xml.documentElement(), parentFolder, i18n("Create color clip"), callBack);
return res ? id : QStringLiteral("-1");
}
......@@ -177,7 +183,10 @@ QString ClipCreator::createSlideshowClip(const QString &path, int duration, cons
Xml::addXmlProperties(prod, properties);
QString id;
bool res = model->requestAddBinClip(id, xml.documentElement(), parentFolder, i18n("Create slideshow clip"));
std::function<void(const QString &)> callBack = [](const QString &binId) {
pCore->bin()->selectClipById(binId);
};
bool res = model->requestAddBinClip(id, xml.documentElement(), parentFolder, i18n("Create slideshow clip"), callBack);
return res ? id : QStringLiteral("-1");
}
......@@ -210,7 +219,10 @@ QString ClipCreator::createTitleTemplate(const QString &path, const QString &tex
}
QString id;
bool res = model->requestAddBinClip(id, xml.documentElement(), parentFolder, i18n("Create title template"));
std::function<void(const QString &)> callBack = [](const QString &binId) {
pCore->bin()->selectClipById(binId);
};
bool res = model->requestAddBinClip(id, xml.documentElement(), parentFolder, i18n("Create title template"), callBack);
return res ? id : QStringLiteral("-1");
}
......@@ -232,6 +244,7 @@ const QString ClipCreator::createClipsFromList(const QList<QUrl> &list, bool che
// Check for duplicates
QList<QUrl> cleanList;
QStringList duplicates;
bool firstClip = topLevel;
for (const QUrl &url : list) {
if (!pCore->projectItemModel()->urlExists(url.toLocalFile())) {
cleanList << url;
......@@ -331,7 +344,14 @@ const QString ClipCreator::createClipsFromList(const QList<QUrl> &list, bool che
if (answer == KMessageBox::Cancel) continue;
}
const QString clipId = ClipCreator::createClipFromFile(file.toLocalFile(), parentFolder, model, undo, redo);
std::function<void(const QString &)> callBack = [](const QString &) {};
if (firstClip) {
callBack = [](const QString &binId) {
pCore->bin()->selectClipById(binId);
};
firstClip = false;
}
const QString clipId = ClipCreator::createClipFromFile(file.toLocalFile(), parentFolder, model, undo, redo, callBack);
if (createdItem.isEmpty() && clipId != QLatin1String("-1")) {
createdItem = clipId;
}
......
......@@ -731,12 +731,12 @@ bool ProjectItemModel::requestAddBinClip(QString &id, const QDomElement &descrip
return res;
}
bool ProjectItemModel::requestAddBinClip(QString &id, const QDomElement &description, const QString &parentId, const QString &undoText)
bool ProjectItemModel::requestAddBinClip(QString &id, const QDomElement &description, const QString &parentId, const QString &undoText, const std::function<void(const QString &)> &readyCallBack)
{
QWriteLocker locker(&m_lock);
Fun undo = []() { return true; };
Fun redo = []() { return true; };
bool res = requestAddBinClip(id, description, parentId, undo, redo);
bool res = requestAddBinClip(id, description, parentId, undo, redo, readyCallBack);
if (res) {
pCore->pushUndo(undo, redo, undoText.isEmpty() ? i18n("Add bin clip") : undoText);
}
......
......@@ -163,7 +163,7 @@ public:
*/
bool requestAddBinClip(QString &id, const QDomElement &description, const QString &parentId, Fun &undo, Fun &redo,
const std::function<void(const QString &)> &readyCallBack = [](const QString &) {});
bool requestAddBinClip(QString &id, const QDomElement &description, const QString &parentId, const QString &undoText = QString());
bool requestAddBinClip(QString &id, const QDomElement &description, const QString &parentId, const QString &undoText = QString(), const std::function<void(const QString &)> &readyCallBack = [](const QString &) {});
/** @brief This is the addition function when we already have a producer for the clip*/
bool requestAddBinClip(QString &id, const std::shared_ptr<Mlt::Producer> &producer, const QString &parentId, Fun &undo, Fun &redo);
......
......@@ -669,10 +669,6 @@ void ClipLoadTask::run()
}
generateThumbnail(binClip, producer);
emit taskDone();
if (pCore->projectItemModel()->clipsCount() == 1) {
// Always select first added clip
pCore->selectBinClip(QString::number(m_owner.second), false);
}
}
pCore->taskManager.taskDone(m_owner.second, this);
}
......
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