diff --git a/qml/FolderGridViewPopup.qml b/qml/FolderGridViewPopup.qml index 822eec6e..335ab204 100644 --- a/qml/FolderGridViewPopup.qml +++ b/qml/FolderGridViewPopup.qml @@ -151,14 +151,14 @@ Popup { readonly property real paddingColumns: 0.3 readonly property int horizontalPadding: contentRoot.width * paddingColumns anchors.fill: parent - + property bool createdEmptyPage: false function checkDragMove() { if (drag.x < horizontalPadding) { pageIntent = -1 } else if (drag.x > (width - horizontalPadding)) { let isLastPage = folderPagesView.currentIndex === folderPagesView.count - 1 - if (isLastPage) { + if (isLastPage && folderPageDropArea.createdEmptyPage) { return } pageIntent = 1 @@ -181,9 +181,11 @@ Popup { let dragId = drop.getDataAsString("text/x-dde-launcher-dnd-desktopId") dropOnPage(dragId, "internal/folders/" + folderLoader.currentFolderId, folderPagesView.currentIndex) pageIntent = 0 + createdEmptyPage = false } onExited: { pageIntent = 0 + createdEmptyPage = false } onPageIntentChanged: { if (pageIntent !== 0) { @@ -198,7 +200,16 @@ Popup { interval: 1000 onTriggered: { if (parent.pageIntent > 0) { - incrementPageIndex(folderPagesView) + let isLastPage = (folderPagesView.currentIndex === folderPagesView.count - 1) + if (isLastPage && !folderPageDropArea.createdEmptyPage) { + let newPageIndex = ItemArrangementProxyModel.creatEmptyPage(folderLoader.currentFolderId) + folderPageDropArea.createdEmptyPage = true + folderPagesView.setCurrentIndex(newPageIndex) + parent.pageIntent = 0 + return + }else{ + incrementPageIndex(folderPagesView) + } } else if (parent.pageIntent < 0) { decrementPageIndex(folderPagesView) } @@ -240,6 +251,14 @@ Popup { currentIndex: folderPageIndicator.currentIndex + Connections { + target: ItemArrangementProxyModel + function onFolderPageCountChanged(folderId) { + if (folderId === folderLoader.currentFolderId) { + gridViews.model = ItemArrangementProxyModel.pageCount(folderId) + } + } + } Repeater { id: gridViews model: ItemArrangementProxyModel.pageCount(folderLoader.currentFolderId) // FIXME: should be a property? diff --git a/src/models/itemarrangementproxymodel.cpp b/src/models/itemarrangementproxymodel.cpp index fc06734d..f3008f73 100644 --- a/src/models/itemarrangementproxymodel.cpp +++ b/src/models/itemarrangementproxymodel.cpp @@ -153,10 +153,22 @@ void ItemArrangementProxyModel::commitDndOperation(const QString &dragId, const } // return new empty page index -int ItemArrangementProxyModel::creatEmptyPage() const +int ItemArrangementProxyModel::creatEmptyPage(int folderId) const { - m_topLevel->appendEmptyPage(); - return m_topLevel->pageCount() - 1; + if(folderId == 0){ + m_topLevel->appendEmptyPage(); + return m_topLevel->pageCount() - 1; + } + QString fullId("internal/folders/" + QString::number(folderId)); + Q_ASSERT(m_folders.contains(fullId)); + + if (auto itemPage = m_folders.value(fullId); itemPage) { + itemPage->appendEmptyPage(); + return itemPage->pageCount() - 1; + } else { + qWarning() << "itemPage create empty page false, return 0. fullId is" << fullId; + return 0; + } } void ItemArrangementProxyModel::removeEmptyPage() const @@ -408,6 +420,11 @@ ItemsPage *ItemArrangementProxyModel::createFolder(const QString &id) folder->setData(fullId, AppItem::DesktopIdRole); m_folderModel.appendRow(folder); + connect(page, &ItemsPage::pageCountChanged, this, [this, fullId]() { + int folderId = QStringView{fullId}.mid(17).toInt(); + emit folderPageCountChanged(folderId); + }); + return page; } diff --git a/src/models/itemarrangementproxymodel.h b/src/models/itemarrangementproxymodel.h index 765cb05e..78dc97b7 100644 --- a/src/models/itemarrangementproxymodel.h +++ b/src/models/itemarrangementproxymodel.h @@ -58,7 +58,7 @@ class ItemArrangementProxyModel : public QConcatenateTablesProxyModel Q_INVOKABLE void updateFolderName(int folderId, const QString & name); Q_INVOKABLE void bringToFront(const QString & id); Q_INVOKABLE void commitDndOperation(const QString & dragId, const QString & dropId, const DndOperation op, int pageHint = -1); - Q_INVOKABLE int creatEmptyPage() const; + Q_INVOKABLE int creatEmptyPage(int folderId = 0) const; Q_INVOKABLE void removeEmptyPage() const; ItemsPage *itemsPage() { return m_topLevel; } @@ -70,6 +70,7 @@ class ItemArrangementProxyModel : public QConcatenateTablesProxyModel signals: void topLevelPageCountChanged(); + void folderPageCountChanged(int folderId); private: explicit ItemArrangementProxyModel(QObject *parent = nullptr);