Creating an macOS Macstream Application for 1Password

I am trying to create a macOS menubar application that will have a text box as the first element. The text box will serve as a search bar to filter other items that will be displayed below it.

It should look very similar to 1password:

1password

This is what I managed:

mine

I accomplished this by creating Status menuwith three elements and creating my own view for the first element in the menu.

However, this approach does not seem to solve my problem. When you click cmd + Ain the search field, the focus moves to the next menu item. This is the default behavior for NSMenu.

So my question is: is it right to come up with a single-user application or is there a better one?

+5
1

.

. NSTextField performKeyEquivalent

class AXCVTextField: NSTextField {

    override func performKeyEquivalent(with event: NSEvent) -> Bool {
        if event.modifierFlags.contains(.command),
          let key = event.charactersIgnoringModifiers {
            var action : String?
            switch key {
            case "x": action = "cut:"
            case "c": action = "copy:"
            case "v": action = "paste:"
            case "a": action = "selectAll:"
            default:
                break
            }
            if let action = action {
                return NSApp.sendAction(Selector(action), to:self.window!.firstResponder, from:self)
            }
        }
        return super.performKeyEquivalent(with: event)
    }
}
+3

Source: https://habr.com/ru/post/1687918/


All Articles