plugin-cross-tab-copy-paste
Check for duplicates
- [X] I have searched for similar issues before opening a new one.
Component
plugin-cross-tab-copy-paste
Description
Hi everybody,
I have used the plugin-cross-tab-copy-paste plugin for the first time, and it works very well. Very useful plugin!
However in our application we create a new workspace when we show the old workspace in full screen. When we do that now, the following exceptions is raised. All my other plugins have no issue, but they all have a dispose function that does the cleanup of all stuff. However the plugin-cross-tab-copy-paste plugin does 't offer such a function...
Thanks! Bart
Reproduction steps
- Call ´Blockly.inject´
- Initialize the plugin:
node.copyPastePlugin = new CrossTabCopyPaste(); node.copyPastePlugin.init(copyPastePluginOptions, function() { //console.log('Use this error callback to handle TypeError while pasting'); }); - For all other plugins I call now their
disposefunction, but this plugin doesn' t have it... - Call ´Blockly.inject´ again. Now an exception occurs
Stack trace
Uncaught Error: Menu item with ID "blockCopyToStorage" is already registered.
at ContextMenuRegistry$$module$build$src$core$contextmenu_registry.register (contextmenu_registry.ts:45:13)
at t.blockCopyToStorageContextMenu (index.js:90:5)
at t.init (index.js:33:12)
at createWorkspace (<anonymous>:455:34)
at Object.open (<anonymous>:918:29)
at n (red.min.js?v=:19:44660)
at red.min.js?v=:19:45794
Screenshots
No response
does it work if you call Blockly.ContextMenuRegistry.registry.unregister('blockCopyToStorage'); in place of plugin.dispose()
Hi @alicialics,
Thanks for joining (again)!
-
In some circumstances I arrive at the cleanup part before the plugins have been initialized, and then your statement results into this:
Uncaught Error: Menu item with ID "blockCopyToStorage" not found. at ContextMenuRegistry$$module$build$src$core$contextmenu_registry.unregister (contextmenu_registry.ts:58:17) at cleanup_plugins (<anonymous>:549:50) at createWorkspace (<anonymous>:369:9) at lastScriptToLoad.onload (<anonymous>:217:13)Which can be resolved by checking first if the context menu item has already been registered.
-
Beside the blockCopyToStorage menu item, there is also a blockPasteFromStorage menu item. Which needs the same treatement.
As a result, the following code snippet seems to do the job for me:
if (Blockly.ContextMenuRegistry.registry.getItem("blockCopyToStorage")) {
Blockly.ContextMenuRegistry.registry.unregister('blockCopyToStorage');
}
if (Blockly.ContextMenuRegistry.registry.getItem("blockPasteFromStorage")) {
Blockly.ContextMenuRegistry.registry.unregister('blockPasteFromStorage');
}
So a dispose function with that would be sufficient...
BTW I am not familiar with Typescript. Is there perhaps somewhere a description of how to contribute something like this (e.g. how to generate the javascript...)?
Enjoy your weekend! Bart
Thanks Bart! =)
The typescript declarations are fairly straightforward I think, you can a new function declaration here:
dispose(): void;
I took a look at CrossTabCopyPaste and suspect that it doesn't have dispose because having one meant that it might need to cleanup these shortcuts