Fixing Bug 416137 - "Close other" option automatically saves session. Unable to restore previous state
I took a further peek at https://bugs.kde.org/show_bug.cgi?id=416137
and whipped up a patch (as attached) patch-for-416137-no-autosave-session-on-close-4-prompt-anon-w-debugs-CLEAN.diff. It seems the autosave was being triggered by all sorts of unexpected actions. Hopefully this patch resolves (most of) it.
Current limitations:
- renaming a file via the context menu you get when right clicking on the filetree does not mark the doclist as changed (I couldn't figure out how to do that -- KateViewSpace::showContextMenu? KateFileTree::slotRenameFile? All that is needed is to successfully call KateApp::self()->documentManager()->setSessionChanged()). Using the file menu at the top to rename does work as intended/expected.
- katesessionmanager.cpp, someone needs to check if this won't close some non-active session without saving (is that a thing? I don't know the kate codebase well, I just hacked this thing together)
bool KateSessionManager::activateSession(KateSession::Ptr session, const bool closeAndSaveLast, const bool loadNew)
{
[...]
if (closeAndSaveLast) {
if (KateApp::self()->activeKateMainWindow()) { // HERE
- In bool KateMainWindow::promptIfUnsavedActiveSession() the call is made to * KateApp::self()->sessionManager()->sessionSave()*, which uses KateSessionManager::saveActiveSession(), but without setting rememberAsLast. Someone needs to check if that is a problem.
I'm not sure what the workflow for kate is to submit patches (merge requests?) but @cullmann advised me in https://phabricator.kde.org/D27180 to use invent.kde.org instead of phabricator. Can someone let me know what the proper way to do it is? I'm guessing just attaching a patch here is not it. Having the instructions in an open issue might be helpful for further newbies wanting to help provide patches and fixes. (Posting the patch on phabricator is just so trivially easy.)
How to test the patch:
Try different combinations of opening a (new) session, closing the window, opening (or closing) a file from the session, and navigating the prompts that appear. Opening a "New" (ie, empty) session, followed by opening a file, should prompt you for a name to save the session as when you choose to save. The patch in theory should prevent you from losing changes in a session, or unknowingly overwriting a session, whether at the moment of closing a window or launching a new/different session.