}
bool Menu::IsCommandIdChecked(int command_id) const {
+ v8::HandleScope scope;
return CallDelegate(v8::False(),
handle(),
"isCommandIdChecked",
}
bool Menu::IsCommandIdEnabled(int command_id) const {
+ v8::HandleScope scope;
return CallDelegate(v8::True(),
handle(),
"isCommandIdEnabled",
}
bool Menu::IsCommandIdVisible(int command_id) const {
+ v8::HandleScope scope;
return CallDelegate(v8::True(),
handle(),
"isCommandIdVisible",
bool Menu::GetAcceleratorForCommandId(int command_id,
ui::Accelerator* accelerator) {
+ v8::HandleScope scope;
v8::Handle<v8::Value> shortcut = CallDelegate(v8::Undefined(),
handle(),
"getAcceleratorForCommandId",
}
bool Menu::IsItemForCommandIdDynamic(int command_id) const {
+ v8::HandleScope scope;
return CallDelegate(v8::False(),
handle(),
"isItemForCommandIdDynamic",
}
string16 Menu::GetLabelForCommandId(int command_id) const {
+ v8::HandleScope scope;
return V8ValueToUTF16(CallDelegate(v8::False(),
handle(),
"getLabelForCommandId",
}
string16 Menu::GetSublabelForCommandId(int command_id) const {
+ v8::HandleScope scope;
return V8ValueToUTF16(CallDelegate(v8::False(),
handle(),
"getSubLabelForCommandId",
}
void Menu::ExecuteCommand(int command_id, int event_flags) {
+ v8::HandleScope scope;
v8::Handle<v8::Value> args[] = {
v8::String::New("execute"),
v8::Integer::New(command_id)
v8::Handle<v8::Value> Menu::InsertSubMenu(const v8::Arguments &args) {
UNWRAP_MEMNU_AND_CHECK;
- // FIXME should rely on js code to keep a reference of submenu and check
- // the constructor type of menu object.
-
if (!args[0]->IsNumber() ||
!args[1]->IsNumber() ||
!args[2]->IsString() ||
NODE_SET_PROTOTYPE_METHOD(t, "popup", Popup);
target->Set(v8::String::NewSymbol("Menu"), t->GetFunction());
+
+ NODE_SET_METHOD(target, "setApplicationMenu", SetApplicationMenu);
}
} // namespace api
#include "base/message_loop.h"
#include "base/mac/scoped_sending_event.h"
#include "browser/native_window.h"
-#import "chrome/browser/ui/cocoa/menu_controller.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
}
}
+// static
+v8::Handle<v8::Value> Menu::SetApplicationMenu(const v8::Arguments &args) {
+ v8::HandleScope scope;
+
+ if (!args[0]->IsObject())
+ return node::ThrowTypeError("Bad argument");
+
+ MenuMac* menu = ObjectWrap::Unwrap<MenuMac>(args[0]->ToObject());
+ if (!menu)
+ return node::ThrowError("Menu is destroyed");
+
+ scoped_nsobject<MenuController> menu_controller(
+ [[MenuController alloc] initWithModel:menu->model_.get()
+ useWithPopUpButtonCell:NO]);
+ [NSApp setMainMenu:[menu_controller menu]];
+
+ // Ensure the menu_controller_ is destroyed after main menu is set.
+ menu_controller.swap(menu->menu_controller_);
+
+ return v8::Undefined();
+}
+
// static
Menu* Menu::Create(v8::Handle<v8::Object> wrapper) {
return new MenuMac(wrapper);
EventEmitter = require('events').EventEmitter
BrowserWindow = require 'browser_window'
-Menu = process.atomBinding('menu').Menu
+bindings = process.atomBinding 'menu'
+Menu = bindings.Menu
Menu::__proto__ = EventEmitter.prototype
popup = Menu::popup
Menu::appendSeparator = (args...) -> @insertSeparator -1, args...
Menu::appendSubMenu = (args...) -> @insertSubMenu -1, args...
+Menu.setApplicationMenu = (menu) ->
+ throw new TypeError('Invalid menu') unless menu?.constructor is Menu
+ bindings.setApplicationMenu menu
+
module.exports = Menu