Help with file recovery service in KWrite: how to open and show windows

I’m trying to implement the #1 thing I miss from Atom/Pulsar: file recovery. I lost count of the number of times that saved me when my laptop unexpectedly froze, so I’d really like to see it added to KWrite.

I don’t know much about contributing to KDE, but so far, what I’ve done is: start a timer in KateDocManager that runs every 30 seconds that serializes every open document to a JSON file in QStandardPaths::StateLocation. When the user clicks a button “Reopen Last Session” on the welcome screen, KateViewManage calls a method in KateDocManager that reads the JSON file and creates new documents using createDoc and setText when there is no URL (unsaved files) and openUrl when there is, then calls KateViewManager::activateView on the last document created using this method.

The JSON part works (though there might be problems if there’s more than one open window), but after activateView is called, all that’s shown is a blank screen with none of the files.

Any suggestions? I’d really love to not have to worry about losing my work.

I’m quite sure there is such thing in Kate as recovery and since kwrite is now just a special Kate “profile” kwrite should have it too.

Examining the kwrite settings this should already working: In the settings Open/Save → Advanced there is a settings for swap files. Is this enabled for you?

I checked and it is enabled. When I close and reopen KWrite, every file I had open is closed and I have to reopen them one at a time.

The functionality is used in order to restore any unsaved changes in file in case of abnormal termination (ie if it crashes). When that happens, and you try to open the last file it will show you a message saying that you can recover the unsaved data.

If you want to be able to have the files you were working last time open automatically, you have to use kate and create a session. I don’t think it’s possible to do it in kwrite,

As jsalatas mentioned this is another feature, we can call it as session restore, and since kwrite is aimed to be a simple text editor I think it is intentionally lacking this feature.

Is there any particular reason you don’t want to use Kate? Plugins can be enabled on per session based, so you can mimic kwrite by creating a new session and disable every plugin in that session. You can start you specific session using the -s CLI switch.