[Openmcl-devel] how to show NSAlert on Lisp startup

Alexander Repenning ralex at cs.colorado.edu
Wed Sep 14 14:47:43 PDT 2011

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.

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")


Prof. Alexander Repenning

University of Colorado
Computer Science Department
Boulder, CO 80309-430

vCard: http://www.cs.colorado.edu/~ralex/AlexanderRepenning.vcf

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20110914/7dcf5f1f/attachment.htm>

More information about the Openmcl-devel mailing list