use cocoa::appkit::NSMenu; use cocoa::appkit::NSMenuItem; use cocoa::base::{nil, selector}; use cocoa::foundation::NSAutoreleasePool; use lutt::application::Application; use lutt::macos::ns_string; use lutt::menu::Menu; use lutt::menu_item::MenuItem; use lutt::window::Window; /// Adds the main menu. unsafe fn add_main_menu(application: &Application) { // Create the main menu. let main_menu = Menu::new(); // Set the main menu. application.set_main_menu(&main_menu); // Create the application menu item. let application_menu_item = MenuItem::new(); // Add the application menu item to the main menu. main_menu.add_menu_item(&application_menu_item); // Create the application sub-menu. let application_sub_menu = Menu::new(); // "Quit" { // TODO let quit_label = ns_string(&format!("Quit {}", application.name())); let quit_action = selector("terminate:"); let quit_key = ns_string("q"); let quit_item = NSMenuItem::alloc(nil) .initWithTitle_action_keyEquivalent_(quit_label, quit_action, quit_key) .autorelease(); // TODO application_sub_menu.ns_menu().addItem_(quit_item); } // Set the application sub-menu to the application menu item. // TODO application_menu_item .ns_menu_item() .setSubmenu_(application_sub_menu.ns_menu()); } fn main() { let application_name = "Simple"; unsafe { // Create an application. let application = Application::new(application_name.to_owned()); add_main_menu(&application); // Create the main window. let _main_window = Window::new(application_name, 500.0, 300.0); // Bring the application focused to front. application.focus(); // Run the application. application.run(); } }