Hello,
export const changeRenderer = (app: BlocklyApplicationType, renderNew: string = (document.getElementById('rendererMenu') as HTMLSelectElement).value): string => {
app.WORKSPACE_OPTIONS['renderer'] = renderNew;
workspaceReboot(app);
window.history.pushState({}, "µcB", addReplaceParamToUrl(window.location.search, "renderer", renderNew));
return renderNew;
}
WORKSPACE_OPTIONS = {
grid:
{
spacing: 20,
length: 3,
colour: '#ccc',
snap: true
},
scrollbars: true,
toolbox: µcB.toolbox,
zoom:
{
controls: true,
wheel: true,
startScale: 1.0,
maxScale: 6,
minScale: 0.1,
scaleSpeed: 1.2,
pinch: true
},
trashcan: true,
}
export const workspaceReboot = (app: BlocklyApplicationType): void => {
workspaceSaveBlocks(app.workspace, 'mainWorkspace_blocks');
workspaceSetupPlugins(app.workspace, true);
app.workspace.dispose();
app.workspace = Blockly.inject(div_workspace_content_blockly, app.WORKSPACE_OPTIONS);
workspaceSetupPlugins(app.workspace, false);
workspaceLoadBlocks(app.workspace, 'mainWorkspace_blocks');
(app.workspace as Blockly.WorkspaceSvg).scrollCenter();
}
export const workspaceSaveBlocks = function(workspace: Blockly.Workspace, storageKeyWorkspaceBlocks: string) {
const data = Blockly.serialization.workspaces.save(workspace);
window.sessionStorage?.setItem(storageKeyWorkspaceBlocks, JSON.stringify(data));
};
export const workspaceLoadBlocks = function(workspace: Blockly.Workspace, storageKeyWorkspaceBlocks: string) {
const data = window.sessionStorage?.getItem(storageKeyWorkspaceBlocks);
if (!data) return;
// Don't emit events during loading.
Blockly.Events.disable();
Blockly.serialization.workspaces.load(JSON.parse(data), workspace);
Blockly.Events.enable();
};
const plugin_KeyboardNav = new NavigationController();
let plugin_contentHighlight = new ContentHighlight();
let plugin_minimap = new PositionedMinimap();
let plugin_modal = new Modal();
let plugin_workspaceSearch = new WorkspaceSearch();
let plugin_zoomToFit = new ZoomToFitControl();
export const workspaceSetupPlugins = (workspace: Blockly.Workspace, disposePlugin: boolean = false): void => {
const backpackOptions = {
allowEmptyBackpackOpen: true,
useFilledBackpackImage: true,
skipSerializerRegistration: false,
contextMenu: {
emptyBackpack: true,
removeFromBackpack: true,
copyToBackpack: true,
copyAllToBackpack: true,
pasteAllToBackpack: true,
disablePreconditionChecks: true,
},
};
const plugin_backpack = new Backpack(workspace as Blockly.WorkspaceSvg, backpackOptions);
plugin_contentHighlight = new ContentHighlight(workspace);
plugin_modal = new Modal(workspace);
plugin_workspaceSearch = new WorkspaceSearch(workspace);
plugin_zoomToFit = new ZoomToFitControl(workspace);
const pluginHighlightCheck = <HTMLInputElement>document.getElementById('pluginHighlight');
const pluginMinimap = <HTMLInputElement>document.getElementById('pluginMinimap');
if (disposePlugin) {
µcB.workspace.addChangeListener(shadowBlockConversionChangeListener);
plugin_KeyboardNav.dispose();
plugin_backpack.dispose();
if (pluginHighlightCheck.checked) {
plugin_contentHighlight.dispose();
pluginHighlightCheck.checked = false;
}
plugin_minimap.dispose();
pluginMinimap.checked = false;
plugin_modal.dispose();
plugin_workspaceSearch.dispose();
plugin_zoomToFit.dispose();
} else {
µcB.workspace.removeChangeListener(shadowBlockConversionChangeListener);
plugin_KeyboardNav.init();
plugin_KeyboardNav.addWorkspace(workspace);
plugin_backpack.init();
if (pluginHighlightCheck.checked) {
plugin_contentHighlight.init();
}
//particular to this plugin
plugin_minimap = new PositionedMinimap(workspace);
plugin_minimap.init();
pluginMinimap.checked = true;
plugin_modal.init();
plugin_workspaceSearch.init();
plugin_zoomToFit.init();
}
/* it seems there's conflict with nav keyboard copy function
const options = {
contextMenu: true,
shortcut: true
}
const crossTabCopyPastePlugin = new CrossTabCopyPaste();
crossTabCopyPastePlugin.init(options);*/
}
I hope it could help understand why I did.