Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jeremypw
Copy link
Collaborator

@jeremypw jeremypw commented Jun 30, 2025

Fixes #721
Fixes #1593

When a second or subsequent window is closed its documents are just closed after saving if required.

Closing a second or subsequent window (with <Alt>F4 or otherwise) only closes the focused window.

<Ctrl>Q closes all windows. Only the docs in the last closed window will be restored.

NOTE: Restarting or closing down the system still causes unsaved data to be lost as in 'master'.

Some names are changed to make clearer their function.

@jeremypw jeremypw added this to the 8.1 milestone Jun 30, 2025
@jeremypw jeremypw modified the milestones: 8.1, 8.2 Jul 18, 2025
@jeremypw jeremypw marked this pull request as ready for review August 9, 2025 16:41
@jeremypw jeremypw requested a review from a team August 9, 2025 16:41
@kaixoo12
Copy link

I don't think moving unsaved files from window A to window B is expected behaviour at all. I don't like this behaviour. Window B should:

A) Autosave all files from the window that are unsaved.

B) Ask to save them (I think this is discouraged by elementary guidelines, but it might make sense in this specific context where the user closes the window with unsaved files?)

@danirabbit
Copy link
Member

Yeah I agree I don't think this is the expected behavior. If I'm closing a window with tabs, I would expect those tabs to close. If I wanted to keep the tabs, I'd move them to the other window.

There seems to be a couple of issues in #721:

  • Ctrl + Q should quit the app entirely, not just close the last window. I believe Ctrl + W is the shortcut for closing just a window
  • We should probably throw a warning when trying to close a window with unsaved documents since it's unclear what to do and we need a decision about if the files should be saved or deleted

@jeremypw
Copy link
Collaborator Author

jeremypw commented Aug 12, 2025

@danirabbit @kaixoo12 Thanks for the input - I'll rework this PR accordingly. Note that with the suggested behaviour, the documents will be saved but not restored.

@jeremypw jeremypw marked this pull request as draft August 12, 2025 11:43
@jeremypw
Copy link
Collaborator Author

@danirabbit I think <Ctrl>W usually just closes the current tab (or <Ctrl><Shift>W for Terminal). <Alt>F4 closes the current window in Code and Files. You are right that <Ctrl>Q should close all windows - as it does in Files. Code needs to be fixed in this respect.

@jeremypw jeremypw changed the title Move docs into another window when another one closes Handle closing second or subsequent window Aug 13, 2025
@jeremypw jeremypw marked this pull request as ready for review August 13, 2025 17:41
@jeremypw
Copy link
Collaborator Author

Note: The PR currently restores the doc in the last closed window, not the first opened window. Please confirm whether this is the correct behaviour.

@flodavid
Copy link

flodavid commented Dec 31, 2025

@jeremypw I just tested it. The behaviour is definitely better.
A problem I find is that when reopening an instance after closing all windows, the "Closed tabs" is the one of the last closed window. Would it be possible to either share the content of this menu between instances or at least to merge its content to an opened window when one is closed ? It would avoid losing any closed tabs history.

@jeremypw
Copy link
Collaborator Author

jeremypw commented Jan 1, 2026

@flodavid Thanks for the review! I am glad the PR improves things for you. Could you expand a little on the question of what to do when a second or subsequent window is closed? The idea of automatically moving docs to another window has been vetoed by the design team but I am not sure whether moving the address of the docs to another windows "closed docs" list has been considered. This may be possible, but it would not cause those documents to be restored after closing the last window and then restarting. At the moment the settings can only restore one list of docs and that is the docs that were open in the last window to be closed. Closing another window will overwrite that list with the docs open in that window. We would have to change the structure of the settings quite significantly to restore the docs that were open in all windows opened in the session, and that may not always be what the user wants. This is not an easy question to solve and is probably outside the scope of this PR.

@jeremypw
Copy link
Collaborator Author

jeremypw commented Jan 1, 2026

One solution may be to cause the close window signal to throw up a list of options when there are more than one window. Ideally it should be possible to save the session exactly - i.e. each window saves and restores separately.

@flodavid
Copy link

flodavid commented Jan 2, 2026

I am not sure whether moving the address of the docs to another windows "closed docs" list has been considered. This may be possible, but it would not cause those documents to be restored after closing the last window and then restarting.

@jeremypw I do not mean that documents of all closed windows should be restored on restart, but it would be nice if they were added to the "Closed tabs" menu of some window still open. This way, it would be easy to restore any document if needed, as long as there is one open window left.
Screenshot from 2026-01-02 02 25 42

That said, you may be right that it's outside the scope of this PR.

Copy link

@flodavid flodavid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am no expert in the codebase or in even in Vala, but I took the liberty of reviewing the changes since it has been pending for quite some time.
I added some minor suggestions but it looks good to me.


public async bool handle_quit_window (MainWindow window_to_close) {
unowned List<Gtk.Window> windows = get_windows ();
var n_windows = windows.length ();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be replaced by bool is_last_window = windows.length () == 1; since the comparison is made two times

Comment on lines +203 to +212
unowned List<Gtk.Window> windows;
windows = get_windows ();
//NOTE This yields the last opened window at head of list (may change in future?)
while (windows.length () > 0) {
if (!yield handle_quit_window ((MainWindow) (windows.first ().data))) {
return;
}

windows = get_windows ();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be replaced by:

unowned List<Gtk.Window> windows = null;
do {
  windows = get_windows ();
      
  if (!yield handle_quit_window ((MainWindow) (windows.first ().data))) {
    return;
  }

   windows = get_windows ();
} while (windows.length () > 0);

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.

Regression: Closing a second window also closes the first Ctrl+Q closes second windows with loss of unsaved changes

6 participants