From 85e434913b68394d5a7d07be121c4fc521e907a4 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Sun, 10 Jul 2022 22:49:55 -0400 Subject: [PATCH] homescreens/halcyon: Add ability to move out of folder --- .../homescreens/halcyon/applicationfolder.cpp | 10 ++++++++++ .../homescreens/halcyon/applicationfolder.h | 2 ++ .../package/contents/ui/FavoritesAppDelegate.qml | 16 +++++++++++----- .../package/contents/ui/FavoritesGrid.qml | 9 ++++++++- .../halcyon/package/contents/ui/FolderGrid.qml | 13 ++++++++++++- containments/homescreens/halcyon/pinnedmodel.cpp | 8 ++++++++ containments/homescreens/halcyon/pinnedmodel.h | 3 +++ 7 files changed, 54 insertions(+), 7 deletions(-) diff --git a/containments/homescreens/halcyon/applicationfolder.cpp b/containments/homescreens/halcyon/applicationfolder.cpp index 1b56da15..2d2b5ab7 100644 --- a/containments/homescreens/halcyon/applicationfolder.cpp +++ b/containments/homescreens/halcyon/applicationfolder.cpp @@ -123,3 +123,13 @@ void ApplicationFolder::removeApp(int row) Q_EMIT applicationsChanged(); Q_EMIT saveRequested(); } + +void ApplicationFolder::moveAppOut(int row) +{ + if (row < 0 || row >= m_applications.size()) { + return; + } + + Q_EMIT moveAppOutRequested(m_applications[row]->storageId()); + removeApp(row); +} diff --git a/containments/homescreens/halcyon/applicationfolder.h b/containments/homescreens/halcyon/applicationfolder.h index bd372e3a..faa73fd0 100644 --- a/containments/homescreens/halcyon/applicationfolder.h +++ b/containments/homescreens/halcyon/applicationfolder.h @@ -42,11 +42,13 @@ public: Q_INVOKABLE void moveEntry(int fromRow, int toRow); Q_INVOKABLE void addApp(const QString &storageId, int row); Q_INVOKABLE void removeApp(int row); + Q_INVOKABLE void moveAppOut(int row); // moves app to main page Q_SIGNALS: void nameChanged(); void applicationsChanged(); void saveRequested(); + void moveAppOutRequested(const QString &storageId); private: QString m_name; diff --git a/containments/homescreens/halcyon/package/contents/ui/FavoritesAppDelegate.qml b/containments/homescreens/halcyon/package/contents/ui/FavoritesAppDelegate.qml index 65aa2d2c..17c9a5fa 100644 --- a/containments/homescreens/halcyon/package/contents/ui/FavoritesAppDelegate.qml +++ b/containments/homescreens/halcyon/package/contents/ui/FavoritesAppDelegate.qml @@ -26,6 +26,8 @@ Item { property real dragFolderAnimationProgress: 0 + property list menuActions + // whether this delegate is a folder property bool isFolder @@ -40,7 +42,6 @@ Item { readonly property string applicationIcon: application ? application.icon : "" signal folderOpenRequested() - signal removeRequested() property alias drag: mouseArea.drag Drag.active: delegate.drag.active @@ -96,14 +97,19 @@ Item { active: false sourceComponent: PlasmaComponents.Menu { + id: menu title: label.text closePolicy: PlasmaComponents.Menu.CloseOnReleaseOutside | PlasmaComponents.Menu.CloseOnEscape - PlasmaComponents.MenuItem { - icon.name: "emblem-favorite" - text: i18n("Remove from favourites") - onClicked: delegate.removeRequested() + Repeater { + model: menuActions + delegate: PlasmaComponents.MenuItem { + icon.name: modelData.iconName + text: modelData.text + onClicked: modelData.triggered() + } } + onClosed: dialogLoader.active = false } } diff --git a/containments/homescreens/halcyon/package/contents/ui/FavoritesGrid.qml b/containments/homescreens/halcyon/package/contents/ui/FavoritesGrid.qml index f1e5d4e1..9fa8e6a8 100644 --- a/containments/homescreens/halcyon/package/contents/ui/FavoritesGrid.qml +++ b/containments/homescreens/halcyon/package/contents/ui/FavoritesGrid.qml @@ -217,7 +217,14 @@ MobileShell.GridView { application: model.application onFolderOpenRequested: root.requestOpenFolder(model.folder) - onRemoveRequested: Halcyon.PinnedModel.removeEntry(model.index); + + menuActions: [ + Kirigami.Action { + iconName: "emblem-favorite" + text: i18n("Remove from favourites") + onTriggered: root.folder.removeApp(model.index) + } + ] readonly property bool isLeftColumn: !root.twoColumn || ((visualIndex % 2) === 0) readonly property bool isRightColumn: !root.twoColumn || ((visualIndex % 2) !== 0) diff --git a/containments/homescreens/halcyon/package/contents/ui/FolderGrid.qml b/containments/homescreens/halcyon/package/contents/ui/FolderGrid.qml index 8253873c..9a865a5d 100644 --- a/containments/homescreens/halcyon/package/contents/ui/FolderGrid.qml +++ b/containments/homescreens/halcyon/package/contents/ui/FolderGrid.qml @@ -123,7 +123,18 @@ MobileShell.GridView { isFolder: false application: modelData - onRemoveRequested: root.folder.removeApp(model.index); + menuActions: [ + Kirigami.Action { + iconName: "emblem-favorite" + text: i18n("Remove from favourites") + onTriggered: root.folder.removeApp(model.index) + }, + Kirigami.Action { + iconName: "document-open-folder" + text: i18n("Move out of folder") + onTriggered: root.folder.moveAppOut(model.index) + } + ] readonly property bool isLeftColumn: !root.twoColumn || ((visualIndex % 2) === 0) readonly property bool isRightColumn: !root.twoColumn || ((visualIndex % 2) !== 0) diff --git a/containments/homescreens/halcyon/pinnedmodel.cpp b/containments/homescreens/halcyon/pinnedmodel.cpp index 01198d22..d234f21d 100644 --- a/containments/homescreens/halcyon/pinnedmodel.cpp +++ b/containments/homescreens/halcyon/pinnedmodel.cpp @@ -70,6 +70,7 @@ void PinnedModel::addFolder(QString name, int row) ApplicationFolder *folder = new ApplicationFolder(this, name); connect(folder, &ApplicationFolder::saveRequested, this, &PinnedModel::save); + connect(folder, &ApplicationFolder::moveAppOutRequested, this, &PinnedModel::addAppFromFolder); beginInsertRows(QModelIndex(), row, row); m_applications.insert(row, nullptr); @@ -146,6 +147,7 @@ void PinnedModel::createFolderFromApps(int sourceAppRow, int draggedAppRow) // replace source app with folder containing both apps ApplicationFolder *folder = new ApplicationFolder(this, i18nc("Default application folder name.", "Folder")); connect(folder, &ApplicationFolder::saveRequested, this, &PinnedModel::save); + connect(folder, &ApplicationFolder::moveAppOutRequested, this, &PinnedModel::addAppFromFolder); folder->addApp(m_applications[sourceAppRow]->storageId(), 0); folder->addApp(m_applications[draggedAppRow]->storageId(), 0); @@ -203,6 +205,7 @@ void PinnedModel::load() // read folder ApplicationFolder *folder = ApplicationFolder::fromJson(obj, this); connect(folder, &ApplicationFolder::saveRequested, this, &PinnedModel::save); + connect(folder, &ApplicationFolder::moveAppOutRequested, this, &PinnedModel::addAppFromFolder); if (folder) { m_applications.append(nullptr); @@ -233,3 +236,8 @@ void PinnedModel::save() m_applet->config().writeEntry("Pinned", QString::fromStdString(data.toStdString())); Q_EMIT m_applet->configNeedsSaving(); } + +void PinnedModel::addAppFromFolder(const QString &storageId) +{ + addApp(storageId, 0); +} diff --git a/containments/homescreens/halcyon/pinnedmodel.h b/containments/homescreens/halcyon/pinnedmodel.h index f9e7adec..06932ea5 100644 --- a/containments/homescreens/halcyon/pinnedmodel.h +++ b/containments/homescreens/halcyon/pinnedmodel.h @@ -47,6 +47,9 @@ public: Q_INVOKABLE void load(); void save(); +public Q_SLOTS: + void addAppFromFolder(const QString &storageId); + private: QList m_applications; QList m_folders;