Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added modified file tracking and unsaved change #393

Merged

Conversation

Drachenkaetzchen
Copy link
Contributor

This PR implements a configurable confirmation dialog if unsaved changes would be discarded in the editor. This PR also implements a config option to prevent ESC to close the editor.

Added Features

  • File Changed Indicator (the well-known Asterisk *)
  • Confirmation dialog if the user attempts to close the editor with unsaved changes with the following options
    • Cancel to continue editing
    • Don't save to close the editor without saving the changes
    • Save & Close to close the editor and saving the changes (same as in the top bar)
    • Save & Restart if the config file affects a restartable service (same as in the top bar)
  • Confirmation dialog can be disabled to make the system behave like in previous versions
  • ESC key can be disabled to prevent accidental closing of the editor

Implementation Notes

  • This PR calculates a hash of the loaded file to compare it against the actual editor content to reliably show if the content has been edited or not.
    • The used editor only fires an event if the content has been changed, but this doesn't allow the PR to check if that change has been reverted
    • Example: If the user types an a, the editor would fire the "changed" event. If the user now deletes the a, the editor would fire the "changed" event again, and the file would be shown as changed, even though the change was reverted.
  • Because the used editor always uses Unix-style newlines, even if the original file has Windows-style newlines, the file would immediately be shown as changed. Due to that, the PR converts all newlines to Unix-style newlines prior the hash calculation.
  • The hash calculation is reasonably fast for small files (1-2ms at a file size of 50kb), but significantly slows down with huge G-Code files (2 seconds for 60MB of G-Code). However, even without the hash calculation the editor is slow with huge G-Code files, so this shouldn't matter too much.
  • The default settings are:
    • [x] Use ESC to close editor
    • [x] Prompt to save or discard unsaved changes
    • The reason behind the defaults is to have new users benefit from the "Prompt unsaved changes" dialog, whilst users preferring not to be nagged by the dialog can turn it off. If the default was to disable the "Prompt unsaved changes" dialog, new users would not be aware of this feature and potentially loosing their changes by accident.

Screenshots

image
image

dialog on unsaved changes. This can be disabled
if the user wishes to do so.

Also allows the user to configure if the editor can be
closed by hitting the "ESC" key.
@Drachenkaetzchen Drachenkaetzchen changed the title Added modified file tracking and unsaved change feat: Added modified file tracking and unsaved change Oct 26, 2021
@meteyou meteyou merged commit 0a0c456 into mainsail-crew:develop Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants