Commit 75c79f6c authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle

When a clip is dropped in bin, focus on it.

Related to #287
parent 6b603b81
Pipeline #12553 passed with stage
in 13 minutes and 56 seconds
......@@ -2787,7 +2787,14 @@ void Bin::slotItemDropped(const QList<QUrl> &urls, const QModelIndex &parent)
}
parentFolder = parentItem->clipId();
}
ClipCreator::createClipsFromList(urls, true, parentFolder, m_itemModel);
const QString id = ClipCreator::createClipsFromList(urls, true, parentFolder, m_itemModel);
if (!id.isEmpty()) {
std::shared_ptr<AbstractProjectItem> item = m_itemModel->getItemByBinId(id);
if (item) {
QModelIndex ix = m_itemModel->getIndexFromItem(item);
m_itemView->scrollTo(m_proxyModel->mapFromSource(ix), QAbstractItemView::PositionAtCenter);
}
}
}
void Bin::slotExpandUrl(const ItemInfo &info, const QString &url, QUndoCommand *command)
......
......@@ -206,9 +206,10 @@ QString ClipCreator::createTitleTemplate(const QString &path, const QString &tex
return res ? id : QStringLiteral("-1");
}
bool ClipCreator::createClipsFromList(const QList<QUrl> &list, bool checkRemovable, const QString &parentFolder, const std::shared_ptr<ProjectItemModel> &model,
const QString ClipCreator::createClipsFromList(const QList<QUrl> &list, bool checkRemovable, const QString &parentFolder, const std::shared_ptr<ProjectItemModel> &model,
Fun &undo, Fun &redo, bool topLevel)
{
QString createdItem;
QScopedPointer<QProgressDialog> progressDialog;
if (topLevel) {
progressDialog.reset(new QProgressDialog(pCore->window()));
......@@ -238,6 +239,7 @@ bool ClipCreator::createClipsFromList(const QList<QUrl> &list, bool checkRemovab
if (!folderCreated) {
continue;
}
createdItem = folderId;
QStringList result = dir.entryList(QDir::Files);
QStringList subfolders = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
QList<QUrl> folderFiles;
......@@ -270,14 +272,19 @@ bool ClipCreator::createClipsFromList(const QList<QUrl> &list, bool checkRemovab
}
if (!sublist.isEmpty()) {
// load subfolders
created = created || createClipsFromList(sublist, checkRemovable, folderId, model, undo, redo, false);
const QString clipId = createClipsFromList(sublist, checkRemovable, folderId, model, undo, redo, false);
if (createdItem.isEmpty() && clipId != QLatin1String("-1")) {
createdItem = clipId;
}
}
} else {
bool clipsCreated = createClipsFromList(folderFiles, checkRemovable, folderId, model, local_undo, local_redo, false);
created = true;
if (!clipsCreated) {
const QString clipId = createClipsFromList(folderFiles, checkRemovable, folderId, model, local_undo, local_redo, false);
if (clipId.isEmpty() || clipId == QLatin1String("-1")) {
local_undo();
} else {
if (createdItem.isEmpty()) {
createdItem = clipId;
}
UPDATE_UNDO_REDO_NOLOCK(local_redo, local_undo, undo, redo)
}
// Check subfolders
......@@ -305,21 +312,23 @@ bool ClipCreator::createClipsFromList(const QList<QUrl> &list, bool checkRemovab
if (answer == KMessageBox::Cancel) continue;
}
QString id = ClipCreator::createClipFromFile(file.toLocalFile(), parentFolder, model, undo, redo);
created = created || (id != QStringLiteral("-1"));
const QString clipId = ClipCreator::createClipFromFile(file.toLocalFile(), parentFolder, model, undo, redo);
if (createdItem.isEmpty() && clipId != QLatin1String("-1")) {
createdItem = clipId;
}
}
}
qDebug() << "/////////// creatclipsfromlist return" << created;
return created;
return createdItem == QLatin1String("-1") ? QString() : createdItem;
}
bool ClipCreator::createClipsFromList(const QList<QUrl> &list, bool checkRemovable, const QString &parentFolder, std::shared_ptr<ProjectItemModel> model)
const QString ClipCreator::createClipsFromList(const QList<QUrl> &list, bool checkRemovable, const QString &parentFolder, std::shared_ptr<ProjectItemModel> model)
{
Fun undo = []() { return true; };
Fun redo = []() { return true; };
bool ok = ClipCreator::createClipsFromList(list, checkRemovable, parentFolder, std::move(model), undo, redo);
if (ok) {
const QString id = ClipCreator::createClipsFromList(list, checkRemovable, parentFolder, std::move(model), undo, redo);
if (!id.isEmpty()) {
pCore->pushUndo(undo, redo, i18np("Add clip", "Add clips", list.size()));
}
return ok;
return id;
}
......@@ -92,9 +92,9 @@ bool createClipFromFile(const QString &path, const QString &parentFolder, std::s
@param parentFolder: the binId of the containing folder
@param model: a shared pointer to the bin item model
*/
bool createClipsFromList(const QList<QUrl> &list, bool checkRemovable, const QString &parentFolder, const std::shared_ptr<ProjectItemModel> &model, Fun &undo,
const QString createClipsFromList(const QList<QUrl> &list, bool checkRemovable, const QString &parentFolder, const std::shared_ptr<ProjectItemModel> &model, Fun &undo,
Fun &redo, bool topLevel = true);
bool createClipsFromList(const QList<QUrl> &list, bool checkRemovable, const QString &parentFolder, std::shared_ptr<ProjectItemModel> model);
const QString createClipsFromList(const QList<QUrl> &list, bool checkRemovable, const QString &parentFolder, std::shared_ptr<ProjectItemModel> model);
/* @brief Create minimal xml description from an url
*/
......
......@@ -357,6 +357,7 @@ void ProjectItemModel::onItemUpdated(const QString &binId, int role)
onItemUpdated(item, role);
}
}
std::shared_ptr<ProjectClip> ProjectItemModel::getClipByBinID(const QString &binId)
{
READ_LOCK();
......
......@@ -425,11 +425,11 @@ void ClipCreationDialog::createClipsCommand(KdenliveDoc *doc, const QString &par
}
Fun undo = []() { return true; };
Fun redo = []() { return true; };
bool created = ClipCreator::createClipsFromList(list, true, parentFolder, model, undo, redo);
const QString id = ClipCreator::createClipsFromList(list, true, parentFolder, model, undo, redo);
// We reset the state of the "don't ask again" for the question about removable devices
KMessageBox::enableMessage(QStringLiteral("removable"));
if (created) {
if (!id.isEmpty()) {
pCore->pushUndo(undo, redo, i18np("Add clip", "Add clips", list.size()));
}
}
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