Skip to content

Close only “child” window (e.g. Preview) inside Browser on Cmd+W #3913

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

Conversation

beyondcompute
Copy link
Contributor

@beyondcompute beyondcompute commented Apr 9, 2025

Currently if we open Preview (for example) while being in the Browse mode, and then we try to close the Preview by pressing Cmd+W, both the Preview and the “parent” Browse window get closed. This feels counter-intuitive as Cmd+W should only close the “current window”.

Before

Before.mov

After

After.mov

It is interesting that Qt does not do ”the right thing” out of the box. 📦

@beyondcompute beyondcompute force-pushed the browser-action_close-only-child-windows-not-everything branch 2 times, most recently from 5c7d372 to 9812a71 Compare April 11, 2025 11:55
Copy link
Member

@dae dae left a comment

Choose a reason for hiding this comment

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

This is an improvement, though there's still an issue not caused by this PR: if the user switches to the main window then back to preview, the shortcut stops working, as the main window's menu is still active.

Given #3905 as well, it's got me wondering whether we'd be better off with a global shortcut handler that does something like what you've done here, so we don't need to manually add the shortcuts to each different dialog. WDYT?

@beyondcompute
Copy link
Contributor Author

This is an improvement, though there's still an issue not caused by this PR: if the user switches to the main window then back to preview, the shortcut stops working, as the main window's menu is still active.

Given #3905 as well, it's got me wondering whether we'd be better off with a global shortcut handler that does something like what you've done here, so we don't need to manually add the shortcuts to each different dialog. WDYT?

Yeah, it is an interesting issue with switching windows. I wonder, does Qt actually offer some pattern on how to manage those handlers.

As a side note, I tried “simply closing the Browse window if it’s active and do nothing otherwise (hoping that a sub-dialog has its own handler)” approach, and that does not work. Even if I install the handler to a sub-window, it apparently gets intercepted by the Browse window. 🙈

The global approach obviously sounds better! I suppose, I’ll try to at least research into that direction. But I am not sure that I won’t miss some important aspects of Anki’s architecture or Qt’s approaches.

@dae
Copy link
Member

dae commented Apr 13, 2025

It's a learning experience for all of us :-)

@beyondcompute beyondcompute force-pushed the browser-action_close-only-child-windows-not-everything branch from 9812a71 to f275385 Compare April 25, 2025 21:37
@dae
Copy link
Member

dae commented Apr 26, 2025

I noticed you updated this - does that mean you'd prefer to merge this in as-is for now?

@beyondcompute beyondcompute force-pushed the browser-action_close-only-child-windows-not-everything branch from f275385 to c71a053 Compare April 26, 2025 14:07
@beyondcompute
Copy link
Contributor Author

@dae, yes, I think I’d prefer that.

  1. Thanks for merging the other PR as well! 🙏
  2. I just remembered yesterday to go and prune my branches and decided to rebase “just in case”. Of course, it’s your call if this is OK to be merged.
  3. I quickly tried some things regarding the global keyboard shortcut handling. But nothing worked so far. It seems also that Anki has a custom mechanism for opening dialog windows… I haven’t spent that much time on the issue but in any case, I am not sure if I would be able to confidently test a larger refactoring if that were to take place.

@beyondcompute
Copy link
Contributor Author

Actually #3885 could affect how close actions work. 🤔

Currently, if a user tries to close Preview which was opened inside Browse, the "parent" Browse window itself gets closed
@beyondcompute beyondcompute force-pushed the browser-action_close-only-child-windows-not-everything branch from c71a053 to 6c63196 Compare April 26, 2025 16:14
@dae
Copy link
Member

dae commented Apr 27, 2025

Not all of our windows have access to a menubar, and I don't think we'll be moving to a unified bar in the near future, so a global shortcut is more useful.

@dae dae merged commit 2acdc8c into ankitects:main Apr 27, 2025
1 check passed
@beyondcompute beyondcompute deleted the browser-action_close-only-child-windows-not-everything branch April 27, 2025 19:15
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.

2 participants