Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/disablesave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,40 @@ export const disableSavePlugin: JupyterFrontEndPlugin<void> = {
}
});

/**
* 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');
});
}
Expand Down