Skip to content

Commit c88df9d

Browse files
committed
fix: Dragging applications in the application folder cannot create a new page
as title. pms-bug-288839
1 parent 46e4d3d commit c88df9d

3 files changed

Lines changed: 43 additions & 7 deletions

File tree

qml/FolderGridViewPopup.qml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ Popup {
151151
readonly property real paddingColumns: 0.3
152152
readonly property int horizontalPadding: contentRoot.width * paddingColumns
153153
anchors.fill: parent
154-
154+
property bool createdEmptyPage: false
155155

156156
function checkDragMove() {
157157
if (drag.x < horizontalPadding) {
158158
pageIntent = -1
159159
} else if (drag.x > (width - horizontalPadding)) {
160160
let isLastPage = folderPagesView.currentIndex === folderPagesView.count - 1
161-
if (isLastPage) {
161+
if (isLastPage && folderPageDropArea.createdEmptyPage) {
162162
return
163163
}
164164
pageIntent = 1
@@ -181,6 +181,7 @@ Popup {
181181
let dragId = drop.getDataAsString("text/x-dde-launcher-dnd-desktopId")
182182
dropOnPage(dragId, "internal/folders/" + folderLoader.currentFolderId, folderPagesView.currentIndex)
183183
pageIntent = 0
184+
createdEmptyPage = false
184185
}
185186
onExited: {
186187
pageIntent = 0
@@ -198,7 +199,16 @@ Popup {
198199
interval: 1000
199200
onTriggered: {
200201
if (parent.pageIntent > 0) {
201-
incrementPageIndex(folderPagesView)
202+
let isLastPage = (folderPagesView.currentIndex === folderPagesView.count - 1)
203+
if (isLastPage && !folderPageDropArea.createdEmptyPage) {
204+
let newPageIndex = ItemArrangementProxyModel.creatEmptyPage(folderLoader.currentFolderId)
205+
folderPageDropArea.createdEmptyPage = true
206+
folderPagesView.setCurrentIndex(newPageIndex)
207+
parent.pageIntent = 0
208+
return
209+
}else{
210+
incrementPageIndex(folderPagesView)
211+
}
202212
} else if (parent.pageIntent < 0) {
203213
decrementPageIndex(folderPagesView)
204214
}
@@ -240,6 +250,14 @@ Popup {
240250

241251
currentIndex: folderPageIndicator.currentIndex
242252

253+
Connections {
254+
target: ItemArrangementProxyModel
255+
function onFolderPageCountChanged(folderId) {
256+
if (folderId === folderLoader.currentFolderId) {
257+
gridViews.model = ItemArrangementProxyModel.pageCount(folderId)
258+
}
259+
}
260+
}
243261
Repeater {
244262
id: gridViews
245263
model: ItemArrangementProxyModel.pageCount(folderLoader.currentFolderId) // FIXME: should be a property?

src/models/itemarrangementproxymodel.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,22 @@ void ItemArrangementProxyModel::commitDndOperation(const QString &dragId, const
153153
}
154154

155155
// return new empty page index
156-
int ItemArrangementProxyModel::creatEmptyPage() const
156+
int ItemArrangementProxyModel::creatEmptyPage(int folderId) const
157157
{
158-
m_topLevel->appendEmptyPage();
159-
return m_topLevel->pageCount() - 1;
158+
if(folderId == 0){
159+
m_topLevel->appendEmptyPage();
160+
return m_topLevel->pageCount() - 1;
161+
}
162+
QString fullId("internal/folders/" + QString::number(folderId));
163+
Q_ASSERT(m_folders.contains(fullId));
164+
165+
if (auto itemPage = m_folders.value(fullId); itemPage) {
166+
itemPage->appendEmptyPage();
167+
return itemPage->pageCount() - 1;
168+
} else {
169+
qWarning() << "itemPage create empty page false, return 0. fullId is" << fullId;
170+
return 0;
171+
}
160172
}
161173

162174
void ItemArrangementProxyModel::removeEmptyPage() const
@@ -408,6 +420,11 @@ ItemsPage *ItemArrangementProxyModel::createFolder(const QString &id)
408420
folder->setData(fullId, AppItem::DesktopIdRole);
409421
m_folderModel.appendRow(folder);
410422

423+
connect(page, &ItemsPage::pageCountChanged, this, [this, fullId]() {
424+
int folderId = QStringView{fullId}.mid(17).toInt();
425+
emit folderPageCountChanged(folderId);
426+
});
427+
411428
return page;
412429
}
413430

src/models/itemarrangementproxymodel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ItemArrangementProxyModel : public QConcatenateTablesProxyModel
5858
Q_INVOKABLE void updateFolderName(int folderId, const QString & name);
5959
Q_INVOKABLE void bringToFront(const QString & id);
6060
Q_INVOKABLE void commitDndOperation(const QString & dragId, const QString & dropId, const DndOperation op, int pageHint = -1);
61-
Q_INVOKABLE int creatEmptyPage() const;
61+
Q_INVOKABLE int creatEmptyPage(int folderId = 0) const;
6262
Q_INVOKABLE void removeEmptyPage() const;
6363

6464
ItemsPage *itemsPage() { return m_topLevel; }
@@ -70,6 +70,7 @@ class ItemArrangementProxyModel : public QConcatenateTablesProxyModel
7070

7171
signals:
7272
void topLevelPageCountChanged();
73+
void folderPageCountChanged(int folderId);
7374

7475
private:
7576
explicit ItemArrangementProxyModel(QObject *parent = nullptr);

0 commit comments

Comments
 (0)