Skip to content

Commit

Permalink
Merge pull request #3 from zaru/exec-by-enter
Browse files Browse the repository at this point in the history
Implemented to execute the first menu when the Enter key is pressed
  • Loading branch information
zaru authored May 20, 2020
2 parents 6b81b4e + 0dd2349 commit 02bbf7c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions menuffy/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ extension AppDelegate: NSTextFieldDelegate {
let source2 = CGEventSource(stateID: CGEventSourceStateID.hidSystemState)
let downArrowEvent = CGEvent(keyboardEventSource: source2, virtualKey: 0x7d, keyDown: true)
downArrowEvent?.post(tap: CGEventTapLocation.cghidEventTap)
} else if commandSelector == #selector(NSResponder.insertNewline(_:)) {
let menuItem = menuView.filterdMenuItems[0]
NSApp.sendAction(menuItem.action!, to: menuItem.target, from: menuItem)
}
return false
}
Expand Down
4 changes: 4 additions & 0 deletions menuffy/MainMenu/MenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class MenuView: NSView {
var appMenu: NSMenu = NSMenu()
private (set) public var allElements: [AXUIElement] = []
var allMenuItems: [NSMenuItem] = []
var filterdMenuItems: [NSMenuItem] = []
var menuIndex: Int = 0
var topLevelMenuNum: Int = 0

Expand All @@ -27,6 +28,8 @@ class MenuView: NSView {
}

func filterMenuItem(keyword: String) {

filterdMenuItems = []
// 検索時は既存のトップレベルメニューを隠す、空なら表示する
let hidden = keyword == "" ? false : true
for index in 1...topLevelMenuNum {
Expand All @@ -47,6 +50,7 @@ class MenuView: NSView {
if item.title.localizedCaseInsensitiveContains(keyword) {
guard let copyItem = item.copy() as? NSMenuItem else { continue }
appMenu.addItem(copyItem)
filterdMenuItems.append(copyItem)
}
}
}
Expand Down

0 comments on commit 02bbf7c

Please sign in to comment.