Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore opened files between application restarts #264

Merged
merged 11 commits into from
Dec 31, 2022
Merged

Conversation

dail8859
Copy link
Owner

@dail8859 dail8859 commented Nov 10, 2022

This is a first attempt at saving/loading a user's session between application restarts.

This feature is not enabled by default. This needs enabled through the preferences dialog.

This feature does not currently save temporary files (that will come later). This base functionality is needed before temporary files can be properly saved/loaded.

TODO:

  • Make sure new files don't get named the same as existing files. E.g. since New 1 can be loaded from the session, File > New would then also create New 1
  • Allow to files with the same name to be stored in the session. C:\dir1\test.txt and C:\dir2\test.txt both get saved as text.txt and will overwite each other.
  • Remove commented out code

Calling this from outside the class does not give the proper results. The currently focused editor in the DockManger gets out of sync with the rest of the GUI
- Renamed settings
- Move logic out of EditorManager that always required it to handle every possible use case
- Added temporary flag to ScintillaNext so that it can show as unsaved even when it is unedited (e.g. modify() == true)
- Properly handle when it is unsaved
- Overhaul SessionManager logic
- SessionManager determines if a file needs saved before closing
Renaming and add better preferences (kind of)
@mikelupe
Copy link

Very nice, will be my daily driver - thanks for your efforts.

One situation ("bug"):
0. Fresh start, no sessions apart "New 1"

  1. "New 1" > type some text > "Save as.." test.txt
  2. Double click to create a new tab > "New 1" > type some text > close NotepadNext w/o saving
  3. Relaunch NotepadNext ; State: one tab "test.txt" (red with content), one tab "New 1" (red with content)
  4. Again double click to create a new tab > "New 1" (blue empty)
  5. On close and reopen, only the last "New 1" is kept, the original "New 1" (red) is ~overwritten

Basically: As long as a "New X" tab hasn't been saved, the next increment of new still is "New X", so no increment :)
I hope it's reproducable

kind regards

@dail8859
Copy link
Owner Author

@mikelupe Thanks for testing it out!

  1. "New 1" > type some text > "Save as.." test.txt
  2. Double click to create a new tab > "New 1" > type some text > close NotepadNext w/o saving

Just to make sure, in step 2 wouldn't it be "New 2" since the "New 1" document was already saved?


But yes this is one of the bugs, that you can't have two files with the same name currently. A couple points to this:

  • If New 2 (or any other temp file for that matter) is loaded, then a new tab (e.g. File > New) should never be named that, so some logic would need added to keep incrementing the number in the name until one is found that doesn't exist.
  • The same thing will happen if you have C:\dir1\test.txt and C:\dir2\test.txt since they both tried to get saved in the session folder both as test.txt. I've got an idea to fix this.

@mikelupe
Copy link

mikelupe commented Dec 28, 2022

Just to make sure, in step 2 wouldn't it be "New 2" since the "New 1" document was already saved?

It is again "New 1", as the old "New 1" previously had been saved as "test.txt" in step 1

Thanks again for your effort, this will be epic :)

This allows files with the same name to be stored in the session without overwriting one another.
@mikelupe
Copy link

I checked your latest commit:

I had to remove the rm ~/.config/NotepadNext/NotepadNext.ini , otherwise I got a segfault :)

Unfortunately now it generates a "New 2" but then later on again another "New 2". Almost there

@dail8859
Copy link
Owner Author

otherwise I got a segfault :)

Yeah that makes sense, but would indicate some better error handling is needed incase the settings file gets modified or corrupted.

Unfortunately now it generates a "New 2" but then later on again another "New 2". Almost there

Yep the root issue was fixed so that even if you have two New 2 temp files they won't overwrite each other. Still need to fix the file name incrementing to prevent this.

Just curious since you are on a non-Windows machine, where exactly does it save the session files too? I'm assuming something like ~/.config/NotepadNext/NotepadNext/session/? I've only tested it on Windows.

@mikelupe
Copy link

I see, nice.

Re location - I had to find it first :) It saves it to "~/.local/share/NotepadNext/NotepadNext/session/" . so $HOME/.local/...

@dail8859
Copy link
Owner Author

It saves it to "~/.local/share/NotepadNext/NotepadNext/session/" . so $HOME/.local/...

Hmmm, ok. The Qt documentation for standard paths is a bit fuzzy, so it saved to a semi-sane location on Windows but didn't know what that would look like on other systems.

@mikelupe
Copy link

mikelupe commented Dec 28, 2022

I think that's quite legit. ~/.config/NotepadNext/session/ would be ok as well. Eventually a config setting with the recent defaults could make sense.

But at the end of the day ~/.local/share/.. is ok, as it's nothing a user would ever like to move to another machine :)

edit: or rather: "It can be totally irrelevant to the user".

@mikelupe
Copy link

Nice

@dail8859 dail8859 marked this pull request as ready for review December 29, 2022 13:12
@mikelupe
Copy link

Thanks for your speedy work, and for the mention :) The latest build is becoming my driver.

There is one thing though, double clicking generates incremented "New X", but if closed w/o saving, on a new creation it still increments - so create "New 2" > close "New 2", create a new one gives "New 3" > close w/o saving > create a new one gives "New 4" etc.

Would it be easy to check on this, even if it's not really a show-stopper? It would make it even more consistent.

@dail8859
Copy link
Owner Author

There is one thing though, double clicking generates incremented "New X", but if closed w/o saving, on a new creation it still increments - so create "New 2" > close "New 2", create a new one gives "New 3" > close w/o saving > create a new one gives "New 4" etc.

This is actually a preexisting bug (not sure if this PR made it worse or not) but even in the official v0.5.6 release I can recreate it by:

  1. Start a fresh instance, which just contains New 1
  2. File > New creates New 2
  3. File > Close All closes files and creates New 3
  4. Repeat step 3, creates New 4 etc.

This was one of the bugs I ran across and thought I introduced it with these changes but there is at least some not-desirable behavior that already exists. Appreciate you testing things and providing feedback!

@mikelupe
Copy link

Let's be frank, It's not really a bug, maybe just some polishing.

Something else, would a dark mode be a lot of work? But this would extend it over original Notepad++'s features.

Thanks again for your work

@dail8859
Copy link
Owner Author

Let's be frank, It's not really a bug, maybe just some polishing.

Agreed

Something else, would a dark mode be a lot of work?

Yes and no. Getting something basic is easy, to really polish it would probably take a bit of time. There may be existing 3rd party dark theme css files that would work well but I haven't tested them. You can load custom css files: see #171 (comment)

Not something I'll be working on myself any time soon.

There are other non-Windows systems that have Qt theming built-in so it carries over to Notepad Next: #109 (comment)

@mikelupe
Copy link

Thanks for the hint.

As it's mainly about the editor background that would need to be dark, I'll be waiting. There really is no hurry.

@dail8859 dail8859 linked an issue Dec 31, 2022 that may be closed by this pull request
@dail8859 dail8859 merged commit ee8021f into master Dec 31, 2022
@dail8859 dail8859 deleted the restore-session branch December 31, 2022 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Close without saving modified files
3 participants