PhonologicalCorpusTools / SLPAA

5 stars 0 forks source link

Unsaved changes warning + save_as bugs #228

Closed stannam closed 12 months ago

stannam commented 1 year ago

This PR does two things: 1. adds unsaved changes warning, and 2. fixes two save_as bugs.

1. unsaved changes warning #210

I modified check_unsaved_change(), which is the decorator that prompts a warning for any unsaved changes. A warning message appears if a Boolean self.unsaved_changes is True. It has three buttons each for discarding, saving and cancelling.

image

The flag unsaved_changes starts as False, (line 77)

https://github.com/PhonologicalCorpusTools/SLPAA/blob/2058c94daec4532c11c06835e07c2f467d400f05/src/main/python/gui/main_window.py#L68-L77

... and gets valued True whenever the sign_updated signal is emitted, i.e., after any change in the sign.

https://github.com/PhonologicalCorpusTools/SLPAA/blob/2058c94daec4532c11c06835e07c2f467d400f05/src/main/python/gui/panel.py#L767-L768

https://github.com/PhonologicalCorpusTools/SLPAA/blob/2058c94daec4532c11c06835e07c2f467d400f05/src/main/python/gui/main_window.py#L310

Specifically, a new function flag_and_refresh below flags unsaved_changes.

https://github.com/PhonologicalCorpusTools/SLPAA/blob/2058c94daec4532c11c06835e07c2f467d400f05/src/main/python/gui/main_window.py#L935-L939

Saving (or saving as...) unflags unsaved_changes. Cf. lines 823 and 842, respectively.

https://github.com/PhonologicalCorpusTools/SLPAA/blob/2058c94daec4532c11c06835e07c2f467d400f05/src/main/python/gui/main_window.py#L794-L824

https://github.com/PhonologicalCorpusTools/SLPAA/blob/2058c94daec4532c11c06835e07c2f467d400f05/src/main/python/gui/main_window.py#L826-L843

Finally, in check_unsaved_change, a warning message appears if self.unsaved_change:

https://github.com/PhonologicalCorpusTools/SLPAA/blob/2058c94daec4532c11c06835e07c2f467d400f05/src/main/python/gui/decorator.py#L11-L42

//

2. fixing two save_as bugs #53 #140

While working on the decorator, I noticed the decorator check_unsaved_corpus is wrongly called when 'save as.' Simply removing the decorator solved the two bugs.

Commit 4f551f64a41b84d86a7b49c4b4941999b239ce0e removed the decorator and added some comments to the decorator to help developers understand what it does and when it is called.

stannam commented 1 year ago

@kvesik Thanks for the review Kaili. Now, both issues are solved.

Issue #210 Previously deleting a sign did not emit sign_changed Signal, which in turn did not flag unsaved_changes. Now deleting a sign also flags it.

As for the unwanted 'unsaved changes' warning, the reason was that I didn't refresh unsaved_changes when loading a corpus. This resulted in the program 'not forgetting' the changes in the previous corpus. Now, loading or creating a corpus gets unsaved_changes back to False.

Issue #140 It was an easy fix. Now, if the user cancels on the save as dialog, the program does not save the corpus.

stannam commented 12 months ago

Thanks for the review, Kaili!