Skip to content

Commit

Permalink
feat: special context menu for dummy apps
Browse files Browse the repository at this point in the history
为占位包实现了仅有“安装”和“移除”的右键菜单。

Log: 为占位应用图标提供了简单版本的右键菜单。
  • Loading branch information
RigoLigoRLC authored and BLumia committed Oct 16, 2024
1 parent 7539f1d commit d5e05aa
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ set(QML_FILES
${PROJECT_SOURCE_DIR}/qml/Main.qml
${PROJECT_SOURCE_DIR}/qml/FullscreenFrame.qml
${PROJECT_SOURCE_DIR}/qml/AppItemMenu.qml
${PROJECT_SOURCE_DIR}/qml/DummyAppItemMenu.qml
${PROJECT_SOURCE_DIR}/qml/GridViewContainer.qml
${PROJECT_SOURCE_DIR}/qml/DrawerFolder.qml
${PROJECT_SOURCE_DIR}/qml/IconItemDelegate.qml
Expand All @@ -84,6 +85,7 @@ get_target_property(WINDOWED_QML_FILES launcher-qml-windowed QT_QML_MODULE_QML_F
# see also: https://www.qt.io/blog/revisited-i18n-with-cmake
set(QML_FILES_NEED_TRANSLATION
qml/AppItemMenu.qml
qml/DummyAppItemMenu.qml
qml/Main.qml
qml/FullscreenFrame.qml
${WINDOWED_QML_FILES}
Expand Down
70 changes: 70 additions & 0 deletions qml/DummyAppItemMenu.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

import QtQuick 2.15
import QtQuick.Controls 2.15
import org.deepin.dtk 1.0

import org.deepin.launchpad 1.0
import org.deepin.launchpad.models 1.0

Loader {
id: root

property string desktopId

signal closed()

Component {
id: contextMenuComp

Menu {
id: contextMenu
modal: true

MenuItem {
text: qsTr("Install")
onTriggered: {
launchApp(root.desktopId)
}
}

MenuItem {
text: qsTr("Remove")
onTriggered: {
DesktopIntegration.uninstallApp(root.desktopId)
}
}

onClosed: {
root.closed()
root.destroy()
}
}
}

Connections {
target: LauncherController
function onVisibleChanged(visible) {
if (!LauncherController.visible) {
item.close()
}
}
}

asynchronous: true
sourceComponent: contextMenuComp

function popup() {
active = true
}

function close() {
active = false
}

onStatusChanged: if (status == Loader.Ready) {
item.popup()
}
}
39 changes: 26 additions & 13 deletions qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,39 @@ QtObject {

property var activeMenu: null
property Component appContextMenuCom: AppItemMenu { }
property Component dummyAppContextMenuCom: DummyAppItemMenu {}
function showContextMenu(obj, model, additionalProps = {}) {
if (!obj || !obj.Window.window) {
console.log("obj or obj.Window.window is null")
return
}
closeContextMenu()

const menu = appContextMenuCom.createObject(obj.Window.window.contentItem, Object.assign({
display: model.display,
desktopId: model.desktopId,
iconName: model.iconName,
isFavoriteItem: false,
hideFavoriteMenu: true,
hideDisplayScalingMenu: false,
hideMoveToTopMenu: true
}, additionalProps));
menu.closed.connect(menu.destroy)
menu.popup();

activeMenu = menu
if (!DesktopIntegration.appIsDummyPackage(model.desktopId)) {
// Pop a menu for normal apps
const menu = appContextMenuCom.createObject(obj.Window.window.contentItem, Object.assign({
display: model.display,
desktopId: model.desktopId,
iconName: model.iconName,
isFavoriteItem: false,
hideFavoriteMenu: true,
hideDisplayScalingMenu: false,
hideMoveToTopMenu: true
}, additionalProps));
menu.closed.connect(menu.destroy)
menu.popup();

activeMenu = menu
} else {
// Pop a simplified menu for dummy apps
const menu = dummyAppContextMenuCom.createObject(obj.Window.window.contentItem, Object.assign({
desktopId: model.desktopId
}), additionalProps);
menu.closed.connect(menu.destroy)
menu.popup();

activeMenu = menu
}
}

function closeContextMenu() {
Expand Down

0 comments on commit d5e05aa

Please sign in to comment.