<commit_before>// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import {
  ArrayExt
} from '@phosphor/algorithm';

import {
    Menu, MenuBar
} from '@phosphor/widgets';

import {
  JupyterLab
} from '@jupyterlab/application';

import {
    IMainMenu
} from '@jupyterlab/apputils';

let remote = (window as any).require('electron').remote;

let NMenu = remote.Menu;
let NMenuItem = remote.MenuItem;

export
class NativeMenu extends MenuBar implements IMainMenu {

    /**
     * The native menu object. This is a remote object in the main process.
     */
    private nMenu: Electron.Menu;

    /**
     * The next open index in the menu array
     */
    private index: number = 0;

    constructor(private app: JupyterLab) {
        super();
        this.nMenu = new NMenu();
    }

    private handleClick(menuItem: Electron.MenuItem): void {
        console.log('Click Received');
    }

    addMenu(menu: Menu, options: IMainMenu.IAddOptions = {}): void {
        if (ArrayExt.firstIndexOf(this.menus, menu) > -1) {
            return;
        }

        let nItems: Electron.MenuItemConstructorOptions[] = menu.items.map((item: Menu.IItemOptions) => {
            let nItem: Electron.MenuItemConstructorOptions = new Object();
            // HACK. Submenus should be new menu objects.
            if (item.type == 'command' || item.type == 'submenu') {
                nItem.type = 'normal';
                nItem.label = this.app.commands.label(item.command);
                nItem.click = this.handleClick;
            } else {
                nItem.type = 'separator'
            }
            return nItem;
        });

        /* Append the menu to the native menu */
        this.nMenu.append(new NMenuItem({
            label: menu.title.label,
            submenu: nItems
        }));
        // We need to look into the performace impact of calling this
        // every time
        NMenu.setApplicationMenu(this.nMenu);

        /* Append the menu to local list */
        this.insertMenu(this.index++, menu);
    }
}<commit_msg>Fix bug in menubar render<commit_after>// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import {
  ArrayExt
} from '@phosphor/algorithm';

import {
    Menu, MenuBar
} from '@phosphor/widgets';

import {
  JupyterLab
} from '@jupyterlab/application';

import {
    IMainMenu
} from '@jupyterlab/apputils';

let remote = (window as any).require('electron').remote;

let NMenu = remote.Menu;
let NMenuItem = remote.MenuItem;

export
class NativeMenu extends MenuBar implements IMainMenu {

    /**
     * The native menu object. This is a remote object in the main process.
     */
    private nMenu: Electron.Menu;

    /**
     * The next open index in the menu array
     */
    private index: number = 0;

    constructor(private app: JupyterLab) {
        super();
        this.nMenu = new NMenu();
        NMenu.setApplicationMenu(this.nMenu);
    }

    private handleClick(menuItem: Electron.MenuItem): void {
        console.log('Click Received');
    }

    addMenu(menu: Menu, options: IMainMenu.IAddOptions = {}): void {
        if (ArrayExt.firstIndexOf(this.menus, menu) > -1) {
            return;
        }

        let nItems: Electron.MenuItemConstructorOptions[] = menu.items.map((item: Menu.IItemOptions) => {
            let nItem: Electron.MenuItemConstructorOptions;
            // HACK. Submenus should be new menu objects.
            if (item.type == 'command' || item.type == 'submenu')
                nItem.type = 'normal';
            nItem.label = this.app.commands.label(item.command);
            nItem.click = this.handleClick;
            return nItem;
        });

        /* Append the menu to the native menu */
        this.nMenu.append(new NMenuItem({
            label: menu.title.label,
            submenu: nItems
        }));

        /* Append the menu to local list */
        this.insertMenu(this.index++, menu);
    }
}
{'fraction_non_alphanumeric': 0.11365332006963443, 'fraction_numerical': 0.000994777418552599, 'mean_word_length': 2.2279293739967896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '360663', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1149, 'n_words': 324}