Skip to content

Commit 13160be

Browse files
wjyrichBLumia
authored andcommitted
fix: Dragging applications in the application folder cannot create a new page
as title. pms-bug-288839
1 parent cde3c4f commit 13160be

3 files changed

Lines changed: 44 additions & 7 deletions

File tree

qml/FolderGridViewPopup.qml

Lines changed: 22 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,9 +181,11 @@ 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
188+
createdEmptyPage = false
187189
}
188190
onPageIntentChanged: {
189191
if (pageIntent !== 0) {
@@ -198,7 +200,16 @@ Popup {
198200
interval: 1000
199201
onTriggered: {
200202
if (parent.pageIntent > 0) {
201-
incrementPageIndex(folderPagesView)
203+
let isLastPage = (folderPagesView.currentIndex === folderPagesView.count - 1)
204+
if (isLastPage && !folderPageDropArea.createdEmptyPage) {
205+
let newPageIndex = ItemArrangementProxyModel.creatEmptyPage(folderLoader.currentFolderId)
206+
folderPageDropArea.createdEmptyPage = true
207+
folderPagesView.setCurrentIndex(newPageIndex)
208+
parent.pageIntent = 0
209+
return
210+
}else{
211+
incrementPageIndex(folderPagesView)
212+
}
202213
} else if (parent.pageIntent < 0) {
203214
decrementPageIndex(folderPagesView)
204215
}
@@ -240,6 +251,14 @@ Popup {
240251

241252
currentIndex: folderPageIndicator.currentIndex
242253

254+
Connections {
255+
target: ItemArrangementProxyModel
256+
function onFolderPageCountChanged(folderId) {
257+
if (folderId === folderLoader.currentFolderId) {
258+
gridViews.model = ItemArrangementProxyModel.pageCount(folderId)
259+
}
260+
}
261+
}
243262
Repeater {
244263
id: gridViews
245264
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)