Next: About this document ... Up: 3 Menus Previous: 3.5 Creating sub-menus

3.6 Creating a standard info panel

You may have noticed that in our previous example with the Info... sub-menu, we have used orderFrontStandardInfoPanel: as the action for the Info menu entry. The Info menu entry is usually supposed to display an ``Info Panel'' (also called ``About Panel'' on Microsoft Windows), with the title of the program, the version, the author, the copyright info. In this case, we use orderFrontStandardInfoPanel:, which is implemented by NSApplication (it is a GNUstep extension), and which displays a standard info panel. The information on what to display in the panel is taken from the Info-gnustep.plist file in the application's main bundle. This file is created automatically for you at compile time by the GNUstep make system; but you can insert your own entries in this file as follows.

If your application name is, for example, MyFirstApp, then you need to create a file called MyFirstAppInfo.plist in your source directory (you do not need to add anything to your GNUmakefile; the make system looks for this file automatically). Here is an example of such a file:

  ApplicationName = "My First Application";
  ApplicationDescription = "An Example of how to use NSMenu";
  ApplicationRelease = "0.1";
  Authors = ("Your Name Here <>", 
             "Another Name Here <>");
  Copyright = 
    "Copyright (c) 2008 Your Name Here <>";
  CopyrightDescription = 
    "This program is released under the GNU GPL";
You should of course edit this example filling in with the information appropriate for your own app. The file is in a format called ``property list'' (that is why it has extension plist; see the Basic Foundation Classes GNUstep Mini Tutorial for more information on property lists). The entries should be self-explanatory; note that Authors should be equal to an array of names. If you want to omit some of the entries, you may safely do it.

Here is the full listing of our latest app source code, containing an info submenu able to display the Info Panel:

#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>

@interface MyDelegate : NSObject
- (void) printHello: (id)sender;
- (void) applicationWillFinishLaunching: (NSNotification *)not;

@implementation MyDelegate : NSObject 
- (void) printHello: (id)sender
  printf ("Hello!\n");

- (void) applicationWillFinishLaunching: (NSNotification *)not
  NSMenu *menu;
  NSMenu *infoMenu;
  NSMenuItem *menuItem;

  menu = AUTORELEASE ([NSMenu new]);

  infoMenu = AUTORELEASE ([NSMenu new]);

  [infoMenu addItemWithTitle: @"Info Panel..." 
            action: @selector (orderFrontStandardInfoPanel:) 
            keyEquivalent: @""];

  [infoMenu addItemWithTitle: @"Help..." 
            action: @selector (orderFrontHelpPanel:)
            keyEquivalent: @"?"];

  menuItem = [menu addItemWithTitle: @"Info..." 
                   action: NULL 
                   keyEquivalent: @""];

  [menu setSubmenu: infoMenu  forItem: menuItem];

  [menu addItemWithTitle: @"Print Hello"  
        action: @selector (printHello:)  
        keyEquivalent: @""];

  [menu addItemWithTitle: @"Quit"  
        action: @selector (terminate:)  
        keyEquivalent: @"q"];

  [NSApp setMainMenu: menu];

int main (int argc, const char **argv)
  [NSApplication sharedApplication];
  [NSApp setDelegate: [MyDelegate new]];

  return NSApplicationMain (argc, argv);

Next: About this document ... Up: 3 Menus Previous: 3.5 Creating sub-menus