Merge pull request #4069 from node-red/prevent-edit-from-sidebar

Prevent opening locked node's edit dialog
This commit is contained in:
Nick O'Leary 2023-02-24 13:10:01 +00:00 committed by GitHub
commit 910f6134f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 37 deletions

View File

@ -503,7 +503,7 @@ RED.clipboard = (function() {
$("#red-ui-clipboard-dialog-import-text").on("keyup", validateImport); $("#red-ui-clipboard-dialog-import-text").on("keyup", validateImport);
$("#red-ui-clipboard-dialog-import-text").on('paste',function() { setTimeout(validateImport,10)}); $("#red-ui-clipboard-dialog-import-text").on('paste',function() { setTimeout(validateImport,10)});
if (RED.workspaces.active() === 0 || RED.workspaces.isActiveLocked()) { if (RED.workspaces.active() === 0 || RED.workspaces.isLocked()) {
$("#red-ui-clipboard-dialog-import-opt-current").addClass('disabled').removeClass("selected"); $("#red-ui-clipboard-dialog-import-opt-current").addClass('disabled').removeClass("selected");
$("#red-ui-clipboard-dialog-import-opt-new").addClass("selected"); $("#red-ui-clipboard-dialog-import-opt-new").addClass("selected");
} else { } else {
@ -1278,7 +1278,7 @@ RED.clipboard = (function() {
RED.keyboard.add("#red-ui-drop-target", "escape" ,hideDropTarget); RED.keyboard.add("#red-ui-drop-target", "escape" ,hideDropTarget);
$('#red-ui-workspace-chart').on("dragenter",function(event) { $('#red-ui-workspace-chart').on("dragenter",function(event) {
if (!RED.workspaces.isActiveLocked() && ( if (!RED.workspaces.isLocked() && (
$.inArray("text/plain",event.originalEvent.dataTransfer.types) != -1 || $.inArray("text/plain",event.originalEvent.dataTransfer.types) != -1 ||
$.inArray("Files",event.originalEvent.dataTransfer.types) != -1)) { $.inArray("Files",event.originalEvent.dataTransfer.types) != -1)) {
$("#red-ui-drop-target").css({display:'table'}).focus(); $("#red-ui-drop-target").css({display:'table'}).focus();
@ -1288,7 +1288,7 @@ RED.clipboard = (function() {
$('#red-ui-drop-target').on("dragover",function(event) { $('#red-ui-drop-target').on("dragover",function(event) {
if ($.inArray("text/plain",event.originalEvent.dataTransfer.types) != -1 || if ($.inArray("text/plain",event.originalEvent.dataTransfer.types) != -1 ||
$.inArray("Files",event.originalEvent.dataTransfer.types) != -1 || $.inArray("Files",event.originalEvent.dataTransfer.types) != -1 ||
RED.workspaces.isActiveLocked()) { RED.workspaces.isLocked()) {
event.preventDefault(); event.preventDefault();
} }
}) })
@ -1296,7 +1296,7 @@ RED.clipboard = (function() {
hideDropTarget(); hideDropTarget();
}) })
.on("drop",function(event) { .on("drop",function(event) {
if (!RED.workspaces.isActiveLocked()) { if (!RED.workspaces.isLocked()) {
try { try {
if ($.inArray("text/plain",event.originalEvent.dataTransfer.types) != -1) { if ($.inArray("text/plain",event.originalEvent.dataTransfer.types) != -1) {
var data = event.originalEvent.dataTransfer.getData("text/plain"); var data = event.originalEvent.dataTransfer.getData("text/plain");

View File

@ -28,7 +28,7 @@ RED.contextMenu = (function () {
const isMultipleLinks = !hasSelection && hasLinks && wireLinks.length > 1 const isMultipleLinks = !hasSelection && hasLinks && wireLinks.length > 1
const canDelete = hasSelection || hasLinks const canDelete = hasSelection || hasLinks
const isGroup = hasSelection && selection.nodes.length === 1 && selection.nodes[0].type === 'group' const isGroup = hasSelection && selection.nodes.length === 1 && selection.nodes[0].type === 'group'
const canEdit = !RED.workspaces.isActiveLocked() const canEdit = !RED.workspaces.isLocked()
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

View File

@ -860,6 +860,7 @@ RED.editor = (function() {
function showEditDialog(node, defaultTab) { function showEditDialog(node, defaultTab) {
if (buildingEditDialog) { return } if (buildingEditDialog) { return }
buildingEditDialog = true; buildingEditDialog = true;
if (node.z && RED.workspaces.isLocked(node.z)) { return }
var editing_node = node; var editing_node = node;
var removeInfoEditorOnClose = false; var removeInfoEditorOnClose = false;
var skipInfoRefreshOnClose = false; var skipInfoRefreshOnClose = false;
@ -1155,6 +1156,8 @@ RED.editor = (function() {
var editing_config_node = RED.nodes.node(id); var editing_config_node = RED.nodes.node(id);
var activeEditPanes = []; var activeEditPanes = [];
if (editing_config_node && editing_config_node.z && RED.workspaces.isLocked(editing_config_node.z)) { return }
var configNodeScope = ""; // default to global var configNodeScope = ""; // default to global
var activeSubflow = RED.nodes.subflow(RED.workspaces.active()); var activeSubflow = RED.nodes.subflow(RED.workspaces.active());
if (activeSubflow) { if (activeSubflow) {
@ -1708,6 +1711,7 @@ RED.editor = (function() {
function showEditGroupDialog(group, defaultTab) { function showEditGroupDialog(group, defaultTab) {
if (buildingEditDialog) { return } if (buildingEditDialog) { return }
buildingEditDialog = true; buildingEditDialog = true;
if (group.z && RED.workspaces.isLocked(group.z)) { return }
var editing_node = group; var editing_node = group;
editStack.push(group); editStack.push(group);
RED.view.state(RED.state.EDITING); RED.view.state(RED.state.EDITING);

View File

@ -188,7 +188,7 @@ RED.group = (function() {
var activateMerge = false; var activateMerge = false;
var activateRemove = false; var activateRemove = false;
var singleGroupSelected = false; var singleGroupSelected = false;
var locked = RED.workspaces.isActiveLocked() var locked = RED.workspaces.isLocked()
if (activateGroup) { if (activateGroup) {
singleGroupSelected = selection.nodes.length === 1 && selection.nodes[0].type === 'group'; singleGroupSelected = selection.nodes.length === 1 && selection.nodes[0].type === 'group';
@ -266,7 +266,7 @@ RED.group = (function() {
} }
} }
function pasteGroupStyle() { function pasteGroupStyle() {
if (RED.workspaces.isActiveLocked()) { return } if (RED.workspaces.isLocked()) { return }
if (RED.view.state() !== RED.state.DEFAULT) { return } if (RED.view.state() !== RED.state.DEFAULT) { return }
if (groupStyleClipboard) { if (groupStyleClipboard) {
var selection = RED.view.selection(); var selection = RED.view.selection();
@ -301,7 +301,7 @@ RED.group = (function() {
} }
function groupSelection() { function groupSelection() {
if (RED.workspaces.isActiveLocked()) { return } if (RED.workspaces.isLocked()) { return }
if (RED.view.state() !== RED.state.DEFAULT) { return } if (RED.view.state() !== RED.state.DEFAULT) { return }
var selection = RED.view.selection(); var selection = RED.view.selection();
if (selection.nodes) { if (selection.nodes) {
@ -320,7 +320,7 @@ RED.group = (function() {
} }
} }
function ungroupSelection() { function ungroupSelection() {
if (RED.workspaces.isActiveLocked()) { return } if (RED.workspaces.isLocked()) { return }
if (RED.view.state() !== RED.state.DEFAULT) { return } if (RED.view.state() !== RED.state.DEFAULT) { return }
var selection = RED.view.selection(); var selection = RED.view.selection();
if (selection.nodes) { if (selection.nodes) {
@ -344,7 +344,7 @@ RED.group = (function() {
} }
function ungroup(g) { function ungroup(g) {
if (RED.workspaces.isActiveLocked()) { return } if (RED.workspaces.isLocked()) { return }
var nodes = []; var nodes = [];
var parentGroup = RED.nodes.group(g.g); var parentGroup = RED.nodes.group(g.g);
g.nodes.forEach(function(n) { g.nodes.forEach(function(n) {
@ -371,7 +371,7 @@ RED.group = (function() {
} }
function mergeSelection() { function mergeSelection() {
if (RED.workspaces.isActiveLocked()) { return } if (RED.workspaces.isLocked()) { return }
if (RED.view.state() !== RED.state.DEFAULT) { return } if (RED.view.state() !== RED.state.DEFAULT) { return }
var selection = RED.view.selection(); var selection = RED.view.selection();
if (selection.nodes) { if (selection.nodes) {
@ -441,7 +441,7 @@ RED.group = (function() {
} }
function removeSelection() { function removeSelection() {
if (RED.workspaces.isActiveLocked()) { return } if (RED.workspaces.isLocked()) { return }
if (RED.view.state() !== RED.state.DEFAULT) { return } if (RED.view.state() !== RED.state.DEFAULT) { return }
var selection = RED.view.selection(); var selection = RED.view.selection();
if (selection.nodes) { if (selection.nodes) {
@ -469,7 +469,7 @@ RED.group = (function() {
} }
} }
function createGroup(nodes) { function createGroup(nodes) {
if (RED.workspaces.isActiveLocked()) { return } if (RED.workspaces.isLocked()) { return }
if (nodes.length === 0) { if (nodes.length === 0) {
return; return;
} }
@ -575,7 +575,7 @@ RED.group = (function() {
markDirty(group); markDirty(group);
} }
function removeFromGroup(group, nodes, reparent) { function removeFromGroup(group, nodes, reparent) {
if (RED.workspaces.isActiveLocked()) { return } if (RED.workspaces.isLocked()) { return }
if (!Array.isArray(nodes)) { if (!Array.isArray(nodes)) {
nodes = [nodes]; nodes = [nodes];
} }

View File

@ -573,7 +573,7 @@ RED.subflow = (function() {
} }
}); });
RED.events.on("view:selection-changed",function(selection) { RED.events.on("view:selection-changed",function(selection) {
if (!selection.nodes || RED.workspaces.isActiveLocked()) { if (!selection.nodes || RED.workspaces.isLocked()) {
RED.menu.setDisabled("menu-item-subflow-convert",true); RED.menu.setDisabled("menu-item-subflow-convert",true);
} else { } else {
RED.menu.setDisabled("menu-item-subflow-convert",false); RED.menu.setDisabled("menu-item-subflow-convert",false);
@ -636,7 +636,7 @@ RED.subflow = (function() {
} }
function convertToSubflow() { function convertToSubflow() {
if (RED.workspaces.isActiveLocked()) { if (RED.workspaces.isLocked()) {
return return
} }
var selection = RED.view.selection(); var selection = RED.view.selection();

View File

@ -39,7 +39,7 @@ RED.view.tools = (function() {
} }
function alignToGrid() { function alignToGrid() {
if (RED.workspaces.isActiveLocked()) { if (RED.workspaces.isLocked()) {
return return
} }
var selection = RED.view.selection(); var selection = RED.view.selection();
@ -90,7 +90,7 @@ RED.view.tools = (function() {
} }
function moveSelection(dx,dy) { function moveSelection(dx,dy) {
if (RED.workspaces.isActiveLocked()) { if (RED.workspaces.isLocked()) {
return return
} }
if (moving_set === null) { if (moving_set === null) {
@ -159,7 +159,7 @@ RED.view.tools = (function() {
} }
function setSelectedNodeLabelState(labelShown) { function setSelectedNodeLabelState(labelShown) {
if (RED.workspaces.isActiveLocked()) { if (RED.workspaces.isLocked()) {
return return
} }
var selection = RED.view.selection(); var selection = RED.view.selection();
@ -448,7 +448,7 @@ RED.view.tools = (function() {
} }
function alignSelectionToEdge(direction) { function alignSelectionToEdge(direction) {
// if (RED.workspaces.isActiveLocked()) { // if (RED.workspaces.isLocked()) {
// return // return
// } // }
var selection = RED.view.selection(); var selection = RED.view.selection();
@ -552,7 +552,7 @@ RED.view.tools = (function() {
} }
function distributeSelection(direction) { function distributeSelection(direction) {
if (RED.workspaces.isActiveLocked()) { if (RED.workspaces.isLocked()) {
return return
} }
var selection = RED.view.selection(); var selection = RED.view.selection();
@ -713,7 +713,7 @@ RED.view.tools = (function() {
} }
function reorderSelection(dir) { function reorderSelection(dir) {
if (RED.workspaces.isActiveLocked()) { if (RED.workspaces.isLocked()) {
return return
} }
var selection = RED.view.selection(); var selection = RED.view.selection();
@ -752,7 +752,7 @@ RED.view.tools = (function() {
} }
function wireSeriesOfNodes() { function wireSeriesOfNodes() {
if (RED.workspaces.isActiveLocked()) { if (RED.workspaces.isLocked()) {
return return
} }
var selection = RED.view.selection(); var selection = RED.view.selection();
@ -795,7 +795,7 @@ RED.view.tools = (function() {
} }
function wireNodeToMultiple() { function wireNodeToMultiple() {
if (RED.workspaces.isActiveLocked()) { if (RED.workspaces.isLocked()) {
return return
} }
var selection = RED.view.selection(); var selection = RED.view.selection();
@ -841,7 +841,7 @@ RED.view.tools = (function() {
} }
function wireMultipleToNode() { function wireMultipleToNode() {
if (RED.workspaces.isActiveLocked()) { if (RED.workspaces.isLocked()) {
return return
} }
var selection = RED.view.selection(); var selection = RED.view.selection();
@ -903,7 +903,7 @@ RED.view.tools = (function() {
* @param {Object || Object[]} wires The wire(s) to split and replace with link-out, link-in nodes. * @param {Object || Object[]} wires The wire(s) to split and replace with link-out, link-in nodes.
*/ */
function splitWiresWithLinkNodes(wires) { function splitWiresWithLinkNodes(wires) {
if (RED.workspaces.isActiveLocked()) { if (RED.workspaces.isLocked()) {
return return
} }
let wiresToSplit = wires || (RED.view.selection().links && RED.view.selection().links.filter(e => !e.link)); let wiresToSplit = wires || (RED.view.selection().links && RED.view.selection().links.filter(e => !e.link));
@ -1074,7 +1074,7 @@ RED.view.tools = (function() {
* @param {{ renameBlank: boolean, renameClash: boolean, generateHistory: boolean }} options Possible options are `renameBlank`, `renameClash` and `generateHistory` * @param {{ renameBlank: boolean, renameClash: boolean, generateHistory: boolean }} options Possible options are `renameBlank`, `renameClash` and `generateHistory`
*/ */
function generateNodeNames(node, options) { function generateNodeNames(node, options) {
if (RED.workspaces.isActiveLocked()) { if (RED.workspaces.isLocked()) {
return return
} }
options = Object.assign({ options = Object.assign({
@ -1147,7 +1147,7 @@ RED.view.tools = (function() {
} }
function addJunctionsToWires(wires) { function addJunctionsToWires(wires) {
if (RED.workspaces.isActiveLocked()) { if (RED.workspaces.isLocked()) {
return return
} }
let wiresToSplit = wires || (RED.view.selection().links && RED.view.selection().links.filter(e => !e.link)); let wiresToSplit = wires || (RED.view.selection().links && RED.view.selection().links.filter(e => !e.link));

View File

@ -671,7 +671,7 @@ RED.view = (function() {
RED.actions.add("core:copy-selection-to-internal-clipboard",copySelection); RED.actions.add("core:copy-selection-to-internal-clipboard",copySelection);
RED.actions.add("core:cut-selection-to-internal-clipboard",function(){copySelection(true);deleteSelection();}); RED.actions.add("core:cut-selection-to-internal-clipboard",function(){copySelection(true);deleteSelection();});
RED.actions.add("core:paste-from-internal-clipboard",function(){ RED.actions.add("core:paste-from-internal-clipboard",function(){
if (RED.workspaces.isActiveLocked()) { if (RED.workspaces.isLocked()) {
return return
} }
importNodes(clipboard,{generateIds: clipboardSource === 'copy', generateDefaultNames: clipboardSource === 'copy'}); importNodes(clipboard,{generateIds: clipboardSource === 'copy', generateDefaultNames: clipboardSource === 'copy'});
@ -2549,7 +2549,7 @@ RED.view = (function() {
} }
function editSelection() { function editSelection() {
if (RED.workspaces.isActiveLocked()) { return } if (RED.workspaces.isLocked()) { return }
if (movingSet.length() > 0) { if (movingSet.length() > 0) {
var node = movingSet.get(0).n; var node = movingSet.get(0).n;
if (node.type === "subflow") { if (node.type === "subflow") {
@ -2883,7 +2883,7 @@ RED.view = (function() {
function detachSelectedNodes() { function detachSelectedNodes() {
if (RED.workspaces.isActiveLocked()) { return } if (RED.workspaces.isLocked()) { return }
var selection = RED.view.selection(); var selection = RED.view.selection();
if (selection.nodes) { if (selection.nodes) {
const {newLinks, removedLinks} = RED.nodes.detachNodes(selection.nodes); const {newLinks, removedLinks} = RED.nodes.detachNodes(selection.nodes);
@ -3465,7 +3465,7 @@ RED.view = (function() {
} }
if (dblClickPrimed && mousedown_node == d && clickElapsed > 0 && clickElapsed < dblClickInterval) { if (dblClickPrimed && mousedown_node == d && clickElapsed > 0 && clickElapsed < dblClickInterval) {
mouse_mode = RED.state.DEFAULT; mouse_mode = RED.state.DEFAULT;
if (RED.workspaces.isActiveLocked()) { if (RED.workspaces.isLocked()) {
clickElapsed = 0; clickElapsed = 0;
d3.event.stopPropagation(); d3.event.stopPropagation();
return return
@ -4009,7 +4009,7 @@ RED.view = (function() {
if (RED.view.DEBUG) { if (RED.view.DEBUG) {
console.warn("groupMouseUp", { mouse_mode, event: d3.event }); console.warn("groupMouseUp", { mouse_mode, event: d3.event });
} }
if (RED.workspaces.isActiveLocked()) { return } if (RED.workspaces.isLocked()) { return }
if (dblClickPrimed && mousedown_group == g && clickElapsed > 0 && clickElapsed < dblClickInterval) { if (dblClickPrimed && mousedown_group == g && clickElapsed > 0 && clickElapsed < dblClickInterval) {
mouse_mode = RED.state.DEFAULT; mouse_mode = RED.state.DEFAULT;
RED.editor.editGroup(g); RED.editor.editGroup(g);
@ -4233,7 +4233,7 @@ RED.view = (function() {
function showTouchMenu(obj,pos) { function showTouchMenu(obj,pos) {
var mdn = mousedown_node; var mdn = mousedown_node;
var options = []; var options = [];
const isActiveLocked = RED.workspaces.isActiveLocked() const isActiveLocked = RED.workspaces.isLocked()
options.push({name:"delete",disabled:(isActiveLocked || movingSet.length()===0 && selectedLinks.length() === 0),onselect:function() {deleteSelection();}}); options.push({name:"delete",disabled:(isActiveLocked || movingSet.length()===0 && selectedLinks.length() === 0),onselect:function() {deleteSelection();}});
options.push({name:"cut",disabled:(isActiveLocked || movingSet.length()===0),onselect:function() {copySelection(true);deleteSelection();}}); options.push({name:"cut",disabled:(isActiveLocked || movingSet.length()===0),onselect:function() {copySelection(true);deleteSelection();}});
options.push({name:"copy",disabled:(isActiveLocked || movingSet.length()===0),onselect:function() {copySelection();}}); options.push({name:"copy",disabled:(isActiveLocked || movingSet.length()===0),onselect:function() {copySelection();}});

View File

@ -160,7 +160,7 @@ RED.workspaces = (function() {
} }
}); });
let isCurrentLocked = RED.workspaces.isActiveLocked() let isCurrentLocked = RED.workspaces.isLocked()
if (tab) { if (tab) {
isCurrentLocked = tab.locked isCurrentLocked = tab.locked
} }
@ -833,8 +833,9 @@ RED.workspaces = (function() {
active: function() { active: function() {
return activeWorkspace return activeWorkspace
}, },
isActiveLocked: function() { isLocked: function(id) {
var ws = RED.nodes.workspace(activeWorkspace) || RED.nodes.subflow(activeWorkspace) id = id || activeWorkspace
var ws = RED.nodes.workspace(id) || RED.nodes.subflow(id)
return ws && ws.locked return ws && ws.locked
}, },
selection: function() { selection: function() {