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

Currently, if a user tries to close Preview which was opened inside Browse, the "parent" Browse window itself gets closed

Co-authored-by: beyondcompute <beyondcompute@users.noreply.github.com>
This commit is contained in:
Evgeny Kulikov 2025-04-27 11:25:20 +03:00 committed by GitHub
parent 62bad44eed
commit 2acdc8c30a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View file

@ -280,6 +280,19 @@ class Browser(QMainWindow):
if note_type_id := self.get_active_note_type_id():
add_cards.set_note_type(note_type_id)
# If in the Browser we open Preview and press Ctrl+W there,
# both Preview and Browser windows get closed by Qt out of the box.
# We circumvent that behavior by only closing the currently active window
def _handle_close(self):
active_window = QApplication.activeWindow()
if active_window and active_window != self:
if isinstance(active_window, QDialog):
active_window.reject()
else:
active_window.close()
else:
self.close()
def setupMenus(self) -> None:
# actions
f = self.form

View file

@ -792,7 +792,7 @@
<sender>actionClose</sender>
<signal>triggered()</signal>
<receiver>Dialog</receiver>
<slot>close()</slot>
<slot>_handle_close()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>