This PR stops Geany from trying to reopen a project file that is already open. This eliminates unnecessary warnings and processing. You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany/pull/2951
-- Commit Summary --
* <a href="https://github.com/geany/geany/pull/2951/commits/910cfe3b1642773e5e655288612cdeec53f78562">Don't reopen project that is already open</a>
-- File Changes --
M src/socket.c (9)
-- Patch Links --
https://github.com/geany/geany/pull/2951.patch https://github.com/geany/geany/pull/2951.diff
@elextr requested changes on this pull request.
Is this needed? What are the downsides of reloading projects? Also does reloading a project have useful semantics that this would block, I'm not sure?
If this is desired it should be applied to UI activated opening as well, by doing this in the project open code, not socket code.
Also technically it should be comparing `realpath`ed absolute filenames so it won't refuse to load projects of the same name in different directories.
@@ -631,8 +631,13 @@ static void handle_input_filename(const gchar *buf)
{ if (g_str_has_suffix(locale_filename, ".geany")) { - if (project_ask_close()) - main_load_project_from_command_line(locale_filename, TRUE); + /* Don't open project when it is already opened */ + if (!app->project || !(g_strcmp0(app->project->file_name, locale_filename) == 0
Do you need to compare to the locale filename? IIUC the `project->file_name` has to be UTF-8 or GTK display will be broken, so just compare to UTF-8 filename.
Is this needed?
Yes.
What are the downsides of reloading projects?
* Popup to warn about closing project – waste time closing popup. * Geany doesn't take focus when it creates popups – waste time switching to Geany when it would otherwise take focus. * Popups to save unsaved files – more wasted time. And they're annoying. * Lost undo history.
Also does reloading a project have useful semantics that this would block, I'm not sure?
Nothing useful. It creates lots of popups and destroys undo history. Because of the popups, it's faster to reopen a project by closing and rerunning Geany itself.
If this is desired it should be applied to UI activated opening as well, by doing this in the project open code, not socket code.
I made the change here because that is where the function to generate the popup is called. That function does not receive the new project file name, so cannot make a comparison.
When a project is opened from the menu, no warning is generated. So even if the project were prevented from being opened elsewhere, the change here would still be necessary to prevent the warning dialog from being shown.
Also technically it should be comparing realpathed absolute filenames so it won't refuse to load projects of the same name in different directories.
`app->project->file_name` contains the full path. The [`GeanyProject`](https://www.geany.org/manual/reference/structGeanyProject.html) struct does not appear to have a `real_path` component.
@xiota commented on this pull request.
@@ -631,8 +631,13 @@ static void handle_input_filename(const gchar *buf)
{ if (g_str_has_suffix(locale_filename, ".geany")) { - if (project_ask_close()) - main_load_project_from_command_line(locale_filename, TRUE); + /* Don't open project when it is already opened */ + if (!app->project || !(g_strcmp0(app->project->file_name, locale_filename) == 0
I wanted to make extra sure that the open project would be left alone.
I'll make this change you've suggested, and also look for where to disable opening the project from the menu, as you suggested in another comment.
Popup to warn about closing project – waste time closing popup.
#2949 means you can avoid this if you don't want it :smile:
Geany doesn't take focus when it creates popups – waste time switching to Geany when it would otherwise take focus.
IIRC all Geany popups are marked modal, so they should take focus, but it is up to the window manager/wayland compositor to grant that. Seems to work here with Cinnamon.
Nothing useful.
Ok, but project load does cause a signal that plugins might use, do the project plugins do rescans or other stuff when that happens.
When a project is opened from the menu, no warning is generated.
Oh, Ok, well no need to add one then, coulda sworn it did, but maybe its been removed, maybe github search knows ... ahh, it used to for a "recent project" open, but that was removed in https://github.com/geany/geany/commit/f40569d1c327af162726dbab14a78fd83ca5e0....
The GeanyProject struct does not appear to have a real_path component.
Yeah, I said "technically", but absolute should be fine most of the time to distinguish two files of the same name in differing directories, only getting confused for smarties with multiple paths to the same file, but in that case its no different to the current situation, so no need for real_path.
app->project->file_name contains the full path.
Do you get an absolute path from the socket buffer then?
BTW I am not saying this PR is a bad idea, just want to be sure the implementation has no negative side effects.
@xiota pushed 2 commits.
99ab5895262dfbb8e0d21c1fdd721076d77119a4 Don't reopen project that is already open 8d2e8ad3062e39b55c2681c5290498ee3c4cdedc Prevent already-open project from being re-opened from Project menu
@xiota pushed 1 commit.
95f5a8bfd911a73598386fcb77f1a30f3fd1b76d Use realpath to compare project filename
#2949 means you can avoid this if you don't want it smile
Haha... yes...
IIRC all Geany popups are marked modal, so they should take focus, but it is up to the window manager/wayland compositor to grant that. Seems to work here with Cinnamon.
It's probably focus stealing prevention... But I prefer no popups in the first place.
Ok, but project load does cause a signal that plugins might use, do the project plugins do rescans or other stuff when that happens.
Since the project is already open, I'd expect that plugins would have done what they needed the first time the project was opened. I used `grep` to look for plugins that handle the `project-close` and `project-open` signals.
* geanylua and geanypy – pass the signals on to scripts.
* projectorganizer – close/open/update project, update sidebar. I don't see anything that looks like updating indices in response to open/close signals, but those could be hiding in function calls I didn't follow (I only looked at only 2-3 levels across two files). I've been using this plugin and PR together with no ill effects.
* scope – Functions that call functions that call functions that look like they eventually update the menu. Since it's the same project, I would guess the menu state would end up in the same place.
* geanyctags – Changes widget sensitivity. Would not be affected by this PR because it's clearly supposed to end up in the same state.
* treebrowser – Updates the path. There are also buttons and context menu items that can be used to update the path to achieve similar effect.
When a project is opened from the menu, no warning is generated.
Oh, Ok, well no need to add one then, coulda sworn it did, but maybe its been removed, maybe github search knows ... ahh, it used to for a "recent project" open, but that was removed in f40569d.
My main concern was opening from the file manager, since that's how I've been opening projects. Maybe already-open projects can continue to be re-opened from the menu because "Unlikely to be done accidentally." ?
Or the behavior of this PR could be put behind an option, like `files.reload_project_open_same` ?
... only getting confused for smarties with multiple paths to the same file, but in that case its no different to the current situation, so no need for real_path.
I missed the symlink issue. I've changed it to use the real path.
Do you get an absolute path from the socket buffer then?
I think so because the filenames are able to match, preventing the project from opening.
BTW I am not saying this PR is a bad idea, just want to be sure the implementation has no negative side effects.
My interpretation is that your intention is to improve the PR... Or if it's really misguided, help me figure it out...
@xiota pushed 1 commit.
de26ca9db565130e10b1726e751efcf2405995d4 Add option to control whether to reopen already-open projects
@xiota pushed 1 commit.
76cf6af9449628e5ec0e2c7a8979ca835d30247f update manual
I put the behavior from this PR behind an option in various, "projects.reload_already_open". The default is true, which is the current behavior (or should it be false?). When the project is not reloaded, a message is sent to the status window.
@xiota pushed 1 commit.
08d5f644afff8717a9d4f79df068bc014590bc15 change default of projects.reload_already_open to false
@xiota pushed 1 commit.
75516f2414310f71206f1e9bd3204ec3330f1570 Add option to avoid reloading already-open projects
Force push to rebase and combine commits.
@xiota pushed 1 commit.
df6f4059c5a3e6bcd62f103334712dd34ec8c5f8 Use error macro
@xiota pushed 2 commits.
681d86e95758df12e67bfc69744941ce03302e99 Add option to avoid reloading already-open projects 151ea546d90685987ca9f30da37cbba8a8948d59 Use error macro
Force push to rebase and guarantee no conflicts with recent session-split commit.
Closed #2951.
github-comments@lists.geany.org