2015-10-03 01:57:40 +08:00
---
layout: docs
title: MenuManager
2015-10-04 04:56:58 +08:00
edit_url: "https://github.com/nylas/N1/blob/master/src/menu-manager.coffee"
2015-10-03 01:57:40 +08:00
---
2015-10-02 03:34:16 +08:00
2015-10-03 01:57:40 +08:00
< h2 > Summary< / h2 >
2015-10-02 03:34:16 +08:00
2015-10-03 01:57:40 +08:00
< div class = "markdown-from-sourecode" >
< p > < p > Provides a registry for menu items that you' d like to appear in the
2015-10-02 03:34:16 +08:00
application menu.< / p >
< p > An instance of this class is always available as the < code > atom.menu< / code > global.< / p >
< h2 id = "menu-cson-format" > Menu CSON Format< / h2 >
< p > Here is an example from the < a href = "https://github.com/atom/tree-view/blob/master/menus/tree-view.cson" > tree-view< / a > :< / p >
< pre > < code class = "lang-coffee" > < span class = "hljs-list" > [
{
< span class = "hljs-variable" > 'label< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-variable" > 'View< / span > '
< span class = "hljs-variable" > 'submenu< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-list" > [
{ < span class = "hljs-variable" > 'label< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-variable" > 'Toggle< / span > Tree View', < span class = "hljs-variable" > 'command< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-variable" > 'tree-view:toggle< / span > ' }
]
}
{
< span class = "hljs-variable" > 'label< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-variable" > 'Packages< / span > '
< span class = "hljs-variable" > 'submenu< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-list" > [
< span class = "hljs-variable" > 'label< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-variable" > 'Tree< / span > View'
< span class = "hljs-variable" > 'submenu< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-list" > [
{ < span class = "hljs-variable" > 'label< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-variable" > 'Focus< / span > ', < span class = "hljs-variable" > 'command< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-variable" > 'tree-view:toggle-focus< / span > ' }
{ < span class = "hljs-variable" > 'label< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-variable" > 'Toggle< / span > ', < span class = "hljs-variable" > 'command< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-variable" > 'tree-view:toggle< / span > ' }
{ < span class = "hljs-variable" > 'label< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-variable" > 'Reveal< / span > Active File', < span class = "hljs-variable" > 'command< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-variable" > 'tree-view:reveal-active-file< / span > ' }
{ < span class = "hljs-variable" > 'label< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-variable" > 'Toggle< / span > Tree Side', < span class = "hljs-variable" > 'command< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-variable" > 'tree-view:toggle-side< / span > ' }
]
]
}
]< / span > < / span > < / span > < / span >
< / code > < / pre >
< p > Use in your package' s menu < code > .cson< / code > file requires that you place your menu
structure under a < code > menu< / code > key.< / p >
< pre > < code class = "lang-coffee" > < span class = "hljs-variable" > 'menu< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-list" > [
{
< span class = "hljs-variable" > 'label< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-variable" > 'View< / span > '
< span class = "hljs-variable" > 'submenu< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-list" > [
{ < span class = "hljs-variable" > 'label< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-variable" > 'Toggle< / span > Tree View', < span class = "hljs-variable" > 'command< / span > < span class = "hljs-variable" > ':< / span > < span class = "hljs-variable" > 'tree-view:toggle< / span > ' }
]
}
]< / span > < / span >
< / code > < / pre >
< p > See < a href = '#add' > add< / a > for more info about adding menu' s directly.< / p >
< / p >
2015-10-03 01:57:40 +08:00
< / div >
2015-10-02 03:34:16 +08:00
2015-10-03 01:57:40 +08:00
< ul >
< / ul >
2015-10-02 03:34:16 +08:00
2015-10-03 01:57:40 +08:00
< h3 > Instance Methods< / h3 >
2015-10-02 03:34:16 +08:00
2015-10-03 01:57:40 +08:00
< h4 id = add class = "function-name" >
add(< span class = "args" > < span class = "arg" > items< / span > < / span > ) < a href = "#add" class = "link" > < / a >
< / h4 >
2015-10-04 04:56:58 +08:00
2015-10-03 01:57:40 +08:00
< div class = "function-description markdown-from-sourecode" >
< p > < p > Adds the given items to the application menu.< / p >
< / p >
< / div >
2015-10-04 04:56:58 +08:00
2015-10-03 01:57:40 +08:00
< strong > Parameters< / strong >
< table class = "arguments" >
2015-10-02 03:34:16 +08:00
< tr >
2015-10-03 01:57:40 +08:00
< th > Argument< / th >
< th > Description< / th >
2015-10-02 03:34:16 +08:00
< / tr >
2015-10-03 01:57:40 +08:00
< tr >
< td style = "width:15%;" >
< em > items< / em >
< / td >
< td class = "markdown-from-sourecode" >
2015-10-04 04:56:58 +08:00
2015-10-03 01:57:40 +08:00
< p > An < a href = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/array' > Array< / a > of menu item < a href = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/object' > Object< / a > s containing the keys:< / p >
2015-10-04 04:56:58 +08:00
2015-10-03 01:57:40 +08:00
< / td >
< / tr >
< / table >
2015-10-04 04:56:58 +08:00
2015-10-03 01:57:40 +08:00
< strong > Returns< / strong >
< table class = "arguments" >
< tr >
< th > Return Values< / th >
< / tr >
< tr > < td class = "markdown-from-sourecode" > < p > Returns a {Disposable} on which < code > .dispose()< / code > can be called to remove the
added menu items.< / p >
< / td > < / tr >
< / table >
< h4 id = update class = "function-name" >
update(< span class = "args" > < / span > ) < a href = "#update" class = "link" > < / a >
< / h4 >
2015-10-04 04:56:58 +08:00
2015-10-03 01:57:40 +08:00
< div class = "function-description markdown-from-sourecode" >
< p > < p > Refreshes the currently visible menu. < / p >
< / p >
< / div >