tomboy-notes / tomboy-ng

Next generation of Tomboy
MIT License
389 stars 38 forks source link

Backup old note on rename #209

Closed dajoker closed 3 years ago

dajoker commented 4 years ago

openSUSE Leap 15.1 (x86_64) KDE tomboy-ng 0.30 (GTK2)

The lack of an undo (Ctrl+z) is a pretty big omission, in my opinion, and as a result (due to a set of contributing factors) I have, on multiple occasions, lost an entire note's worth of contents. Since I keep track of my day's work in a note, that's a problem depending on when it happens; today it happened at the very end of my work day (the last time was just an hour into the day).

This happens when I cannot tell where I am currently (blame Citrix doing really stupid things with my open windows) and my attempting to change "screens" (screen command) using Ctrl+a followed by a number, or something like that. Ctrl+a in tomboy-ng, of course, tells the UI to select all, thus the next keystroke causes all data to be removed. The new note now takes on the name of this new thing, and all data are gone forever due to the lack of an undo. Since my client does not let me stop using Citrix in order to do work for them, I am stuck with the likely problem of losing my data due to Citrix putting my cursor in tomboy-ng when I thin kit is actually in a Putty window.

To work around this, I would like anytime a note is renamed (meaning the first line is changed, happening after my Ctrl+a-anything catastrophe) for the old note to be backed up, as if it had been deleted, because it has just been effectively deleted. This is probably a pretty small change, but it would be a huge benefit for me since I cannot jut Ctrl+z and undo the mess easily.

Please? For 0.31? My alternative to losing a day's worth of data is to not use the tool, and other than this one feature I think it's a great utility, and I know that adding the undo feature is something you have described as a major overhaul.

davidbannon commented 4 years ago

Yeah, I would really like an Undo but its just too hard to do a conventional layered Ctrl-Z. But maybe you have a good idea there, create a backup file if the title changes. Not too hard, not too obtrusive.

I have also been thinking about a 'revert' command, it would just reverse the last change if the last change involved replacing a block of selected text. I have found myself in that position, selected a large section of a note, hit Ctrl-C to copy, missed the ctrl key and replaced all the text with 'c'. No fun.

So, I will look into both approaches.

Thanks...

Davo

netlore commented 4 years ago

I've always felt the risk of this even with the original tomboy... for myself it would be sufficient to back up the note when it is opened for editing, so that it could be reverted to the state it was when it was opened (as per :e! in VI), but for the issue referred to by OP, I guess it could be time based while the note is open?

davidbannon commented 4 years ago

Because notes are auto saved, the vi like model would not work, one particular note may well be saved every 10 seconds while its being actively edited. I understand dakoker's suggestion is to use the existing backup mechanism if the title changes. Its actually a pretty good idea, low impact. Backups are normally only made when a note is deleted or overwritten by the sync process. Importantly, I don't have to intercept keystrokes, auto save is timer driven, at the next autosave, I can see if title changed and if so, do it differently. That won't help if you have selected everything except the title before hitting that errant key. But the snapshot mechanism will give you an earlier version of the current file of of course. Hmm...

davidbannon commented 4 years ago

OK, so further thinking about this says that dajoker and netlore's ideas are more practical than mine. I understand netlore's idea as "make a new backup of a note at opening". The approaches are compatible and relatively low impact.

While making the backup's are relatively easy alerting the user to the fact they have been made, and allowing him/her to recover them is harder. So, thinking out loud -

I will add a button to the editnote window "revert", it will popup a dialog with -

This note has unsaved content, please choose

This will not solve all cases, if you have a note open for weeks on end (I do) its "On Opening" backup is grossly out of date and if you select all of a note except its Title and overwrite that, sorry, its gone. But between the two paths, we may cover a significant proportion of the likely problems ?

I will save both types of backup notes in the same place as existing Delete/Overwrite notes but with slightly mangled file names. So they will be also accessible via the existing recover lost notes pathway. Only downside I see is even more (probably unused) content in the Backup directory. But diskspace is mostly cheap. In both cases, overwrite an existing similar backup, its not a stack. You can only go back one level. I think I can make a reversion reversible, that is, you can keep reverting, toggling between two copies. That may allow copying content from one to another.

