All Projects → mikekazakov → Mgkmenuwithfilter

mikekazakov / Mgkmenuwithfilter

Licence: mit
A macOS menu that supports items filtration via keyboard input

Projects that are alternatives of or similar to Mgkmenuwithfilter

Iostips
记录iOS(Swift)开发中的一些知识点、小技巧
Stars: ✭ 376 (+1346.15%)
Mutual labels:  cocoa
Vimr
Project VimR is a Neovim GUI for macOS. The goal is to build an editor that uses Neovim inside with many of the convenience GUI features similar to those present in modern editors. We mainly use Swift, but also use C/Objective-C when where appropriate.
Stars: ✭ 5,524 (+21146.15%)
Mutual labels:  cocoa
Nswindowstyles
A showcase of the many different styles of windows possible with NSWindow on macOS
Stars: ✭ 801 (+2980.77%)
Mutual labels:  cocoa
Githubupdates
Cocoa framework to install application updates from GitHub releases.
Stars: ✭ 393 (+1411.54%)
Mutual labels:  cocoa
Midiapps
MIDI apps for Mac OS X: MIDI Monitor and SysEx Librarian.
Stars: ✭ 488 (+1776.92%)
Mutual labels:  cocoa
Orsserialport
Serial port library for Objective-C and Swift macOS apps
Stars: ✭ 609 (+2242.31%)
Mutual labels:  cocoa
Realm Tasks
To Do app built with Realm, inspired by Clear for iOS
Stars: ✭ 369 (+1319.23%)
Mutual labels:  cocoa
Jcggcolorslider
Colorful NSSlider subclass
Stars: ✭ 19 (-26.92%)
Mutual labels:  cocoa
Brisk
✨Cross-platform set of tools for building native UIs with Reason/OCaml
Stars: ✭ 518 (+1892.31%)
Mutual labels:  cocoa
Scrooge
A Thrift parser/generator
Stars: ✭ 724 (+2684.62%)
Mutual labels:  cocoa
Seaglass
A truly native Matrix client for macOS - written in Swift/Cocoa, with E2E encryption support
Stars: ✭ 428 (+1546.15%)
Mutual labels:  cocoa
Swiftai
SwiftAI, write Swift code smart. SwiftAI can generate Model class from JSON now. Codable and HandyJSON is supported. More features will be add.
Stars: ✭ 470 (+1707.69%)
Mutual labels:  cocoa
Latest
A small utility app for macOS that makes sure you know about all the latest updates to the apps you use.
Stars: ✭ 657 (+2426.92%)
Mutual labels:  cocoa
Segmentedprogressbar
Snapchat / Instagram Stories like progress indicator
Stars: ✭ 376 (+1346.15%)
Mutual labels:  cocoa
Wfcolorcode
NSColor extension adding ability to handle HSL color space and CSS3 style color codes
Stars: ✭ 16 (-38.46%)
Mutual labels:  cocoa
Sentry Cocoa
The official Sentry SDK for iOS, tvOS, macOS, watchOS
Stars: ✭ 370 (+1323.08%)
Mutual labels:  cocoa
Strongbox
A KeePass/Password Safe Client for iOS and OS X
Stars: ✭ 586 (+2153.85%)
Mutual labels:  cocoa
Privilegedtaskrunner
Swift 4 example code for creating privileged helpers in macOS
Stars: ✭ 19 (-26.92%)
Mutual labels:  cocoa
Cocoaheads Ukraine
Collection of talks given at the CocoaHeads Ukraine meetups.
Stars: ✭ 18 (-30.77%)
Mutual labels:  cocoa
Xit
Mac OS X Git GUI
Stars: ✭ 700 (+2592.31%)
Mutual labels:  cocoa

MGKMenuWithFilter

A macOS menu that supports items filtration via keyboard input

About

MGKMenuWithFilter is a class that lets the user show only menu items which have a title with a query string inside. The query string can be changed via keyboard typing while the menu instance is shown. Here's the example:

How to use it

Add the MGKMenuWithFilter source code to the project and programmatically populate a menu instance as usually, but allocate a MGKMenuWithFilter object instead of NSMenu. Here's the code snippet for the example above:

@IBAction func showPopUpMenu(_ sender: Any) {
    let folder = NSURL.fileURL(withPath: "/Library/Desktop Pictures")
    let all_files = try! FileManager.default.contentsOfDirectory(at:folder,
                                                                 includingPropertiesForKeys:nil,
                                                                 options:.skipsSubdirectoryDescendants)
    let jpg_files = all_files.filter() { $0.absoluteString.hasSuffix(".jpg") }
    let menu = MGKMenuWithFilter.init(title: "Pictures")!
    for picture in jpg_files {
        let item = NSMenuItem()
        item.title = picture.lastPathComponent
        item.action = #selector(showPicture(_:))
        item.target = self
        let size = NSMakeSize(32, 32)
        let preview = QLThumbnailImageCreate(nil, picture as CFURL!, size, nil as CFDictionary!)
        if preview != nil  {
            item.image = NSImage.init(cgImage:preview!.takeUnretainedValue(), size: size)
            preview!.release()
        }
        item.representedObject = picture
        menu.addItem(item)
    }
    menu.popUp(positioning: nil,
               at: NSMakePoint(0, pushMeButton.bounds.size.height),
               in: pushMeButton)
}

More

MacOS versions supported: [10.8-10.12] are fully supported, 10.7 is partially supported.

Rationale and design notes: https://kazakov.life/2017/05/18/hacking-nsmenu-keyboard-navigation/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].