[Openmcl-devel] how to show NSAlert on Lisp startup
minerva at agentsheets.com
Fri Sep 16 14:14:51 PDT 2011
On Sep 16, 2011, at 1:45 PM, R. Matthew Emerson wrote:
> On Sep 14, 2011, at 5:47 PM, Alexander Repenning wrote:
>> We have a need to show some NSAlerts at the start of running a CCL-based app on Mac/PC using Cocoa/Cocotron. So far we have not found any permutation that works of *restore-lisp-functions* and :toplevel-function (initarg to build-application) on PCs or Macs.
>> The code below will not run the login function but not bring up the modal NSAlert on a Mac and crash on a PC. A variation using (ccl::build-application :name "Crasher" :toplevel-function 'login)
>> does even worse. I am not completely surprised and assume that its just too early in the game of the Cocoa app launch. The main thread may not be running or just not be ready. We did try to call our function from #/applicationDidFinishLaunching which is called but that does not work either.
> It should work to show an alert from #/applicationDidFinishLaunching. You should also be able to have an object listen for NSApplicationDidFinishLaunchingNotification and display an alert from there, as well.
> If I put the following snippet at the end of #/applicationDidFinishLaunching, in ccl:cocoa-ide;app-delegate.lisp, it shows the alert for me.
> (ccl::with-autoreleased-nsstrings ((title "Yow!")
> (msg "Legally imposed CULTURE-reduction is CABBAGE-BRAINED!"))
> (let ((alert (#/init (#/alloc ns:ns-alert))))
> (#/setMessageText: alert title)
> (#/setInformativeText: alert msg)
> (#/runModal alert)))
I've used #/applicationDidFinishLaunching to successfully show this sort of NSAlert on the Mac, but sadly posting an NSAlert during this method causes a freeze on Windows, with no clues about the cause.
>> Is there or how would one create a *Cocoa-Startup-Functions* capable to run modal NSAlerts on CCL Mac and PC?
>> Any suggestions would be appreciated.
>> (in-package :ccl)
>> (defun NATIVE-STRING (String) "
>> Return a native string"
>> (#/autorelease (ccl::%make-nsstring String)))
>> (defmethod STANDARD-ALERT-DIALOG ((Message string) &key
>> (Yes-Text "OK")
>> (No-Text nil)
>> (Cancel-Text nil)
>> (Is-Critical nil))
>> (let ((Alert (#/init (#/alloc ns:ns-alert))))
>> (#/setMessageText: Alert (native-string Message))
>> (when Yes-Text (#/addButtonWithTitle: Alert (native-string Yes-Text)))
>> (when No-Text (#/addButtonWithTitle: Alert (native-string No-Text)))
>> (when Cancel-Text (#/addButtonWithTitle: Alert (native-string Cancel-Text)))
>> (when Explanation-Text (#/setInformativeText: Alert (native-string Explanation-Text)))
>> (#/setAlertStyle: Alert (if Is-Critical #$NSCriticalAlertStyle #$NSWarningAlertStyle))
>> (case (#/runModal Alert)
>> (#.#$NSAlertFirstButtonReturn t)
>> (#.#$NSAlertSecondButtonReturn nil)
>> (#.#$NSAlertThirdButtonReturn (throw :cancel nil)))))
>> (defvar *Evidence-of-Login-Execution* nil)
>> (defun LOGIN ()
>> (setq *Evidence-of-Login-Execution* t)
>> (standard-alert-dialog "Too good to be true?"))
>> (pushnew 'login ccl::*restore-lisp-functions*)
>> (require :build-application)
>> (ccl::build-application :name "Crasher")
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
More information about the Openmcl-devel