Add handling to disable items on context menu

pull/4500/head
Kazuhito Yokoi 2023-12-16 17:02:18 +09:00
parent 0e8d312794
commit 70ea5c839a
1 changed files with 5 additions and 3 deletions

View File

@ -32,6 +32,8 @@ RED.contextMenu = (function () {
const canRemoveFromGroup = hasSelection && !!selection.nodes[0].g const canRemoveFromGroup = hasSelection && !!selection.nodes[0].g
const isAllGroups = hasSelection && selection.nodes.filter(n => n.type !== 'group').length === 0 const isAllGroups = hasSelection && selection.nodes.filter(n => n.type !== 'group').length === 0
const hasGroup = hasSelection && selection.nodes.filter(n => n.type === 'group').length > 0 const hasGroup = hasSelection && selection.nodes.filter(n => n.type === 'group').length > 0
const hasDisabledNode = hasSelection && selection.nodes.filter(e => e.d).length > 0;
const hasEnabledNode = hasSelection && selection.nodes.filter(e => !e.d).length > 0;
const offset = $("#red-ui-workspace-chart").offset() const offset = $("#red-ui-workspace-chart").offset()
let addX = options.x - offset.left + $("#red-ui-workspace-chart").scrollLeft() let addX = options.x - offset.left + $("#red-ui-workspace-chart").scrollLeft()
@ -113,8 +115,8 @@ RED.contextMenu = (function () {
) )
} }
nodeOptions.push( nodeOptions.push(
{ onselect: 'core:enable-selected-nodes', label: RED._('menu.label.enableSelectedNodes') }, { onselect: 'core:enable-selected-nodes', label: RED._('menu.label.enableSelectedNodes'), disabled: !hasDisabledNode },
{ onselect: 'core:disable-selected-nodes', label: RED._('menu.label.disableSelectedNodes') }, { onselect: 'core:disable-selected-nodes', label: RED._('menu.label.disableSelectedNodes'), disabled: !hasEnabledNode },
null, null,
{ onselect: 'core:show-selected-node-labels', label: RED._('menu.label.showSelectedNodeLabels') }, { onselect: 'core:show-selected-node-labels', label: RED._('menu.label.showSelectedNodeLabels') },
{ onselect: 'core:hide-selected-node-labels', label: RED._('menu.label.hideSelectedNodeLabels') } { onselect: 'core:hide-selected-node-labels', label: RED._('menu.label.hideSelectedNodeLabels') }