From 17223a00fcd3f8b505c7e9cf52c814cc301f5b3b Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Mon, 20 Jan 2025 15:18:43 +1100 Subject: launcher: context menu for items --- src/modules/launcher.tsx | 82 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/modules/launcher.tsx b/src/modules/launcher.tsx index 67d0ee9..0e72224 100644 --- a/src/modules/launcher.tsx +++ b/src/modules/launcher.tsx @@ -8,7 +8,7 @@ import { Apps } from "../services/apps"; import Math, { type HistoryItem } from "../services/math"; import { getAppCategoryIcon } from "../utils/icons"; import { launch } from "../utils/system"; -import { setupCustomTooltip } from "../utils/widgets"; +import { MenuItem, setupCustomTooltip } from "../utils/widgets"; import PopupWindow from "../widgets/popupwindow"; type Mode = "apps" | "files" | "math"; @@ -73,18 +73,40 @@ const PinnedApp = (names: string[]) => { } } - if (!app) console.error(`Launcher - Unable to find app for "${names.join(", ")}"`); + if (!app) { + console.error(`Launcher - Unable to find app for "${names.join(", ")}"`); + return null; + } - return app ? ( + const menu = new Gtk.Menu(); + menu.append(new MenuItem({ label: "Launch", onActivate: () => launchAndClose(widget, astalApp!) })); + + if (app.list_actions().length > 0) menu.append(new Gtk.SeparatorMenuItem({ visible: true })); + app.list_actions().forEach(action => { + menu.append( + new MenuItem({ + label: app.get_action_name(action), + onActivate: () => { + close(widget); // Pass result cause menu is its own toplevel + app.launch_action(action, null); + }, + }) + ); + }); + + const widget = ( - ) : null; + ); + return widget; }; const PinnedApps = () => {config.pins.map(PinnedApp)}; @@ -112,14 +134,24 @@ const Result = ({ label, sublabel, onClicked, + onSecondaryClick, + onDestroy, }: { icon?: string; materialIcon?: string; label: string; sublabel?: string; onClicked: (self: Widget.Button) => void; + onSecondaryClick?: (self: Widget.Button) => void; + onDestroy?: () => void; }) => ( -