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

Ask to save the file before closing the tab #280

Closed
vyshnav-vinod opened this issue Apr 8, 2024 · 2 comments · Fixed by #289
Closed

Ask to save the file before closing the tab #280

vyshnav-vinod opened this issue Apr 8, 2024 · 2 comments · Fixed by #289
Assignees
Labels
enhancement New feature or request file management good first issue good for newcomers text editor Related to text editor's features

Comments

@vyshnav-vinod
Copy link
Contributor

Feature

Describe the feature, can also add images

When the user closes the tab, it would be helpful if biscuit asked to save the file. It would be also good to maybe find a way to show if a file has been saved or not. Like in VScode, if the file is not saved, there will be a white circle instead of the close sign in the tab.

@vyshnav-vinod vyshnav-vinod added the enhancement New feature or request label Apr 8, 2024
@tomlin7 tomlin7 added text editor Related to text editor's features file management good first issue good for newcomers labels Apr 8, 2024
@vyshnav-vinod
Copy link
Contributor Author

Ok i tried working on this, but cant quite figure out how to check if the file contents have been changed or not ( So we can show the save dialog). @billyeatcookies

@tomlin7
Copy link
Owner

tomlin7 commented Apr 12, 2024

@vyshnav-vinod thanks for working on the issue!

I think a good approach would be to calculate the initial hash of file when it was opened and then store it, then on next save/close, recalculate hash for content in editor and try to match it with initial.

def calculate_hash(self):
    content = self.get("1.0", "end-1c")
    return hashlib.md5(content.encode()).hexdigest()

If the hashes are equal, that means there are no changes. Otherwise if they mismatch, show the dialog. And if the user accepts on saving, then we can set initial hash to be the newly calculated one.

Comparing the giant strings is the only way i see here. And using hashlib it could be slightly better mayhaps.

Try to make a function on GUIManager level too that is bound to whole app destroyed event.

self.protocol("WM_DELETE_WINDOW", self.on_close)

And trigger the editor level function to show dialog (only if editor.content and editor.content.editable).

vyshnav-vinod added a commit to vyshnav-vinod/biscuit that referenced this issue Apr 12, 2024
vyshnav-vinod added a commit to vyshnav-vinod/biscuit that referenced this issue Apr 12, 2024
Remove unnecessary comments
tomlin7 added a commit that referenced this issue Apr 13, 2024
…shnav-vinod/feat/ask-save-before-close (nightly)

feat: Ask user to save the file before they close the tab #280
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request file management good first issue good for newcomers text editor Related to text editor's features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants