Skip to content

Commit

Permalink
Merge pull request #1181 from p4bl0-/update-closing-event-behavior
Browse files Browse the repository at this point in the history
Update closing event behavior to match GTK behavior in PR #1180
  • Loading branch information
r0x0r committed Jul 28, 2023
2 parents 8403b0a + 1a99275 commit 9853c68
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
12 changes: 5 additions & 7 deletions webview/platforms/cocoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,14 +911,12 @@ def should_close(window):
cancel = window.localization['global.cancel']
msg = window.localization['global.quitConfirmation']

if not window.confirm_close or BrowserView.display_confirmation_dialog(quit, cancel, msg):
should_cancel = window.events.closing.set()
if should_cancel:
return Foundation.NO
else:
return Foundation.YES
else:
should_cancel = window.events.closing.set()
if should_cancel:
return Foundation.NO
if not window.confirm_close or BrowserView.display_confirmation_dialog(quit, cancel, msg):
return Foundation.YES
return Foundation.NO

@staticmethod
def print_webview(webview):
Expand Down
15 changes: 7 additions & 8 deletions webview/platforms/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ def __init__(self, window):
self.js_bridge.window = window

self.is_fullscreen = False
self.confirm_close = window.confirm_close
self.text_select = window.text_select

self._file_name_semaphore = Semaphore(0)
Expand Down Expand Up @@ -456,7 +455,13 @@ def on_set_on_top(self, top):
self.show()

def closeEvent(self, event):
if self.confirm_close:
should_cancel = self.pywebview_window.events.closing.set()

if should_cancel:
event.ignore()
return

if self.pywebview_window.confirm_close:
reply = QMessageBox.question(
self,
self.title,
Expand All @@ -469,12 +474,6 @@ def closeEvent(self, event):
event.ignore()
return

should_cancel = self.pywebview_window.events.closing.set()

if should_cancel:
event.ignore()
return

event.accept()
BrowserView.instances[self.uid].close()
del BrowserView.instances[self.uid]
Expand Down
25 changes: 12 additions & 13 deletions webview/platforms/winforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,22 +279,21 @@ def _shutdown():
self.Invoke(Func[Type](_shutdown))

def on_closing(self, sender, args):
if self.pywebview_window.confirm_close:
result = WinForms.MessageBox.Show(
self.localization['global.quitConfirmation'],
self.Text,
WinForms.MessageBoxButtons.OKCancel,
WinForms.MessageBoxIcon.Asterisk,
)

if result == WinForms.DialogResult.Cancel:
args.Cancel = True
should_cancel = self.closing.set()
if should_cancel:
args.Cancel = True

if not args.Cancel:
should_cancel = self.closing.set()
if self.pywebview_window.confirm_close:
result = WinForms.MessageBox.Show(
self.localization['global.quitConfirmation'],
self.Text,
WinForms.MessageBoxButtons.OKCancel,
WinForms.MessageBoxIcon.Asterisk,
)

if should_cancel:
args.Cancel = True
if result == WinForms.DialogResult.Cancel:
args.Cancel = True

def on_resize(self, sender, args):
if self.WindowState == WinForms.FormWindowState.Maximized:
Expand Down

0 comments on commit 9853c68

Please sign in to comment.