Steps to reproduce: 1. With no project open, open some files 2. Open project A 3. Without closing project A first, open project B 4. Close project B 5. The originally open files from (1) are gone
The problem is that when project A closes and all its files are closed, load_config() gets called which contains
configuration_save_default_session();
This saves the session with all files closed and replaces the original session.
This patch modifies the code to call configuration_save_default_session() only when there are some open tabs so the above problem gets solved.
Even though I was worried that this would break saving default session when all its files get closed and then a project is loaded, it doesn't seem to be the case (I haven't investigated deep enough why).
An alternative to this approach would be to pass a boolean as a parameter of quite many functions and propagate the information whether project close preceded its opening but it introduces a much bigger diff and makes the complicated session opening stuff even wilder.
Fixes #3897. You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany/pull/3898
-- Commit Summary --
* Fix a problem when multiple project opens clear the default session
-- File Changes --
M src/project.c (3)
-- Patch Links --
https://github.com/geany/geany/pull/3898.patch https://github.com/geany/geany/pull/3898.diff
LGBI
@techee pushed 1 commit.
6c1fdf6f8e78512bd43ba2e84169f0321979eebf Add an explanation comment
Even though I was worried that this would break saving default session when all its files get closed and then a project is loaded, it doesn't seem to be the case (I haven't investigated deep enough why).
The reason why this doesn't happen is the default ``` save_config_on_file_change=TRUE ``` When disabled, the problem happens. I.e.: 1. With project closed, open some files. 2. Restart Geany to make sure the files from (1) are stored in the default session 3. Close all of the open files 4. Open a project 5. Close the project 6. The open files from (1) are restored but, instead, there should be no open files because of (3)
So this patch is trading one problem for another, but IMO still worth it because the second problem is much more rare.
Even though I suggested passing some boolean in the description above, this affects several session management functions at various places and makes the already complicated code even worse so I'd prefer the slightly buggy approach from this PR.
In the future, I think the best solution would be rewriting the session management from scratch, moving it to a separate file and making sure its API would abstract-away the callers from details of what state the session is in.
Maybe the session should be saved before opening a project (at step 2 in the OP or step 4 above) so the right thing can be restored after?
Maybe the session should be saved before opening a project (at step 2 in the OP or step 4 above) so the right thing can be restored after?
The trouble with this session management code is that it gets called from many different places and on different occasions so the "before opening project" place is e.g. at - `recent_project_activate_cb()` in `ui_utils.c` - or at `run_open_dialog()` in `project.c`
and then you'd have to add big fat comments regarding why you are placing the saving there and not in project opening itself. Also, this would lead to a double-save for sessions where you don't close all files before loading a project.
As I said, I think the whole session management should be rewritten but that's a major task.
Although on thinking about it, why wasn't the session saved at step 3 above?
Notice what this patch does for project opens: ```C if (have_session_docs()) // <-- the patch adds this check configuration_save_default_session(); ``` This is called in two cases: 1. The currently buggy case - `open project session -> open project session` transition where the current code saves the empty session after closing the first project. 2. The currently non-buggy case `default session -> open project session` where the default session really doesn't contain any file and you want to save the "no open file" state. This patch breaks it.
Note that (2) will break only for the case when both of these conditions are satisfied: 1. `save_config_on_file_change` is disabled (which is not by default) 2. Only when in step (3) from my previous post you close all of the files - if you keep at least one file open, it gets saved
Since I think this behavior is much less problematic than losing the whole session and it is rather hard to trigger, I think it's an acceptable workaround until someone decides to rewrite the session management code from scratch.
If there are no objections, I'd merge this PR in about a week.
I believe the very special case where this patch doesn't save the empty session (which only happens with non-default Various preferences) outweighs the current situation where the default session is lost after 2 project opens.
Merged #3898 into master.
github-comments@lists.geany.org