<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">That's great, thanks a lot!<div><br></div><div>--Mike</div><div><br><div><div>On Mar 6, 2014, at 10:56 PM, mikel evins <<a href="mailto:evins.mikel@gmail.com">evins.mikel@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br>On Mar 6, 2014, at 4:29 PM, Michael Minerva <<a href="mailto:minerva@agentsheets.com">minerva@agentsheets.com</a>> wrote:<br><br><blockquote type="cite">Hey Paul,<br><br>I've been looking through your contributions but haven't found anything about setting up a main menu for the app. Do you have anything about that in your contribs?</blockquote><div><br></div><div>Try this, and let me know how it works. It's slightly dated; beware of possible bitrot.</div><div><br></div><div><font face="Menlo">(in-package :cl-user)<br><br>(defpackage testapp (:use :common-lisp :ccl))<br><br>(in-package :testapp)<br><br>;;; ---------------------------------------------------------------------<br>;;; menu utils<br>;;; ---------------------------------------------------------------------<br><br>(defun make-menu (menu-title)<br> (#/autorelease (#/initWithTitle: (#/alloc (objc:@class ns:ns-menu)) menu-title)))<br><br>(defun add-menu-separator (menu)<br> (#/addItem: menu (#/separatorItem ns:ns-menu-item)))<br><br>(defun add-menu-item (menu item-title <br> &key<br> (action (%null-ptr))<br> (target (%null-ptr)) ; by default target the First Responder<br> (key-equivalent #@"")<br> (key-equivalent-modifier-mask nil)<br> (tag nil))<br> (let ((item (#/addItemWithTitle:action:keyEquivalent: menu item-title action key-equivalent)))<br> (when key-equivalent-modifier-mask<br> (#/setKeyEquivalentModifierMask: item key-equivalent-modifier-mask))<br> (when tag<br> (#/setTag: item tag))<br> (#/setTarget: item target)<br> item))<br><br>;;; ---------------------------------------------------------------------<br>;;; application menu<br>;;; ---------------------------------------------------------------------<br><br>(defun populate-application-menu (main-menu)<br> (let* ((main-item (add-menu-item main-menu #@"Apple"))<br> (menu (make-menu #@"Apple")))<br> (perform-selector (ccl::nsapp)<br> (objc:@selector "setAppleMenu:")<br> :with-object menu)<br><br> (add-menu-item menu #@"About Testapp" :action (objc:@selector "orderFrontStandardAboutPanel:") :target (ccl::nsapp))<br> (add-menu-separator menu)<br><br> (add-menu-item menu #@"Preferences..." :key-equivalent #@"," :target (ccl::nsapp))<br> (let ((services-menu (make-menu #@"Services"))<br> (services-item (add-menu-item menu #@"Services" :target (ccl::nsapp))))<br> (#/setSubmenu:forItem: menu services-menu services-item)<br> (#/setServicesMenu: (ccl::nsapp) services-menu))<br> (add-menu-separator menu)<br><br> (add-menu-item menu #@"Hide Testapp" :action (objc:@selector "hide:") :target (ccl::nsapp) :key-equivalent #@"h")<br> (add-menu-item menu #@"Hide Others" :action (objc:@selector "hideOtherApplications:") :target (ccl::nsapp)<br> :key-equivalent #@"h" :key-equivalent-modifier-mask (logior #$NSCommandKeyMask #$NSAlternateKeyMask))<br> (add-menu-item menu #@"Show All" :action (objc:@selector "unhideAllApplications:") :target (ccl::nsapp))<br> (add-menu-separator menu)<br><br> (add-menu-item menu #@"Quit" :action (objc:@selector "terminate:") :target (ccl::nsapp) :key-equivalent #@"q")<br> <br> (#/setSubmenu:forItem: main-menu menu main-item)))<br><br><br>;;; ---------------------------------------------------------------------<br>;;; file menu<br>;;; ---------------------------------------------------------------------<br><br>(defun populate-file-menu (main-menu)<br> (let* ((main-item (add-menu-item main-menu #@"File"))<br> (menu (make-menu #@"File")))<br> <br> (add-menu-item menu #@"New" :action (objc:@selector "newDocument:") :key-equivalent #@"n")<br> (add-menu-item menu #@"Open..." :action (objc:@selector "openDocument:") :key-equivalent #@"o")<br> (let ((recent-menu (make-menu #@"Open Recent"))<br> (recent-item (add-menu-item menu #@"Open Recent")))<br> (perform-selector recent-menu<br> (objc:@selector "_setMenuName:")<br> :with-object #@"NSRecentDocumentsMenu")<br> (#/setSubmenu:forItem: menu recent-menu recent-item))<br> (add-menu-separator menu)<br><br> (add-menu-item menu #@"Close" :action (objc:@selector "performClose:") :key-equivalent #@"w")<br> (add-menu-item menu #@"Save" :action (objc:@selector "saveDocument:") :key-equivalent #@"s")<br> (add-menu-item menu #@"Save As..." :key-equivalent #@"S")<br> (add-menu-item menu #@"Revert" :action (objc:@selector "revertDocumentToSaved:"))<br> (add-menu-separator menu)<br><br> (add-menu-item menu #@"Page Setup..." :action (objc:@selector "runPageLayout:") :target (ccl::nsapp) :key-equivalent #@"P")<br> (add-menu-item menu #@"Print..." :action (objc:@selector "printDocument:") :target (ccl::nsapp) :key-equivalent #@"p")<br><br> (#/setSubmenu:forItem: main-menu menu main-item)))<br><br><br><br><br>(defun setup-menus ()<br> (let ((main-menu (#/autorelease (#/initWithTitle: (#/alloc (objc:@class ns:ns-menu)) #@"MainMenu"))))<br> (populate-application-menu main-menu)<br> (populate-file-menu main-menu)<br> (#/setMainMenu: (ccl::nsapp) main-menu)))<br></font><br></div></div></blockquote></div><br></div></body></html>