Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// MARK: - Menus
override func buildMenu(with builder: UIMenuBuilder) {
super.buildMenu(with: builder)
builder.insertChild(AppDelegate.fileMenu(), atStartOfMenu: .file)
builder.insertChild(AppDelegate.viewMenu(), atStartOfMenu: .view)
builder.remove(menu: .format)
builder.remove(menu: .toolbar)
builder.remove(menu: .help)
builder.insertSibling(AppDelegate.helpMenu(), afterMenu: .window)
}
override func validate(_ command: UICommand) {
switch command.action {
case #selector(contactSupport):
command.attributes = canContactSupport() ? [] : .disabled
case #selector(insertNewWord):
command.attributes = canInsertNewWord() ? [] : .disabled
case #selector(insertNewFolder):
command.attributes = canInsertNewFolder() ? [] : .disabled
case #selector(openVocabularyPacks):
command.attributes = canOpenVocabularyPacks() ? [] : .disabled
case #selector(openFavorites):
command.attributes = canOpenFavorites() ? [] : .disabled
default:
break
}
}
// MARK: -
class func fileMenu() -> UIMenu {
let newWord = UIKeyCommand(title: NSLocalizedString("New Word", comment: ""), image: nil, action: #selector(AppDelegate.insertNewWord), input: "n", modifierFlags: .command, propertyList: nil)
let newFolder = UIKeyCommand(title: NSLocalizedString("New Folder", comment: ""), image: nil, action: #selector(AppDelegate.insertNewFolder), input: "n", modifierFlags: [.command, .shift], propertyList: nil)
return UIMenu(title: "", image: nil, identifier: UIMenu.Identifier("com.studioamanga.memorii.menus.file"), options: .displayInline, children: [newWord, newFolder])
}
class func viewMenu() -> UIMenu {
let favoritesCommand =
UIKeyCommand(title: NSLocalizedString("Favorites", comment: ""), image: nil, action: #selector(AppDelegate.openFavorites), input: "1", modifierFlags: .command, propertyList: nil)
let vocabularyCommand =
UIKeyCommand(title: NSLocalizedString("Vocabulary Packs", comment: ""), image: nil, action: #selector(AppDelegate.openVocabularyPacks), input: "2", modifierFlags: .command, propertyList: nil)
let viewMenu = UIMenu(title: "", image: nil, identifier: UIMenu.Identifier("com.studioamanga.memorii.menus.views"), options: .displayInline, children: [favoritesCommand, vocabularyCommand])
return viewMenu
}
class func helpMenu() -> UIMenu {
let contact = UIKeyCommand(title: NSLocalizedString("Contact Support", comment: ""), image: nil, action: #selector(AppDelegate.contactSupport), input: "", modifierFlags: [], propertyList: nil)
return UIMenu(title: NSLocalizedString("Help", comment: ""), image: nil, identifier: UIMenu.Identifier("com.studioamanga.memorii.menus.help"), options: [], children: [contact])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.