diff --git a/src/XircuitsFactory.ts b/src/XircuitsFactory.ts index f1b1c909..61b46a24 100644 --- a/src/XircuitsFactory.ts +++ b/src/XircuitsFactory.ts @@ -49,6 +49,7 @@ export class XircuitsFactory extends ABCWidgetFactory { runXircuitSignal: Signal; runTypeXircuitSignal: Signal; lockNodeSignal: Signal; + triggerCanvasUpdateSignal: Signal; triggerLoadingAnimationSignal: Signal; reloadAllNodesSignal: Signal; toggleAllLinkAnimationSignal: Signal; @@ -68,6 +69,7 @@ export class XircuitsFactory extends ABCWidgetFactory { this.runXircuitSignal = new Signal(this); this.runTypeXircuitSignal = new Signal(this); this.lockNodeSignal = new Signal(this); + this.triggerCanvasUpdateSignal = new Signal(this); this.triggerLoadingAnimationSignal = new Signal(this); this.reloadAllNodesSignal = new Signal(this); this.toggleAllLinkAnimationSignal = new Signal(this); @@ -90,6 +92,7 @@ export class XircuitsFactory extends ABCWidgetFactory { runXircuitSignal: this.runXircuitSignal, runTypeXircuitSignal: this.runTypeXircuitSignal, lockNodeSignal: this.lockNodeSignal, + triggerCanvasUpdateSignal: this.triggerCanvasUpdateSignal, triggerLoadingAnimationSignal: this.triggerLoadingAnimationSignal, reloadAllNodesSignal: this.reloadAllNodesSignal, toggleAllLinkAnimationSignal: this.toggleAllLinkAnimationSignal, diff --git a/src/XircuitsWidget.tsx b/src/XircuitsWidget.tsx index 04e334d0..cce694ec 100644 --- a/src/XircuitsWidget.tsx +++ b/src/XircuitsWidget.tsx @@ -24,6 +24,7 @@ export class XircuitsPanel extends ReactWidget { runXircuitSignal: Signal; runTypeXircuitSignal: Signal; lockNodeSignal: Signal; + triggerCanvasUpdateSignal: Signal; triggerLoadingAnimationSignal: Signal; reloadAllNodesSignal: Signal; toggleAllLinkAnimationSignal: Signal; @@ -45,6 +46,7 @@ export class XircuitsPanel extends ReactWidget { this.runXircuitSignal = options.runXircuitSignal; this.runTypeXircuitSignal = options.runTypeXircuitSignal; this.lockNodeSignal = options.lockNodeSignal; + this.triggerCanvasUpdateSignal = options.triggerCanvasUpdateSignal; this.triggerLoadingAnimationSignal = options.triggerLoadingAnimationSignal; this.reloadAllNodesSignal = options.reloadAllNodesSignal; this.toggleAllLinkAnimationSignal = options.toggleAllLinkAnimationSignal; @@ -97,6 +99,7 @@ export class XircuitsPanel extends ReactWidget { runXircuitSignal={this.runXircuitSignal} runTypeXircuitSignal={this.runTypeXircuitSignal} lockNodeSignal={this.lockNodeSignal} + triggerCanvasUpdateSignal={this.triggerCanvasUpdateSignal} triggerLoadingAnimationSignal={this.triggerLoadingAnimationSignal} reloadAllNodesSignal={this.reloadAllNodesSignal} toggleAllLinkAnimationSignal={this.toggleAllLinkAnimationSignal} diff --git a/src/commands/CommandIDs.tsx b/src/commands/CommandIDs.tsx index 76064c16..dd5fecc2 100644 --- a/src/commands/CommandIDs.tsx +++ b/src/commands/CommandIDs.tsx @@ -19,6 +19,7 @@ export const commandIDs = { attachNode: "Xircuit-editor:attach-node", attachAllNodes: "Xircuit-editor:attach-all-nodes", detachAllNodes: "Xircuit-editor:detach-all-nodes", + triggerCanvasUpdate: "Xircuit-editor:trigger-canvas-update", triggerLoadingAnimation: "Xircuit-editor:trigger-loading-animation", reloadNode: "Xircuit-editor:reload-node", reloadAllNodes: "Xircuit-editor:reload-all-nodes", diff --git a/src/commands/NodeActionCommands.tsx b/src/commands/NodeActionCommands.tsx index abe7365c..4dbb1f0e 100644 --- a/src/commands/NodeActionCommands.tsx +++ b/src/commands/NodeActionCommands.tsx @@ -1011,9 +1011,11 @@ export function addNodeActionCommands( node.getOptions().extras.attached = true; let parameterOutPort = node.getOutPorts()[0] as CustomPortModel; let connectedNodes = parameterOutPort.getTargetNodes(); - connectedNodes.forEach((node: CustomNodeModel) => node.setSelected(true)) + connectedNodes.forEach((node: CustomNodeModel) => node.setSelected(true)); + }); widget.xircuitsApp.getDiagramEngine().repaintCanvas(); + widget.triggerCanvasUpdateSignal.emit(null); }, label: trans.__('attach node') }); @@ -1044,10 +1046,11 @@ export function addNodeActionCommands( literal_nodes.forEach(node => { let parameterOutPort = node.getOutPorts()[0] as CustomPortModel; let connectedNodes = parameterOutPort.getTargetNodes(); - connectedNodes.forEach((node: CustomNodeModel) => node.setSelected(true)) + connectedNodes.forEach((node: CustomNodeModel) => node.setSelected(true)); }); widget.xircuitsApp.getDiagramEngine().repaintCanvas(); + widget.triggerCanvasUpdateSignal.emit(null); }, label: trans.__('attach all nodes') }); @@ -1078,10 +1081,11 @@ export function addNodeActionCommands( literal_nodes.forEach(node => { let parameterOutPort = node.getOutPorts()[0] as CustomPortModel; let connectedNodes = parameterOutPort.getTargetNodes(); - connectedNodes.forEach((node: CustomNodeModel) => node.setSelected(true)) + connectedNodes.forEach((node: CustomNodeModel) => node.setSelected(true)); }); widget.xircuitsApp.getDiagramEngine().repaintCanvas(); + widget.triggerCanvasUpdateSignal.emit(null); }, label: trans.__('detach all nodes') }); diff --git a/src/components/XircuitsBodyWidget.tsx b/src/components/XircuitsBodyWidget.tsx index 033dd3a2..a700917e 100644 --- a/src/components/XircuitsBodyWidget.tsx +++ b/src/components/XircuitsBodyWidget.tsx @@ -50,6 +50,7 @@ export interface BodyWidgetProps { runXircuitSignal: Signal; runTypeXircuitSignal: Signal; lockNodeSignal: Signal; + triggerCanvasUpdateSignal: Signal; triggerLoadingAnimationSignal: Signal; reloadAllNodesSignal: Signal; toggleAllLinkAnimationSignal: Signal; @@ -88,6 +89,7 @@ export const BodyWidget: FC = ({ runXircuitSignal, runTypeXircuitSignal, lockNodeSignal, + triggerCanvasUpdateSignal, triggerLoadingAnimationSignal, reloadAllNodesSignal, toggleAllLinkAnimationSignal, @@ -660,6 +662,12 @@ export const BodyWidget: FC = ({ } }); } + const handleTriggerCanvasUpdate = async () => { + if (shell.currentWidget?.id !== widgetId) { + return; + } + onChange(); + }; const handleReloadAll = async () => { if (shell.currentWidget?.id !== widgetId) { @@ -868,6 +876,7 @@ export const BodyWidget: FC = ({ [runXircuitSignal, handleRunClick], [fetchRemoteRunConfigSignal, getRemoteRunTypeFromConfig], [lockNodeSignal, handleLockClick], + [triggerCanvasUpdateSignal, handleTriggerCanvasUpdate], [triggerLoadingAnimationSignal, triggerLoadingAnimation], [reloadAllNodesSignal, handleReloadAll], [toggleAllLinkAnimationSignal, handleToggleAllLinkAnimation], diff --git a/src/context-menu/CanvasContextMenu.tsx b/src/context-menu/CanvasContextMenu.tsx index 2b9749ae..7d70e4c4 100644 --- a/src/context-menu/CanvasContextMenu.tsx +++ b/src/context-menu/CanvasContextMenu.tsx @@ -33,17 +33,14 @@ export class CanvasContextMenu extends React.Component { const handleAttachNode = async () => { await this.props.app.commands.execute(commandIDs.attachNode); - await this.props.app.commands.execute(commandIDs.reloadNode); }; const handleAllAttachNodes = async () => { await this.props.app.commands.execute(commandIDs.attachAllNodes); - await this.props.app.commands.execute(commandIDs.reloadNode); }; const handleDetachAllNodes = async () => { await this.props.app.commands.execute(commandIDs.detachAllNodes); - await this.props.app.commands.execute(commandIDs.reloadNode); }; return ( diff --git a/src/index.tsx b/src/index.tsx index b52f804b..c7ea763e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -178,8 +178,10 @@ const xircuits: JupyterFrontEndPlugin = { {execute: emitSignal(widgetFactory.compileXircuitSignal)}], [commandIDs.fetchRemoteRunConfig, {execute: emitSignal(widgetFactory.fetchRemoteRunConfigSignal)}], - [commandIDs.lockXircuit, + [commandIDs.lockXircuit, {execute: emitSignal(widgetFactory.lockNodeSignal)}], + [commandIDs.triggerCanvasUpdate, + {execute: emitSignal(widgetFactory.triggerCanvasUpdateSignal)}], [commandIDs.triggerLoadingAnimation, {execute: emitSignal(widgetFactory.triggerLoadingAnimationSignal)}], [commandIDs.reloadAllNodes,