Ensure newly created folder is active so that added clips go in it.

parent 300b03ac
...@@ -613,6 +613,10 @@ bool MyTreeView::isEditing() const ...@@ -613,6 +613,10 @@ bool MyTreeView::isEditing() const
void MyTreeView::setEditing(bool edit) void MyTreeView::setEditing(bool edit)
{ {
setState(edit ? QAbstractItemView::EditingState : QAbstractItemView::NoState); setState(edit ? QAbstractItemView::EditingState : QAbstractItemView::NoState);
if (!edit) {
// Ensure edited item is selected
emit selectCurrent();
}
} }
bool MyTreeView::performDrag() bool MyTreeView::performDrag()
...@@ -1742,15 +1746,16 @@ void Bin::slotAddFolder() ...@@ -1742,15 +1746,16 @@ void Bin::slotAddFolder()
if (m_listType == BinTreeView) { if (m_listType == BinTreeView) {
// Make sure parent folder is expanded // Make sure parent folder is expanded
if (parentFolder->clipId().toInt() > -1) { if (parentFolder->clipId().toInt() > -1) {
auto ix = m_itemModel->getIndexFromItem(parentFolder); auto parentIx = m_itemModel->getIndexFromItem(parentFolder);
auto *view = static_cast<QTreeView *>(m_itemView); auto *view = static_cast<QTreeView *>(m_itemView);
view->expand(m_proxyModel->mapFromSource(ix)); view->expand(m_proxyModel->mapFromSource(parentIx));
} }
} }
// Edit folder name // Edit folder name
auto folder = m_itemModel->getFolderByBinId(newId); auto folder = m_itemModel->getFolderByBinId(newId);
auto ix = m_itemModel->getIndexFromItem(folder); auto ix = m_itemModel->getIndexFromItem(folder);
// Scroll to ensure folder is visible // Scroll to ensure folder is visible
m_itemView->scrollTo(m_proxyModel->mapFromSource(ix), QAbstractItemView::PositionAtCenter); m_itemView->scrollTo(m_proxyModel->mapFromSource(ix), QAbstractItemView::PositionAtCenter);
qDebug() << "selecting" << ix; qDebug() << "selecting" << ix;
...@@ -1768,6 +1773,17 @@ void Bin::slotAddFolder() ...@@ -1768,6 +1773,17 @@ void Bin::slotAddFolder()
} }
} }
void Bin::ensureCurrent()
{
const QModelIndexList indexes = m_proxyModel->selectionModel()->selectedRows(0);
for (const QModelIndex &ix : indexes) {
if (!ix.isValid()) {
continue;
}
m_itemView->setCurrentIndex(ix);
}
}
QModelIndex Bin::getIndexForId(const QString &id, bool folderWanted) const QModelIndex Bin::getIndexForId(const QString &id, bool folderWanted) const
{ {
QModelIndexList items = m_itemModel->match(m_itemModel->index(0, 0), AbstractProjectItem::DataId, QVariant::fromValue(id), 1, Qt::MatchRecursive); QModelIndexList items = m_itemModel->match(m_itemModel->index(0, 0), AbstractProjectItem::DataId, QVariant::fromValue(id), 1, Qt::MatchRecursive);
...@@ -2016,6 +2032,7 @@ void Bin::slotInitView(QAction *action) ...@@ -2016,6 +2032,7 @@ void Bin::slotInitView(QAction *action)
view->setWordWrap(true); view->setWordWrap(true);
connect(view, &MyTreeView::updateDragMode, m_itemModel.get(), &ProjectItemModel::setDragType, Qt::DirectConnection); connect(view, &MyTreeView::updateDragMode, m_itemModel.get(), &ProjectItemModel::setDragType, Qt::DirectConnection);
connect(view, &MyTreeView::processDragEnd, this, &Bin::processDragEnd); connect(view, &MyTreeView::processDragEnd, this, &Bin::processDragEnd);
connect(view, &MyTreeView::selectCurrent, this, &Bin::ensureCurrent);
connect(view, &MyTreeView::displayBinFrame, this, &Bin::showBinFrame); connect(view, &MyTreeView::displayBinFrame, this, &Bin::showBinFrame);
if (!m_headerInfo.isEmpty()) { if (!m_headerInfo.isEmpty()) {
view->header()->restoreState(m_headerInfo); view->header()->restoreState(m_headerInfo);
......
...@@ -117,6 +117,7 @@ signals: ...@@ -117,6 +117,7 @@ signals:
void updateDragMode(PlaylistState::ClipState type); void updateDragMode(PlaylistState::ClipState type);
void displayBinFrame(QModelIndex ix, int frame); void displayBinFrame(QModelIndex ix, int frame);
void processDragEnd(); void processDragEnd();
void selectCurrent();
}; };
class SmallJobLabel : public QPushButton class SmallJobLabel : public QPushButton
...@@ -288,6 +289,8 @@ private slots: ...@@ -288,6 +289,8 @@ private slots:
void slotSetSorting(); void slotSetSorting();
/** @brief Show/hide date column */ /** @brief Show/hide date column */
void slotShowColumn(bool show); void slotShowColumn(bool show);
/** @brief Ensure current item is selected */
void ensureCurrent();
/** @brief Go to parent folder */ /** @brief Go to parent folder */
void slotBack(); void slotBack();
/** @brief Setup the bin view type (icon view, tree view, ...). /** @brief Setup the bin view type (icon view, tree view, ...).
......
...@@ -138,7 +138,7 @@ QDomDocument ClipCreator::getXmlFromUrl(const QString &path) ...@@ -138,7 +138,7 @@ QDomDocument ClipCreator::getXmlFromUrl(const QString &path)
QString ClipCreator::createClipFromFile(const QString &path, const QString &parentFolder, const std::shared_ptr<ProjectItemModel> &model, Fun &undo, Fun &redo, QString ClipCreator::createClipFromFile(const QString &path, const QString &parentFolder, const std::shared_ptr<ProjectItemModel> &model, Fun &undo, Fun &redo,
const std::function<void(const QString &)> &readyCallBack) const std::function<void(const QString &)> &readyCallBack)
{ {
qDebug() << "/////////// createClipFromFile" << path << parentFolder << path; qDebug() << "/////////// createClipFromFile" << path << parentFolder;
QDomDocument xml = getXmlFromUrl(path); QDomDocument xml = getXmlFromUrl(path);
if (xml.isNull()) { if (xml.isNull()) {
return QStringLiteral("-1"); return QStringLiteral("-1");
......
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