
How do I detect this event, I don't want anyone clicking on the dock icon and just closing my application without a warning

No, that is not the one. That is when you click on the top menu and select "Quit". I am talking about your application being minimizedPolo wrote:This event is #pb_menu_quit (or something like that).
Code: Select all
EnableExplicit
ImportC ""
sel_registerName(MethodName.S)
class_addMethod(Class.I, Selector.I, Implementation.I, Types.S)
EndImport
ProcedureC AppShouldTerminate(Object.I, Selector.I, Sender.I)
If MessageRequester("Confirmation", "Do you want to terminate the application?",
#PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
End
Else
ProcedureReturn #NO
EndIf
EndProcedure
Procedure.S ConvertToUTF8(String.S)
Protected UTF8String.S = Space(StringByteLength(String))
PokeS(@UTF8String, String, -1, #PB_UTF8)
ProcedureReturn UTF8String
EndProcedure
Define AppDelegate.I = CocoaMessage(0, CocoaMessage(0, 0,
"NSApplication sharedApplication"), "delegate")
OpenWindow(0, 270, 100, 200, 170, "Test", #PB_Window_MinimizeGadget)
class_addMethod(CocoaMessage(0, AppDelegate, "class"),
sel_registerName(ConvertToUTF8("applicationShouldTerminate:")),
@AppShouldTerminate(), "v@:@")
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Code: Select all
EnableExplicit
Prototype Proto_AppShouldTerminate(Object, Selector, Sender)
DeclareC AppShouldTerminate(Object, Selector, Sender)
Global AppDelegate, AppShouldTerminate_.Proto_AppShouldTerminate
AppDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
AppShouldTerminate_ = class_replaceMethod_(CocoaMessage(0, AppDelegate, "class"),
sel_registerName_("applicationShouldTerminate:"),
@AppShouldTerminate(), "v@:@")
ProcedureC AppShouldTerminate(Object, Selector, Sender)
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
OpenWindow(0, 270, 100, 200, 170, "Test", #PB_Window_MinimizeGadget)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Of courseRinzwind wrote:Is there anything you can't figure out irt macPB?
I doubt if what you want is possible this way.Rinzwind wrote:f I return NSTerminateLater the main event loop is indeed not called anymore... a new event loop is started it seems. I have no clue how to handle that bit NSModalPanelRunLoopMode. I want to just continue with the main loop and call replyToApplicationShouldTerminate whenever convenient...
Code: Select all
Enumeration #PB_Event_FirstCustomValue
#Event_TerminateRequested
EndEnumeration
Prototype Proto_AppShouldTerminate(Object, Selector, Sender)
DeclareC AppShouldTerminate(Object, Selector, Sender)
Global AppDelegate, AppShouldTerminate_.Proto_AppShouldTerminate
AppDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
AppShouldTerminate_ = class_replaceMethod_(CocoaMessage(0, AppDelegate, "class"),
sel_registerName_("applicationShouldTerminate:"),
@AppShouldTerminate(), "v@:@")
ProcedureC AppShouldTerminate(Object, Selector, Sender)
PostEvent(#Event_TerminateRequested)
If AppShouldTerminate_
ProcedureReturn AppShouldTerminate_(Object, Selector, Sender)
EndIf
ProcedureReturn #NO
EndProcedure
OpenWindow(0, 0, 0, 420, 320, "Terminate request example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 10, 10, 400, 300)
Repeat
Event = WaitWindowEvent()
If Event = #Event_TerminateRequested
AddGadgetItem(0, -1, "Terminate requested at:" + FormatDate("%hh:%ii:%ss", Date()))
EndIf
Until Event = #PB_Event_CloseWindow