Home Segments Index Top Previous Next

728: Mainline

Once you have created a menu, such as the Options menu, you must connect that menu to a menu window using the addMenu: message. Then, you also must connect the menu window to the top pane of an application. Both connections occur in the createViews method of a view manager.

The following definition illustrates the connections by way of additions to the createViews method shown in Segment 705. The definition also includes a name for the list box, which you need later in Segment••missing reference••.

CalorieViewManager method definition • instance
createViews
  | theTopPane theListBox theMeterPane theMenuWindow |
  "Set up all panes"
  self addView: (theTopPane := TopPane new).
  theListBox := ListBox new.
  theMeterPane := MeterGraphPane new.
  "Set up the top pane"
  theTopPane owner: self;
    labelWithoutPrefix: 'Demonstration Window';
    noSmalltalkMenuBar;
    addSubpane: theListBox;
    addSubpane: theMeterPane;
    menuWindow: (theMenuWindow := MenuWindow new);              
    framingRatio: (1/4 @ (1/3) rightBottom: 3/4 @ (2/3)).
  "Set up the menu window"                                      
  theMenuWindow addMenu:                                        
    (Menu new                                                   
       title: '~Options';                                       
       owner: self;                                             
       appendItem: '~Food Type' selector: #resetListBox;        
       appendSubMenu:                                           
         (Menu new                                              
            title: '~Mode';                                     
            owner: self;                                        
            appendItem: '~Fat Calories' selector: nil;          
            appendItem: '~Total Calories' selector: nil)).      
  "Definition continued on next page"
  "Definition continued from previous page"
  "Set up the list-box pane"
  theListBox owner: self;
    paneName: 'ListBox';                                        
    when: #getContents perform: #initializeListBox:;  
    when: #select perform: #itemSelected:;               
    framingRatio: (2/3 @ 0 rightBottom: 1 @ 1).                  
  "Set up the meter pane" 
  theMeterPane owner: self; 
    paneName: 'CalorieMeter';                                            
    noScrollBars;  
    when: #getContents perform: #initializeMeter:;  
    when: #display perform: #callDrawMeter:;  
    framingRatio: (0 @ 0 rightBottom: 2/3 @ 1).