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

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