EventClose on Dock
Re: EventClose on Dock
Sorry, I was talking in the context of logout. It does work nicely from context menu close, but not from logout.
Re: EventClose on Dock
And cannot use WaitEvent/WaitWindowEvent in the callback procedure to keep things responsive too...
WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback.
WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback.
Re: EventClose on Dock
Seems that BindEvent keeps working. Good.
Re: EventClose on Dock
Why appWillTerminate is not called in below case?
And is there anything wrong with the way to do things like this instead or does this break stuff?:
All code from elsewhere in forum slightly adjusted to fit the case.
Code: Select all
EnableExplicit
Prototype Proto_AppNotification(Object, Selector, Sender)
DeclareC AppShouldTerminate(Object, Selector, Sender)
DeclareC AppWillTerminate(Object, Selector, Sender)
Global AppDelegate, AppShouldTerminate_.Proto_AppNotification, AppWillTerminate_.Proto_AppNotification
AppDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
AppShouldTerminate_ = class_replaceMethod_(CocoaMessage(0, AppDelegate, "class"),
sel_registerName_("applicationShouldTerminate:"),
@AppShouldTerminate(), "v@:@")
AppWillTerminate_ = class_replaceMethod_(CocoaMessage(0, AppDelegate, "class"),
sel_registerName_("applicationWillTerminate:"),
@AppWillTerminate(), "v@:@")
; class_addMethod_(CocoaMessage(0, AppDelegate, "class"),
; sel_registerName_("applicationWillTerminate:"),
; @AppWillTerminate(), "v@:@")
ProcedureC AppShouldTerminate(Object, Selector, Sender)
Debug "AppShouldTerminate"
If AppShouldTerminate_
AppShouldTerminate_(Object, Selector, Sender)
EndIf
If MessageRequester("Confirmation", "Do you want to terminate the application?",
#PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
End
Else
ProcedureReturn #NO
EndIf
EndProcedure
ProcedureC AppWillTerminate(Object, Selector, Sender)
Debug "AppWillTerminate"
End
EndProcedure
OpenWindow(0, 270, 100, 200, 170, "Test", #PB_Window_MinimizeGadget)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Code: Select all
ProcedureC AppShouldTerminate(Object, Selector, Sender)
Debug "AppShouldTerminate"
ProcedureReturn #YES
EndProcedure
ProcedureC AppWillTerminate(Object, Selector, Sender)
Debug "AppWillTerminate"
End
EndProcedure
w = OpenWindow(0, 0, 0, 300, 200, "Test")
CocoaMessage(@app, 0, "NSApplication sharedApplication")
myAppDelegateClass = objc_allocateClassPair_(objc_getClass_("NSObject"), "myAppDelegate", 0)
class_addProtocol_(myAppDelegateClass, objc_getProtocol_("NSApplicationDelegate"))
class_addMethod_(myAppDelegateClass, sel_registerName_("applicationShouldTerminate:"), @appShouldTerminate(), "L@:@")
class_addMethod_(myAppDelegateClass, sel_registerName_("applicationWillTerminate:"), @appWillTerminate(), "v@:@")
objc_registerClassPair_(myAppDelegateClass)
myAppDelegate = class_createInstance_(myAppDelegateClass, 0)
CocoaMessage(0, app, "setDelegate:", myAppDelegate)
Repeat
e = WaitWindowEvent(10)
Until e = #PB_Event_CloseWindow
Re: EventClose on Dock
When you place End within the AppShouldTerminate procedure, it already ends the application so AppWillTerminate will never be called.Rinzwind wrote:Why appWillTerminate is not called in below case?
For some reason when I remove End, it still isn't being called. I have no clue why
Yes, this is wrong. Creating you own app delegate is only safe when you create everything yourself (including windows, event loop etc.).Rinzwind wrote:And is there anything wrong with the way to do things like this instead or does this break stuff?:
PureBasic already uses an app delegate so if you replace it like this with your own app delegate, it will break things.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)