Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

di445 / ElectronAPIDemos   js

Repository URL to install this package:

Version: 1.1.0 

/ sections / menus / menus.html

<template class="task-template">
  <section id="menus-section" class="section js-section u-category-menu">
    <header class="section-header">
      <div class="section-wrapper">
        <h1>
          <svg class="section-icon"><use xlink:href="assets/img/icons.svg#icon-menu"></use></svg>
          Customize Menus
        </h1>
        <h3>The <code>Menu</code> and <code>MenuItem</code> modules can be used to create custom native menus.</h3>

        <p>There are two kinds of menus: the application (top) menu and context (right-click) menu.</p>

        <p>Open the <a href="http://electron.atom.io/docs/api/menu">full API documentation<span class="u-visible-to-screen-reader">(opens in new window)</span></a> in your browser.</p>
      </div>
    </header>

    <div class="demo">
      <div class="demo-wrapper">
        <button id="application-menu-demo-toggle" class="js-container-target demo-toggle-button">Create an application menu
          <div class="demo-meta u-avoid-clicks">Supports: Win, OS X, Linux <span class="demo-meta-divider">|</span> Process: Main</div>
        </button>
        <div class="demo-box">
          <p>The <code>Menu</code> and <code>MenuItem</code> modules allow you to customize your application menu. If you don't set any menu, Electron will generate a minimal menu for your app by default.</p>

          <p>This app uses the code below to set the application menu. If you click the 'View' option in the application menu and then the 'App Menu Demo', you'll see an information box displayed.</p>
          <h5>Main Process</h5>
          <pre><code data-path="main-process/menus/application-menu.js"></code></pre>

          <div class="demo-protip">
            <h2>ProTip</h2>
            <strong>Know operating system menu differences.</strong>
            <p>When designing an app for multiple operating systems it's important to be mindful of the ways application menu conventions differ on each operating system.</p>
            <p>For instance, on Windows, accelerators are set with an <code>&</code>. Naming conventions also vary, like between "Settings" or "Preferences". Below are resources for learning operating system specific standards.</p>
            <ul>
              <li><a href="https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/OSXHIGuidelines/MenuBarMenus.html#//apple_ref/doc/uid/20000957-CH29-SW1">OS X<span class="u-visible-to-screen-reader">(opens in new window)</span></a></li>
              <li><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb226797(v=vs.85).aspx">Windows<span class="u-visible-to-screen-reader">(opens in new window)</span></a></li>
              <li><a href="https://developer.gnome.org/hig/stable/menu-bars.html.en">Linux<span class="u-visible-to-screen-reader">(opens in new window)</span></a></li>
            </ul>
          </div>
        </div>
      </div>
    </div>

    <div class="demo">
      <div class="demo-wrapper">
        <button id="context-menu-demo-toggle" class="js-container-target demo-toggle-button">Create a context menu
          <div class="demo-meta u-avoid-clicks">Supports: Win, OS X, Linux <span class="demo-meta-divider">|</span> Process: Main</div>
        </button>
        <div class="demo-box">
          <div class="demo-controls">
            <button class="demo-button" id="context-menu">View Demo</button>
          </div>
          <p>A context, or right-click, menu can be created with the <code>Menu</code> and <code>MenuItem</code> modules as well. You can right-click anywhere in this app or click the demo button to see an example context menu.</p>

          <p>In this demo we use the <code>ipcRenderer</code> module to show the context menu when explicitly calling it from the renderer process.</p>
          <p>See the full <a href="http://electron.atom.io/docs/api/web-contents/#event-context-menu">context-menu event documentation</a> for all the available properties.</p>
          <h5>Main Process</h5>
          <pre><code data-path="main-process/menus/context-menu.js"></pre></code>
          <h5>Renderer Process</h5>
          <pre><code data-path="renderer-process/menus/context-menu.js"></pre></code>
        </div>
      </div>
    </div>

    <script type="text/javascript">
      require('./renderer-process/menus/context-menu')
    </script>

  </section>
</template>