addMenuItem {iSPlot} | R Documentation

## Add menu and submenu items to the menu from R command line

### Description

addMenuItem adds a menu item to the main menu on the control window after the main menu has already been created. addMenuItem is meant to be called from the R command line when the user wants to add a new menu item to the main menu. addSubMenuItem adds a sub menu item to an already existing menu (such as file, edit, display or viewMode).

### Usage

    addMenuItem(menuName, labelText, ag = get("ag", controlEnv),
                method = "activate-item", modType = GdkModifierType[4],
                accelFlag = GtkAccelFlags[2])
    addSubMenuItem(menuName, labelText, action, ag=get("ag",controlEnv),
                method="activate", modType=GdkModifierType[3],
                accelFlag=GtkAccelFlags[2], ...)

### Arguments

`menuName` | A character string giving the name of the menu. This is displayed on the menu and is used to access the item.
`labelText` | The text shown on the menu item.
`ag` | The Gtk accelerator group.
`method` | The Gtk method, which occurs in response to accelerator keys.
`modType` | the GdkModifierType
`accelFlag` | the GdkAccelFlags
`action` | the current action to set `action` in `controlEnv` (this function will be called in response to activation of menu item)
`...` | any extra parameters that will be needed in the function, `action`

### Details

To add a new menu item, first call `addMenuItem` to create the menu item, and then call `addSubMenuItem` to add sub menu items to the new menu item. There is some checking to see if the item already exists.

When adding a sub menu item, `action` is the name of the function that will be called when the menu item is activated. This function, given as a character string to curAction, can have parameters. Any extra parameters will be placed in the ... parameter. This function will be called in updateControlWindow, using do.call.

### Value

addSubMenuItem returns the new GtkMenuItem object that was created or if an error occurred, then addSubMenuItem returns an empty list.

### Author(s)

Elizabeth Whalen

### See Also

`createMainMenu`, `updateControlWindow`

### Examples

      if (interactive())
      {
        createControlWindow()
        addMenuItem("new","_New")

        testfun<-function()
        {
          w<-gtkWindow(show=FALSE)
          lab<-gtkLabel("It works!")
          w$Add(lab)
          w$Show()
        }

        newMenuItem<-addSubMenuItem("new", "Diff_erent  Ctrl+E","testfun")
      }

[Package iSPlot version 1.0.7 Index]