Skip to content

Instantly share code, notes, and snippets.

@joefiorini
Created July 11, 2013 13:34
Show Gist options
  • Save joefiorini/5975478 to your computer and use it in GitHub Desktop.
Save joefiorini/5975478 to your computer and use it in GitHub Desktop.
class AppDelegate
def applicationDidFinishLaunching(notification)
MainMenu.build!
MainMenu[:app].subscribe :quit do |_|
NSApp.terminate(self)
end
MainMenu[:file].subscribe :new do |_|
puts "new"
end
MainMenu[:file].subscribe :close do |_|
puts "close"
end
MainMenu[:file].subscribe :open do |_|
puts "open"
end
end
end
class MainMenu
extend DrinkMenu::MenuBuilder
menuItem :quit do |item|
item.title = 'Quit'
item.keyEquivalent = 'q'
end
menuItem :open do |item|
item.title = 'Open'
item.keyEquivalent = 'o'
end
menuItem :new, title: 'New'
menuItem :close do |item|
item.title = 'Close'
item.keyEquivalent = 'w'
end
mainMenu :app, title: 'Blah' do
quit
end
mainMenu :file, title: 'File' do
new
open
___
close
end
end
@jamonholmgren
Copy link

I like this, but I wonder if a hash syntax would work better (at least for me).

class MainMenu
  extend DrinkMenu::MenuBuilder

  def menu_data
    {
      app: [
        { title: 'Quit', key: 'q' }
      ],
      file: [
        { title: "Open", key: 'o' },
        { title: "New" },
        ___,
        { title: "Close", key: "w" }
      ]
    }
  end 
end

@jamonholmgren
Copy link

Discussion on issue: joefiorini/drink-menu#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment