Bug 416137 - "Close other" option automatically saves session. Unable to restore previous state
Summary: "Close other" option automatically saves session. Unable to restore previous ...
Status: RESOLVED INTENTIONAL
Alias: None
Product: kate
Classification: Applications
Component: application (show other bugs)
Version: Git
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-11 20:13 UTC by Raphael Rosch
Modified: 2023-02-18 18:34 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
patch to prevent autosave on close (618 bytes, patch)
2020-01-12 04:14 UTC, Raphael Rosch
Details
prevent autosave when user clicks on "Quit" option in file menu (1.06 KB, patch)
2020-01-12 04:50 UTC, Raphael Rosch
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Raphael Rosch 2020-01-11 20:13:06 UTC
SUMMARY
I mistakenly clicked on the "close other" context menu item on a big project session which closed (many) other open documents, and since there is no "undo" button for the action, I closed the window and tried to relaunch the session again, only to find out it had been automatically saved after the "close other" action.

STEPS TO REPRODUCE
1. [Back up the session you wish to test this on]
2. Open session with multiple open files
3. Switch to "tree mode" in "view mode" context menu
4. Right click on a file in a directory with multiple files, and click on "close other"
5. Close the window, without saving the session
6. Relaunch kate with the session

OBSERVED RESULT

Session has automatically been overwritten with the results of the "Close other" action

EXPECTED RESULT

No auto-overwriting of session.


SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Fedora Core 30, 
KDE Frameworks 5.64.0
Qt 5.12.5 (built against 5.12.5)
Kate: Version 18.12.2, and git master as of 2020 January 11

ADDITIONAL INFORMATION

If we are auto-saving in case of a crash, we should auto-save to a special "autosave" session, not the current session, which otherwise requires manual saving (the expected behavior).


If a dev that knows where the fix could go but has no time to fix it themselves wants to point me in the right direction to fixing this, I could try to see if I can do it myself.
Comment 1 Raphael Rosch 2020-01-12 03:21:23 UTC
Further testing reveals that the problem isn't with the "close other" feature, but rather that closing the session triggers its automatic save
( KateSessionManager::saveActiveSession -> KateSessionManager::saveSessionTo ), which is a departure from how it used to handle the situation.  

kate should not overwrite the current session when closing the application, but instead, if an autosave is desired (optimally, this should be a user-selectable option) it should save to a designated /different/ file (say, "autobak.katesession") or to a "backup" copy of the session (ie, if using "my session", it should create a "my session-autobak" session or something like that).

I'm going to see if I can whip up a quick patch, if at least for those who want a parting point to work on this.
Comment 2 Raphael Rosch 2020-01-12 04:14:01 UTC
Created attachment 125049 [details]
patch to prevent autosave on close

The following patch prevents autosave on close. I don't know if it breaks anything else, but this is what I will personally be using to solve the problem for me until a config option is created for this. (I don't think I will be able to devote time to that at any time soon, unfortunately). Hope this is useful as-is to somebody else too.
Comment 3 Raphael Rosch 2020-01-12 04:50:15 UTC
Created attachment 125050 [details]
prevent autosave when user clicks on "Quit" option in file menu

Second patch. This one also prevents the autosave when the user clicks on the "Quit" option in the file menu.
Comment 4 Dominik Haumann 2020-01-14 20:49:52 UTC
Is it that with these patches one always has to save manually?
Comment 5 Raphael Rosch 2020-01-15 00:54:28 UTC
(In reply to Dominik Haumann from comment #4)
> Is it that with these patches one always has to save manually?

Yes. Which is how it used to be, at least for me. Optimally a configuration option to select autosave should be coded for those who want it to work that way. For me, I make mistakes often, and I would rather not have those mistakes irretrievably autosaved. It would also be quite good to have an "undo close file" but that's probably an even bigger undertaking than the config option. Even a prompt before closing that asks if you want to save the session before closing would be good (with it's own config option too, for those who don't want to have to click one more thing before closing).

The patches at least help pinpoint the two places where a dev can start looking into the solution for this.
Comment 6 Raphael Rosch 2020-02-29 06:17:11 UTC
Patch submitted to: https://invent.kde.org/kde/kate/issues/8
Comment 7 Christoph Cullmann 2020-03-02 19:21:24 UTC
Hmm, I am not sure if that behavior change is wanted.

Was there ever a time when the session wasn't saved automatically?

If we add such a change, that should be a configure option like "auto save session", that is default "on"

For the patch submission: It is better to create a merge request at invent.kde.org, having there a second issue with an attached patch is just confusing ;=)

I closed the issue there.
Comment 8 Raphael Rosch 2020-03-31 00:05:03 UTC
I'm not sure if was ever not automatically saved, given my workflow, but the way it is now is destructive (and a nasty shock the first time I realized it had happened to me), as there is no way to retrieve a previous session state if you make an unintended action which changes it (like "close all" for example). 

I don't think a default of "on" on that eventual config option would be the best, since we should opt to be non-destructive by default. But yes, I do agree a config option would be good to have.

I will try to submit the merge request as soon as I can. Thanks for looking into this.
Comment 9 Justin Zobel 2020-10-30 02:40:30 UTC
Raphael are you still working on this patch on invent.kde.org?
Comment 10 Raphael Rosch 2020-10-30 10:59:48 UTC
Hi Justin, I got busied up with other things, I'll give the code another look and see if I can submit a merge request in the coming weeks. Thanks for the bump. Let me know if you have any suggestions for this, if they are simple enough I'll try my best to include them.
Comment 11 Justin Zobel 2020-10-30 22:50:53 UTC
(In reply to Raphael Rosch from comment #10)
> Hi Justin, I got busied up with other things, I'll give the code another
> look and see if I can submit a merge request in the coming weeks. Thanks for
> the bump. Let me know if you have any suggestions for this, if they are
> simple enough I'll try my best to include them.

No suggestions from me, but thank you for taking the time to improve KDE :)
Comment 12 Justin Zobel 2020-10-30 22:51:33 UTC
Raphael working on a patch.
Comment 13 Christoph Cullmann 2022-01-09 12:33:56 UTC
Hi, as said, I think the current behavior is wanted, but if we can have an option to disable auto-saving completely, that would be fine for me.

For new contributions, please take a look at:

https://kate-editor.org/post/2020/2020-07-18-contributing-via-gitlab-merge-requests/
Comment 14 Christoph Cullmann 2023-02-18 18:34:03 UTC
With https://invent.kde.org/utilities/kate/-/merge_requests/1115 this is even more often auto-saved.

I still think the current behavior is sane, if somebody wants to have this optional, please provide a patch.