Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!dali.cs.montana.edu!milton!wiml From: wiml@milton.u.washington.edu (William Lewis) Newsgroups: comp.sys.next Subject: Re: example menu code wanted Summary: Example menu code Keywords: adding menu cells on the fly? Message-ID: <8446@milton.u.washington.edu> Date: 2 Oct 90 03:51:34 GMT References: <3010@network.ucsd.edu> Organization: University of Washington, Seattle Lines: 90 In article <3010@network.ucsd.edu> pbiron@weber.ucsd.edu (Paul Biron) writes: >Here's the situation: I'm trying to add menu cells to a submenu >(of a submenu) on the fly. From reading the Spec Sheets I can't >figure out how to do it. The kind of thing I'm trying to do >is like the "Activate" menu in so many apps that are out there. ... >and every time the user choses the "Add" cell, I do a little >processing and add another cell to "Sub-Sub menu" (and "Remove" >should be able to remove one such cell). I had this same problem a while ago, and this is how I solved it. My main trouble was that IB wouldn't let me directly connect an outlet to a submenu, only to the main window. So I ended up connecting to the "Activate" menu cell (which IB thought was just a plain button, not a submenu) instead and creating and attaching the submenu in the outlet initialization method. This may not be the correct/approved way, but it works for me and seems reasonably clean. - setActivateMenu:anObject { activateMenu = [Menu newTitle:[anObject title]]; [[NXApp mainMenu] setSubmenu:activateMenu forItem:anObject]; [activateMenu display]; return self; } - addWindow:aWin title:(char *)title {id amCell; amCell = [activateMenu addItem:title action:@selector(makeKeyAndOrderFront:) keyEquivalent:-1]; [amCell setTarget:aWin]; [aWin setActivateCell:amCell]; [activateMenu display]; [aWin setDelegate:self]; return amCell; } - windowWillClose:sender {id matrix; int r,c, i; [activateMenu disableDisplay]; matrix = [activateMenu itemList]; // now search for & remove a cell with a target of aWin [matrix getNumRows:&r numCols:&c]; if(c != 1) [self error:"Activate menu matrix has more than one column, in fact it has %d", c]; for(i=0; i