waffles: context menus for app buttons

This commit is contained in:
end-4
2025-12-07 00:04:24 +01:00
parent 13968db31c
commit 6c460b209c
13 changed files with 155 additions and 20 deletions
@@ -95,6 +95,5 @@ Menu {
delegate: WMenuItem {
id: menuItemDelegate
width: ListView.view?.width
}
}
@@ -55,6 +55,9 @@ MenuItem {
rightInset: inset
horizontalPadding: 11
width: ListView.view?.width
height: visible ? implicitHeight : 0
background: Rectangle {
id: backgroundRect
radius: Looks.radius.medium
@@ -57,7 +57,6 @@ Scope {
Item {
anchors.fill: parent
focus: true
Keys.onPressed: (event) => {
if (event.key === Qt.Key_Escape) {
sessionRoot.hide();
@@ -200,6 +200,16 @@ RowLayout {
resultPreview.entry.execute();
}
}),
...(isAppEntry ? [
searchResultComp.createObject(null, {
name: startPinned ? Translation.tr("Unpin from Start") : Translation.tr("Pin to Start"),
iconName: startPinned ? "keep_off" : "keep",
iconType: LauncherSearchResult.IconType.Material,
execute: () => {
LauncherApps.togglePin(appId);
}
})
] : []),
...(isAppEntry ? [
searchResultComp.createObject(null, {
name: pinned ? Translation.tr("Unpin from taskbar") : Translation.tr("Pin to taskbar"),
@@ -210,20 +220,6 @@ RowLayout {
}
})
] : []),
...(isAppEntry ? [
searchResultComp.createObject(null, {
name: startPinned ? Translation.tr("Unpin from start") : Translation.tr("Pin to start"),
iconName: startPinned ? "keep_off" : "keep",
iconType: LauncherSearchResult.IconType.Material,
execute: () => {
if (Config.options.launcher.pinnedApps.indexOf(appId) !== -1) {
Config.options.launcher.pinnedApps = Config.options.launcher.pinnedApps.filter(id => id !== appId)
} else {
Config.options.launcher.pinnedApps = Config.options.launcher.pinnedApps.concat([appId])
}
}
})
] : [])
];
result = result.concat(resultPreview.entry.actions);
return result;
@@ -274,6 +274,9 @@ Rectangle {
id: smallGridAppButton
property DesktopEntry desktopEntry
property bool pinnedStart: LauncherApps.isPinned(smallGridAppButton.desktopEntry.id);
property bool pinnedTaskbar: TaskbarApps.isPinned(smallGridAppButton.desktopEntry.id);
onClicked: {
GlobalStates.searchOpen = false;
desktopEntry.execute();
@@ -298,6 +301,30 @@ Rectangle {
WToolTip {
text: smallGridAppButton.desktopEntry.name
}
altAction: () => {
appMenu.popup();
}
WMenu {
id: appMenu
downDirection: true
WMenuItem {
icon.name: smallGridAppButton.pinnedStart ? "pin-off" : "pin"
text: smallGridAppButton.pinnedStart ? Translation.tr("Unpin from Start") : Translation.tr("Pin to Start")
onTriggered: {
LauncherApps.togglePin(smallGridAppButton.desktopEntry.id);
}
}
WMenuItem {
icon.name: smallGridAppButton.pinnedTaskbar ? "pin-off" : "pin"
text: smallGridAppButton.pinnedTaskbar ? Translation.tr("Unpin from taskbar") : Translation.tr("Pin to taskbar")
onTriggered: {
TaskbarApps.togglePin(smallGridAppButton.desktopEntry.id);
}
}
}
}
component SmallGridButton: WButton {
@@ -23,9 +23,7 @@ GridLayout {
uniformCellWidths: true
Repeater {
model: ScriptModel {
values: root.desktopEntries
}
model: root.desktopEntries
delegate: StartAppButton {
id: pinnedAppButton
required property var modelData
@@ -14,6 +14,10 @@ import qs.modules.waffle.looks
WButton {
id: root
required property DesktopEntry desktopEntry
property bool pinnedStart: LauncherApps.isPinned(root.desktopEntry.id);
property bool pinnedTaskbar: TaskbarApps.isPinned(root.desktopEntry.id);
implicitWidth: 96
implicitHeight: 84
horizontalPadding: 0
@@ -43,4 +47,52 @@ WButton {
WToolTip {
text: root.desktopEntry.name
}
altAction: () => {
appMenu.popup()
}
WMenu {
id: appMenu
downDirection: true
WMenuItem {
visible: root.pinnedStart
icon.name: "arrow-up-left"
text: Translation.tr("Move to front")
onTriggered: {
LauncherApps.moveToFront(root.desktopEntry.id);
}
}
WMenuItem {
visible: root.pinnedStart
icon.name: "arrow-left"
text: Translation.tr("Move left")
onTriggered: {
LauncherApps.moveLeft(root.desktopEntry.id);
}
}
WMenuItem {
visible: root.pinnedStart
icon.name: "arrow-right"
text: Translation.tr("Move right")
onTriggered: {
LauncherApps.moveRight(root.desktopEntry.id);
}
}
WMenuItem {
icon.name: root.pinnedStart ? "pin-off" : "pin"
text: root.pinnedStart ? Translation.tr("Unpin from Start") : Translation.tr("Pin to Start")
onTriggered: {
LauncherApps.togglePin(root.desktopEntry.id);
}
}
WMenuItem {
icon.name: root.pinnedTaskbar ? "pin-off" : "pin"
text: root.pinnedTaskbar ? Translation.tr("Unpin from taskbar") : Translation.tr("Pin to taskbar")
onTriggered: {
TaskbarApps.togglePin(root.desktopEntry.id);
}
}
}
}