Closed ghost closed 6 years ago
When you re-open the editor again, should all files get restored or just those "unsaved" ones?
Hi Martin, yes, all of them should get restored - saved and unsaved ones.
OK
How should the option be switched, would be simple checkbox "Restore previous session" in "General" settings dialog enough?
Yes, an option in the General settings would be great because other people may not want to have the session restored.
Please test, new release incoming.
Yep that's it, well done! But I did find a bug. Once TT has launched, if you try to close an unsaved tab from the previous session, it does not ask you to save it and it should because the tab is unsaved. If you however modify the tab, it does ask you to save it (as expected) so what should TT do is set the "modified" flag to true by default for each unsaved tab that gets restored from the previous session. I hope you know what I mean.
And finally, TT should activate the same tab that was active when TT got closed. For example, if you have 10 tabs opened and tab 5 is currently active, when restoring the previous session on start up, TT should activate that same tab -- so in other words, you resume working on the very same tab that you were working before TT got closed. This is how other certain editors behave.
If you do implement this, One thing to keep in mind however is this. Before activating that tab, check the index of the tab that's about to get activated and make sure that the index is less than the total number of tabs previously opened otherwise you know what will happen - you'll run into a segfault - index out of bounds.
This could happen for instance if you have closed a tab with an actual file on disk but the file has been deleted and in that case the total number of tabs to open will be less than the previous time and if the index of tab to activate is greater and you don't do a check, well, you know what will happen, "index out of bounds". In that case, you can just launch the index of the last opened tab - 1 (just make sure it's not less than 0th index).
I see, just fixing the "modified" state of temp session documents when they get restored.
One more note: current implementation DOES NOT save/restore EMPTY documents (those without "file"). Also, it does not save/restore undo/redo stack (history of changes) within the documents.
Ok no problems Martin, I wasn't aware of that.
Should empty documents get save/restored too? Does it make sense?
No, they shouldn't.
More notes: Settings of restore session are not inter-operable across platforms and are kept separatedly. So you can have different set of files restored on Linux and on Windows (this is because file paths are not easily convertible across platforms).
That make sense.
Should empty documents get save/restored too? Does it make sense?
I decided to even save/restore empty documents, and my reasoning is simple, I sometimes use set of temporary documents to note different kinds of texts, for example:
So I have three documents all the time. If one of them is empty, then I know that I have those things sorted out and move to next one.
Moreover, if user has restoring enabled, it would make sense for me that restoring/saving of session should just restore all tabs, it could be misleading for someone who expects to have 5 tabs after restoration when he had 5 tabs on exit.
Hope it will be okay for you. It will also make implementation bit easier and less error prone and it can be adjusted in the future if needed.
EDIT: Moreover, Sublime Text also restores empty documents by default.
Correct tab now should be automatically reactivated upon session restoration.
Releasing new version...
Yep that's fine with me, thanks, this is a very useful feature.
I agree with your aforementioned reasoning, sounds logical.
I am happy with the fact that you are willing to work along with the community. Many people will appreciate it.
Yes, thanks for feedback. Pls, let me know if this feature completely works (all tabs restored, correct tab selected after restoration). :)
Spot on! I am testing it right now and so far it's holding strong. It even detects when the file gets modified outside TT which is something I just thought of that other editors do. Very impressive so far. Keep up!
Restore Previous Session
Would it be possible to add a - "Restore Previous Session" feature? For instance, with some other editors, you can create 5 new tabs (unsaved files) and you can close the editor without being asked whether you want to save the newly created non-existing files (tabs) and that's because it auto-saves them to a temporary folder in the $HOME dir and then the next time you launch the editor, it will reopen them restoring the last session.
If you have any other files loaded from disk however, if modified, it will ask you to save them before exiting and the next time the editor opens up, it will restore the session reopening the files.
You've developed a great editor but I believe this feature is very neat to have. Some other editors do have it but yours has some features that other editors don't. Keep up the good work...