From ccf6ebef4d9d21f198827f14cbd8d709f83777a6 Mon Sep 17 00:00:00 2001 From: Nariman Jelveh Date: Sun, 16 Jun 2024 20:18:11 -0700 Subject: [PATCH] Add support for `disabled` context menu items through puter.js --- src/IPC.js | 1 + src/UI/UIContextMenu.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/IPC.js b/src/IPC.js index 4ad41d18..0c021713 100644 --- a/src/IPC.js +++ b/src/IPC.js @@ -426,6 +426,7 @@ window.addEventListener('message', async (event) => { html: item.label, icon: item.icon ? `` : undefined, icon_active: item.icon_active ? `` : undefined, + disabled: item.disabled, onClick: () => { if (item.action !== undefined) { item.action(); diff --git a/src/UI/UIContextMenu.js b/src/UI/UIContextMenu.js index c37d3937..9b5a174e 100644 --- a/src/UI/UIContextMenu.js +++ b/src/UI/UIContextMenu.js @@ -261,7 +261,14 @@ function UIContextMenu(options){ } }); - // Useful in cases such as where a menu item is over a window, this prevents from the mousedown event + // disabled item mousedown event + $(`#context-menu-${menu_id} > li.context-menu-item-disabled`).on('mousedown', function (e) { + e.preventDefault(); + e.stopPropagation(); + return false; + }) + + // Useful in cases such as where a menu item is over a window, this prevents the mousedown event from // reaching the window underneath $(`#context-menu-${menu_id} > li:not(.context-menu-item-disabled)`).on('mousedown', function (e) { e.preventDefault();