Would appreciate your thoughts .... Davo

netlore commented 4 years ago

Are you sure that "This note has unsaved content," is what you mean... obviously you mentioned that notes are saved every 10 seconds... perhaps the options should be something like "This note can be reverted", or something similar?

dajoker commented 4 years ago

I think overall the plan sounds good. I do not (and I doubt many disagree) worry about the space of notes generally; years and years of notes of mine, and now with 5000+ built up I'm only using 50 MiB of space. If I have space issues because of infrequent backups, then I have bigger problems.

Just as a side note, in the past I've nearly lost entire notes for this same reason, but happily found (by accident) that if I deleted the entire note's contents before it saved, then it would not save at all. I'm just telling you this as an odd case that may or may not be known/expected, but which has saved me a couple times when I lost the entire note via Ctrl+a + something.

Other possible thing to consider: Generally I do not modify many of my notes, though I open them every day (they have information I need for filling out this form or that document), so if I get a copy of one of those each time it's going to create a lot of identical copies. That's okay with me, but then again maybe something you could do for these backups is have them keep their original UUID/GUID-based name, but append a checksum of the file, e.g. ff0e50c3-69ed-46ae-92e7-f3107156f26.note becomes ff0e50c3-69ed-46ae-92e7-f3107156f26f-md5-d0fceefffdc4013be501c495951c37fe.note or something like that. The result is that, if you open the same note and close it again, you end up with the exact same checksum, and either you can opt to skip the backup (already there) or write it again (no worries, it's the same exact data). I realize metadata may cause a change when there is no substantial change (e.g. cursor position, selection, x/y positioning on screen, etc.) but that's fine with me.

While investigating the possibility of that above it looks like even opening/closing a note causes its timestamp to change in the filesystem, which is interesting/odd, but the checksum does not change unless you change something more substantial than just opening/closing.

Thanks for your thoughts on this; it is very encouraging.

davidbannon commented 4 years ago

Are you sure that "This note has unsaved content," is what you mean... obviously you mentioned that notes are saved every 10 seconds... perhaps the options should be something like "This note can be reverted", or something similar?

You are correct. My first draft of that message had an option to close the note without saving. However, if on reopening, it was found to be missing important content, it would be too late to revert back to the "on open backup". I could workaround that but UI stuff that is too complicated is worse than useless. So, I dropped that option.

(I did warn I was thinking out loud :-) )

dajoker - thats a clever trick, yes, it would work that way but entirely unintentional on my part. Just good luck.

Using checksum would work but I don't think its that important, as you say, disk is cheap, I think I'd rather save the processing time.

Thanks for the input.

Davo

davidbannon commented 4 years ago

Ok, here it is working, In this example, its currently 14:20 or twenty minutes past two. I have loaded a note, made some changes and then, decided to copy its content. So, I pressed Ctrl-A, C - yep, 'C' not Ctrl-C, so, the single letter c overwrote my whole note. I clicked the Roll Back button, and this screen is shown.

RollBack

If I now click 'Opening Backup' I will get the note from before I opened it, I did make some changes earlier in the day, seven minutes past midday. The 'Title Change Backup' on the other hand, with a very recent time, will give me back the note that existed immediately before my Ctrl-A, C sequence.

You can toggle backwards and forwards between versions although I strongly recommend against mixed toggling between the two backups, the outcome is quite predictable but not immediately obvious IHMO. I cannot prevent a user doing so, I cannot determine their intentions !

Comments welcome.

Incidentally, this may help a little but does not resolve the following #107 #97 #96 and #35

Davo

davidbannon commented 3 years ago

OK, this is provided in the just released v0.31 Thanks for the report. Davo

dajoker commented 3 years ago

Upgraded and exactly one test tried so far and it works as advertised where a Ctrl+a followed by Ctrl+x or any other character renames the note and a backup is now allowed. Once reverting, re-reverting is also functional. This will save me from the worst kinds of problems at least, so thank-you very much for implementing it.