From aa28c91c5503435a6c57e0ef6c3ab4f76edf1d12 Mon Sep 17 00:00:00 2001 From: Nakul Date: Sun, 23 Nov 2025 22:17:47 +0530 Subject: [PATCH] Removing Save toolbar button --- src/disablesave.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/disablesave.ts b/src/disablesave.ts index 2221051..b2dff0b 100644 --- a/src/disablesave.ts +++ b/src/disablesave.ts @@ -111,6 +111,40 @@ export const disableSavePlugin: JupyterFrontEndPlugin = { } }); + /** + * Remove save buttons from toolbar + */ + const removeSaveButtons = () => { + const widgets = app.shell.widgets('main'); + + for (const widget of widgets) { + const toolbar = (widget as any)?.toolbar; + if (!toolbar?.node) { + continue; + } + + const selector = + `[data-command="${SAVE_COMMANDS.save}"],` + + `[data-command="${SAVE_COMMANDS.saveAs}"],` + + `[data-command="${SAVE_COMMANDS.saveAll}"]`; + + toolbar.node + .querySelectorAll(selector) + .forEach((button: { remove: () => void }) => { + button.remove(); + }); + } + }; + + setTimeout(() => removeSaveButtons(), 100); + + const labShell = app.shell as any; + if (labShell.currentChanged) { + labShell.currentChanged.connect(() => { + requestAnimationFrame(() => removeSaveButtons()); + }); + } + console.log('Full autosave enabled, save commands disabled'); }); }