<commit_before>'use strict'

let nextCommandId = 0

// Maps role to methods of webContents
const rolesMap = {
  undo: 'undo',
  redo: 'redo',
  cut: 'cut',
  copy: 'copy',
  paste: 'paste',
  pasteandmatchstyle: 'pasteAndMatchStyle',
  selectall: 'selectAll',
  minimize: 'minimize',
  close: 'close',
  delete: 'delete',
  quit: 'quit',
  togglefullscreen: 'toggleFullScreen'
}

// Maps methods that should be called directly on the BrowserWindow instance
const methodInBrowserWindow = {
  minimize: true,
  close: true,
  toggleFullScreen: function (window) {
    window.setFullScreen(!window.isFullScreen())
  }
}

const methodInApp = {
  quit: true
}

const MenuItem = function (options) {
  const {app, Menu} = require('electron')

  const click = options.click
  this.selector = options.selector
  this.type = options.type
  this.role = options.role
  this.label = options.label
  this.sublabel = options.sublabel
  this.accelerator = options.accelerator
  this.icon = options.icon
  this.enabled = options.enabled
  this.visible = options.visible
  this.checked = options.checked

  this.submenu = options.submenu
  if (this.submenu != null && this.submenu.constructor !== Menu) {
    this.submenu = Menu.buildFromTemplate(this.submenu)
  }
  if (this.type == null && this.submenu != null) {
    this.type = 'submenu'
  }
  if (this.type === 'submenu' && (this.submenu == null || this.submenu.constructor !== Menu)) {
    throw new Error('Invalid submenu')
  }

  this.overrideReadOnlyProperty('type', 'normal')
  this.overrideReadOnlyProperty('role')
  this.overrideReadOnlyProperty('accelerator')
  this.overrideReadOnlyProperty('icon')
  this.overrideReadOnlyProperty('submenu')

  this.overrideProperty('label', '')
  this.overrideProperty('sublabel', '')
  this.overrideProperty('enabled', true)
  this.overrideProperty('visible', true)
  this.overrideProperty('checked', false)

  if (!MenuItem.types.includes(this.type)) {
    throw new Error(`Unknown menu item type: ${this.type}`)
  }

  this.commandId = ++nextCommandId

  this.click = (focusedWindow) => {
    // Manually flip the checked flags when clicked.
    if (this.type === 'checkbox' || this.type === 'radio') {
      this.checked = !this.checked
    }

    if (this.role && rolesMap[this.role] && process.platform !== 'darwin' && focusedWindow != null) {
      const methodName = rolesMap[this.role]
      if (methodInApp[methodName]) {
        return app[methodName]()
      } else if (typeof methodInBrowserWindow[methodName] === 'function') {
        return methodInBrowserWindow[methodName](focusedWindow)
      } else if (methodInBrowserWindow[methodName]) {
        return focusedWindow[methodName]()
      } else {
        const {webContents} = focusedWindow
        return webContents != null ? webContents[methodName]() : void 0
      }
    } else if (typeof click === 'function') {
      return click(this, focusedWindow)<commit_msg>Move click variable near this.click<commit_after>'use strict'

let nextCommandId = 0

// Maps role to methods of webContents
const rolesMap = {
  undo: 'undo',
  redo: 'redo',
  cut: 'cut',
  copy: 'copy',
  paste: 'paste',
  pasteandmatchstyle: 'pasteAndMatchStyle',
  selectall: 'selectAll',
  minimize: 'minimize',
  close: 'close',
  delete: 'delete',
  quit: 'quit',
  togglefullscreen: 'toggleFullScreen'
}

// Maps methods that should be called directly on the BrowserWindow instance
const methodInBrowserWindow = {
  minimize: true,
  close: true,
  toggleFullScreen: function (window) {
    window.setFullScreen(!window.isFullScreen())
  }
}

const methodInApp = {
  quit: true
}

const MenuItem = function (options) {
  const {app, Menu} = require('electron')

  this.selector = options.selector
  this.type = options.type
  this.role = options.role
  this.label = options.label
  this.sublabel = options.sublabel
  this.accelerator = options.accelerator
  this.icon = options.icon
  this.enabled = options.enabled
  this.visible = options.visible
  this.checked = options.checked

  this.submenu = options.submenu
  if (this.submenu != null && this.submenu.constructor !== Menu) {
    this.submenu = Menu.buildFromTemplate(this.submenu)
  }
  if (this.type == null && this.submenu != null) {
    this.type = 'submenu'
  }
  if (this.type === 'submenu' && (this.submenu == null || this.submenu.constructor !== Menu)) {
    throw new Error('Invalid submenu')
  }

  this.overrideReadOnlyProperty('type', 'normal')
  this.overrideReadOnlyProperty('role')
  this.overrideReadOnlyProperty('accelerator')
  this.overrideReadOnlyProperty('icon')
  this.overrideReadOnlyProperty('submenu')

  this.overrideProperty('label', '')
  this.overrideProperty('sublabel', '')
  this.overrideProperty('enabled', true)
  this.overrideProperty('visible', true)
  this.overrideProperty('checked', false)

  if (!MenuItem.types.includes(this.type)) {
    throw new Error(`Unknown menu item type: ${this.type}`)
  }

  this.commandId = ++nextCommandId

  const click = options.click
  this.click = (focusedWindow) => {
    // Manually flip the checked flags when clicked.
    if (this.type === 'checkbox' || this.type === 'radio') {
      this.checked = !this.checked
    }

    if (this.role && rolesMap[this.role] && process.platform !== 'darwin' && focusedWindow != null) {
      const methodName = rolesMap[this.role]
      if (methodInApp[methodName]) {
        return app[methodName]()
      } else if (typeof methodInBrowserWindow[methodName] === 'function') {
        return methodInBrowserWindow[methodName](focusedWindow)
      } else if (methodInBrowserWindow[methodName]) {
        return focusedWindow[methodName]()
      } else {
        const {webContents} = focusedWindow
        return webContents != null ? webContents[methodName]() : void 0
      }
    } else if (typeof click === 'function') {
      return click(this, focusedWindow)
{'fraction_non_alphanumeric': 0.13527806209484816, 'fraction_numerical': 0.000682360968952576, 'mean_word_length': 3.861525704809287, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4412602', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1755, 'n_words': 413}