CSSG-Labs / PyNote

Text Editor Written in Python
GNU General Public License v3.0
3 stars 4 forks source link

Prompt user to save at quit #17

Closed PatrickBruso closed 2 years ago

PatrickBruso commented 2 years ago

We need to update the application so that it will prompt the user to save if there is unsaved work when the user quits the program. If the user does want to save, then the text should be saved (either via "Save" or "Save as"). Otherwise, the text should be deleted and the program ended.

AdamLaine commented 2 years ago

@PatrickBruso This one is quite a complex issue due to the number of different cases and will require some stuff done also in other fields. Logically I'm thinking of 2 prompts appearing on different occasions:

  1. The text was changed and not saved, thus options will be "Save", "Don't save", "Cancel"
  2. The text was changed and saved, thus options will be "Quit", "Cancel", for example I'm still thinking (there're several options), but text changing trigger may require creating a custom Text class like this one (https://code.activestate.com/recipes/464635-call-a-callback-when-a-tkintertext-is-modified/ however I'll try to find or adapt something newer than 2005). The custom class though seems huge should not be that much of a problem - the problem, yet, arises with the save as I will require some flag/trigger that the file was already saved, so this issue starts depending on the #15 . Tell me what do you think
PatrickBruso commented 2 years ago

@SamReiCooper I agree, and see my response to your comment in the CustomPrompt issue thread. I think the trigger would be whether a file was opened. Basically, if a file was opened, you will want to save the new/updated text to that same file location. Otherwise, if a file was not opened (meaning the text was added to the initial "new" text box or the user created a "new" text box using the "new" command) then we will want to prompt with the "save as" function to create the file location.

I was going to add a global variable that is referenced by the "Open" function that would save the file location of a file that is opened. That way, whenever we check to save or save as, the program would see if a file location is already available. If so, it would use the save function. If not, it would use save as.

AdamLaine commented 2 years ago

@PatrickBruso I will await the custom prompt acknowledge and after that implement this issue, using an empty save function (later can be changed), i.e.: def save(self): pass

PatrickBruso commented 2 years ago

@SamReiCooper I think this issue can now be completed using the CustomPrompt class and will act as an example of how to use that class that can then be replicated with the "New", "Open", "Save", etc. functions.

AdamLaine commented 2 years ago

Provided that the PR was approved and merged I think this issue can be closed