// 右击菜单
let rightMenu = NSMenu.init()
rightMenu.setAccessibilityEnabled(true)
let uploadFileItem = rightMenu.addItem(withTitle: "上传", action: #selector(uploadByRightMenu), keyEquivalent: "")
uploadFileItem.isEnabled = true
uploadFileItem.target = self
let createFolderItem = rightMenu.addItem(withTitle: "新建文件夹", action: #selector(createFolderByRightMenu), keyEquivalent: "")
createFolderItem.isEnabled = true
createFolderItem.target = self
// 加隔线
rightMenu.addItem(NSMenuItem.separator())
let reloadFileItem = rightMenu.addItem(withTitle: "刷新", action: #selector(reloadByRightMenu), keyEquivalent: "")
reloadFileItem.isEnabled = true
reloadFileItem.target = self
let sortFileItem = rightMenu.addItem(withTitle: "排序", action: nil, keyEquivalent: "")
sortFileItem.isEnabled = true
let sortMenu = NSMenu.init()
let sortByNameItem = sortMenu.addItem(withTitle: "名称", action: #selector(sortNameByRightMenu), keyEquivalent: "")
sortByNameItem.isEnabled = true
sortByNameItem.target = self
let sortBySizeItem = sortMenu.addItem(withTitle: "大小", action: #selector(sortSizeByRightMenu), keyEquivalent: "")
sortBySizeItem.isEnabled = true
sortBySizeItem.target = self
let sortByTimeItem = sortMenu.addItem(withTitle: "修改时间", action: #selector(sortTimeByRightMenu), keyEquivalent: "")
sortByTimeItem.isEnabled = true
sortByTimeItem.target = self
// 为某个item设置二级目录
sortFileItem.submenu = sortMenu
switch FileCoreManager.getCurr().getModule().getSortType() {
case FileModule.FileSortBasis.name:
// 左侧增加对勾
sortByNameItem.state = 1
case FileModule.FileSortBasis.size:
// 左侧增加对勾
sortBySizeItem.state = 1
case FileModule.FileSortBasis.mtime:
// 左侧增加对勾
sortByTimeItem.state = 1
}
rightMenu.autoenablesItems = false
// 获取鼠标在Window的位置
let point = event.locationInWindow
// 设置弹出位置并且弹出
rightMenu.popUp(positioning: nil, at: NSPoint.init(x: point.x - 134, y: 600 - point.y), in: self.collectionView)
mac学习-NSMenu右击弹框操作
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 原文链接:弹框体系总结:模态弹框和非模态弹框 - 优设-UISDC 概要:弹框主要完成信息传递和用户反馈两大功能。...
- 警告框 iOS中警告框给用户警告或提示,最多两个按钮,超过两个就应该使用操作表。由于在iOS中警告框是模态的,因此...