<commit_before>import Cocoa

class InterfaceSubmenu {

  private let interface: Interface

  init(_ interface: Interface) {
    self.interface = interface
  }

  lazy var titleMenuItem: NSMenuItem = {
    let item = NSMenuItem(title: self.interface.title, action: nil, keyEquivalent: "")
    item.representedObject = self.interface
    return item
  }()

  lazy var menuItem: NSMenuItem = {
    let item = NSMenuItem(title: "Loading...", action: nil, keyEquivalent: "")
    item.representedObject = self.interface
    item.target = Controller.self
    item.tag = 42

    if self.interface.softMAC.isValid {
      item.title = self.interface.softMAC.humanReadable
      SoftMACCache.remember(BSDName: self.interface.BSDName, address: self.interface.softMAC.formatted)
    } else {
      if let address = SoftMACCache.address(BSDName: self.interface.BSDName) {
        item.title = address
      } else {
        item.title = self.interface.hardMAC.formatted
      }
    }
    item.state = self.interface.hasOriginalMAC ? 1 : 0
    item.onStateImage = #imageLiteral(resourceName: "InterfaceLeaking")
    item.submenu = self.subMenuItem()
    return item
  }()

  private func subMenuItem() -> NSMenu {
    let submenu: NSMenu = NSMenu()

    let vendorName = MACVendors.name(address: interface.softMAC)

    let vendorNameItem = NSMenuItem(title: vendorName, action: nil, keyEquivalent: "")
    submenu.addItem(vendorNameItem)
    submenu.addItem(NSMenuItem.separator())

    if (interface.isPoweredOffWifi) {
      let poweredOffItem = NSMenuItem(title: "Powered off", action: nil, keyEquivalent: "")
      submenu.addItem(poweredOffItem)
    } else {

      let action = Config.instance.actionForInterface(interface.hardMAC)

      let ignoreItem: NSMenuItem = NSMenuItem(title: "Do nothing", action: #selector(Controller.ignoreInterface), keyEquivalent: "")
      ignoreItem.representedObject = interface
      ignoreItem.target = Controller.self
      ignoreItem.state = action == Interface.Action.ignore ? 1 : 0
      submenu.addItem(ignoreItem)

      let randomizeItem: NSMenuItem = NSMenuItem(title: "Random", action: #selector(Controller.randomizeInterface), keyEquivalent: "")
      randomizeItem.representedObject = interface
      randomizeItem.target = Controller.self
      randomizeItem.state = action == Interface.Action.random ? 1 : 0
      submenu.addItem(randomizeItem)

      let specifyItem: NSMenuItem = NSMenuItem(title: "Define manually", action: #selector(Controller.specifyInterface), keyEquivalent: "")
      specifyItem.representedObject = interface
      specifyItem.target = Controller.self
      specifyItem.state = action == Interface.Action.specify ? 1 : 0
      submenu.addItem(specifyItem)

      let originalizeItem: NSMenuItem = NSMenuItem(title: "Keep original", action: #selector(Controller.originalizeInterface), keyEquivalent: "")
      originalizeItem.representedObject = interface
      originalizeItem.target = Controller.self
      originalizeItem.state = action == Interface.Action.original ? 1 : 0
      submenu.addItem(originalizeItem)

      let forgetItem: NSMenuItem = NSMenuItem(title: "Forget", action: #selector(Controller.forgetInterface), keyEquivalent: "")
      forgetItem.representedObject = interface
      forgetItem.target = Controller.self
      forgetItem.state = action == Interface.Action.original ? 1 : 0
      submenu.addItem(forgetItem)

      submenu.addItem(NSMenuItem.separator())

      let hardMACItem: NSMenuItem = NSMenuItem(title: interface.hardMAC.formatted, action: nil, keyEquivalent: "")
      submenu.addItem(hardMACItem)
}
    return submenu
  }

}
<commit_msg>Renamed "Forget" to "Default", much nicer<commit_after>import Cocoa

class InterfaceSubmenu {

  private let interface: Interface

  init(_ interface: Interface) {
    self.interface = interface
  }

  lazy var titleMenuItem: NSMenuItem = {
    let item = NSMenuItem(title: self.interface.title, action: nil, keyEquivalent: "")
    item.representedObject = self.interface
    return item
  }()

  lazy var menuItem: NSMenuItem = {
    let item = NSMenuItem(title: "Loading...", action: nil, keyEquivalent: "")
    item.representedObject = self.interface
    item.target = Controller.self
    item.tag = 42

    if self.interface.softMAC.isValid {
      item.title = self.interface.softMAC.humanReadable
      SoftMACCache.remember(BSDName: self.interface.BSDName, address: self.interface.softMAC.formatted)
    } else {
      if let address = SoftMACCache.address(BSDName: self.interface.BSDName) {
        item.title = address
      } else {
        item.title = self.interface.hardMAC.formatted
      }
    }
    item.state = self.interface.hasOriginalMAC ? 1 : 0
    item.onStateImage = #imageLiteral(resourceName: "InterfaceLeaking")
    item.submenu = self.subMenuItem()
    return item
  }()

  private func subMenuItem() -> NSMenu {
    let submenu: NSMenu = NSMenu()

    let vendorName = MACVendors.name(address: interface.softMAC)

    let vendorNameItem = NSMenuItem(title: vendorName, action: nil, keyEquivalent: "")
    submenu.addItem(vendorNameItem)
    submenu.addItem(NSMenuItem.separator())

    if (interface.isPoweredOffWifi) {
      let poweredOffItem = NSMenuItem(title: "Powered off", action: nil, keyEquivalent: "")
      submenu.addItem(poweredOffItem)
    } else {

      let action = Config.instance.actionForInterface(interface.hardMAC)

      let ignoreItem: NSMenuItem = NSMenuItem(title: "Do nothing", action: #selector(Controller.ignoreInterface), keyEquivalent: "")
      ignoreItem.representedObject = interface
      ignoreItem.target = Controller.self
      ignoreItem.state = action == Interface.Action.ignore ? 1 : 0
      submenu.addItem(ignoreItem)

      let randomizeItem: NSMenuItem = NSMenuItem(title: "Random", action: #selector(Controller.randomizeInterface), keyEquivalent: "")
      randomizeItem.representedObject = interface
      randomizeItem.target = Controller.self
      randomizeItem.state = action == Interface.Action.random ? 1 : 0
      submenu.addItem(randomizeItem)

      let specifyItem: NSMenuItem = NSMenuItem(title: "Define manually", action: #selector(Controller.specifyInterface), keyEquivalent: "")
      specifyItem.representedObject = interface
      specifyItem.target = Controller.self
      specifyItem.state = action == Interface.Action.specify ? 1 : 0
      submenu.addItem(specifyItem)

      let originalizeItem: NSMenuItem = NSMenuItem(title: "Keep original", action: #selector(Controller.originalizeInterface), keyEquivalent: "")
      originalizeItem.representedObject = interface
      originalizeItem.target = Controller.self
      originalizeItem.state = action == Interface.Action.original ? 1 : 0
      submenu.addItem(originalizeItem)

      let forgetItem: NSMenuItem = NSMenuItem(title: "Default", action: #selector(Controller.forgetInterface), keyEquivalent: "")
      forgetItem.representedObject = interface
      forgetItem.target = Controller.self
      forgetItem.state = action == Interface.Action.undefined ? 1 : 0
      submenu.addItem(forgetItem)

      submenu.addItem(NSMenuItem.separator())

      let hardMACItem: NSMenuItem = NSMenuItem(title: interface.hardMAC.formatted, action: nil, keyEquivalent: "")
      submenu.addItem(hardMACItem)
}
    return submenu
  }

}

{'fraction_non_alphanumeric': 0.102679792179382, 'fraction_numerical': 0.0038282745419742957, 'mean_word_length': 3.7623697916666665, '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': '3938954', 'n_tokens_mistral': 2121, 'n_tokens_neox': 2012, 'n_words': 437}