CSSG-Labs / PyNote

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

Text update flag #28

Closed AdamLaine closed 2 years ago

AdamLaine commented 2 years ago

Ok, fellas, I think I might have an idea, of how to resolve some of our other issues. As I said earlier in #17 #16 and in some other we may require a flag that the text was updated. I already sent some link of 2005 on that issue, now I have a proposition, though I am hesitant as this proposition doubles the memory usage of the program: We use t = self.text.get("1.0", "end") to get the text out of the text box in a lot of functions. What if we have a variable saved_t which will contain the already previously saved text and each time we need to do something (like open, new) we check if (t = self.text.get("1.0", "end") == saved_t), thus if they are our flag_text_changed is False otherwise True, so proceed with the necessary action. I would like to hear your opinion if it is a good idea (even temporarily until a better solution). If yes, I'll quickly implement it

PatrickBruso commented 2 years ago

Hi @SamReiCooper I think that's a good idea and was something I was also considering. I added in a file_location global variable that will save the file_location of a file that is opened in the program. My purpose with that was to tie in the file_location plus another variable like what you mentioned above so that we can determine if changes are made and then also know where to save the changes upon prompt. I'm not too worried about memory usage currently, and I think we can implement this feature and then optimize the code later on.

Also, we do have a discord for discussing ideas that you're welcome to join. There's a link in the README.

PatrickBruso commented 2 years ago

Upon further thought, we may not always need to save the text. For instance, a text box that is initiated via the "New" command will always need to be saved (unless we want to check if there's no text, and not bother to prompt a save in that situation). So, in that case, we're only really needing to check for changes if a file is opened, or if a file is saved after it's created. This may be able to help narrow down the situations in which we need to save the text and those in which we don't.

Another potential solution is just to prompt for save upon exit, no matter what. I know some editors that do this, even if no changes were made. It's a bit bothersome for the user, however.

PatrickBruso commented 2 years ago

Closed by PR #29