Skip to content

Conversation

@jitseniesen
Copy link
Member

Monitor in Spyder whether a notebook has been edited after the last save. If that is the case, then put an * (asterisk) after the filename in the title of the tab and enable the Save action. This brings the behaviour of the Notebook pane in line with the Editor pane.

To implement this, we need a communication channel between the notebook JavaScript (which sends a signal if a notebook has unsaved changes) and Spyder itself. This PR uses the JavaScript alert() function as the communication channel. If the message in the alert starts with a specific prefix (namely, :SpyderComm:), then this is interpreted as a message for Spyder and not for the user. This is perhaps a bit hacky (not using alert for what it is meant for), but it is easy to implement and I don't see a real disadvantage. The alternative would be to first open a channel to the notebook server (perhaps using Qt WebChannel) and then have the notebook server communicate with Spyder (perhaps using zeromq). I envisage that the new communication channel will have further uses.

The video below shows the new behaviour implemented in this PR: after editing the notebook, an * appears in the tab bar and the Save action is enabled; after saving, the * disappears and the Save action is disabled.

dirty.mp4

@jitseniesen jitseniesen added this to the v0.7.2 milestone Nov 8, 2025
@jitseniesen jitseniesen self-assigned this Nov 8, 2025
Connect to the JavaScript signal emitted when a notebook becomes
dirty or non-dirty. On receiving this signal, call alert() with
a specially crafted message. Monitor alerts in Spyder and on
receiving such an alert, emit a Qt signal.

Using alert() as a side channel to communicate messages from
JavaScript to Spyder is perhaps a bit hacky but it is simple and
it works (as long as the alert message does not occur naturally).
I expect that this mechanism is more widely applicable.
If a notebook is dirty (meaning that it has been changed since
the last save), then add an asterix `*` to the file name in the
title of the tab. This mirrors the behaviour of the editor.
Enable the File > Save menu item and the Save button in the Spyder
toolbar only if there the current notebook is dirty (i.e., if there
is something to save).

Enable the Save All action only if any notebook is dirty. If the
user triggers this action, then only save notebooks that are dirty.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant