From f3fe384df176d0d5195fe929454a1b1e09ea5ca1 Mon Sep 17 00:00:00 2001 From: daboe01 Date: Sun, 7 Dec 2025 11:28:53 +0100 Subject: [PATCH 1/2] fixed: CPDocument sends windowWillClose: message twice --- AppKit/CPDocument.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPDocument.j b/AppKit/CPDocument.j index 8770d57aa..e4a9d696b 100644 --- a/AppKit/CPDocument.j +++ b/AppKit/CPDocument.j @@ -874,7 +874,7 @@ var CPDocumentUntitledCount = 0; if (aDocument === self && shouldClose) [self close]; - if (theDelegate != null) + else if (theDelegate != null) theDelegate.isa.objj_msgSend3(theDelegate, context.selector, aDocument, shouldClose, context.context); } From 99cf8e63874f6a668c032fa1e4cda19c8ac0523b Mon Sep 17 00:00:00 2001 From: daboe01 Date: Fri, 26 Dec 2025 10:42:41 +0100 Subject: [PATCH 2/2] improved logic --- AppKit/CPDocument.j | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/AppKit/CPDocument.j b/AppKit/CPDocument.j index e4a9d696b..70fa6ef00 100644 --- a/AppKit/CPDocument.j +++ b/AppKit/CPDocument.j @@ -871,10 +871,13 @@ var CPDocumentUntitledCount = 0; { var theDelegate = context.delegate; - if (aDocument === self && shouldClose) + // Only close the document explicitly if there is NO delegate to handle the action. + // If a delegate exists (e.g., the CPWindow), it is responsible for performing the close + // upon receiving the callback below. Calling [self close] here would cause a double-close. + if (aDocument === self && shouldClose && theDelegate == nil) [self close]; - else if (theDelegate != null) + if (theDelegate) theDelegate.isa.objj_msgSend3(theDelegate, context.selector, aDocument, shouldClose, context.context); }