]> khamidou — GitHub mirrors - electron.git/commitdiff
Add Menu API. (WIP)
authorCheng Zhao <zcbenz@gmail.com>
Mon, 6 May 2013 12:27:09 +0000 (20:27 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 6 May 2013 12:27:09 +0000 (20:27 +0800)
atom.gyp
browser/api/atom_api_menu.cc [new file with mode: 0644]
browser/api/atom_api_menu.h [new file with mode: 0644]
browser/api/atom_api_menu_mac.h [new file with mode: 0644]
browser/api/atom_api_menu_mac.mm [new file with mode: 0644]
common/api/atom_extensions.h

index cebb03c2900ae9caa71307ec34d9eacfbd83832c..ee92b68aa8c5241769d85c25676e703cf7d530f4 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
       'browser/api/atom_api_event.h',
       'browser/api/atom_api_event_emitter.cc',
       'browser/api/atom_api_event_emitter.h',
+      'browser/api/atom_api_menu.cc',
+      'browser/api/atom_api_menu.h',
+      'browser/api/atom_api_menu_mac.h',
+      'browser/api/atom_api_menu_mac.mm',
       'browser/api/atom_api_window.cc',
       'browser/api/atom_api_window.h',
       'browser/api/atom_browser_bindings.cc',
diff --git a/browser/api/atom_api_menu.cc b/browser/api/atom_api_menu.cc
new file mode 100644 (file)
index 0000000..3c82c58
--- /dev/null
@@ -0,0 +1,62 @@
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "browser/api/atom_api_menu.h"
+
+namespace atom {
+
+namespace api {
+
+Menu::Menu(v8::Handle<v8::Object> wrapper)
+    : EventEmitter(wrapper),
+      model_(new ui::SimpleMenuModel(this)) {
+}
+
+Menu::~Menu() {
+}
+
+bool Menu::IsCommandIdChecked(int command_id) const {
+  return false;
+}
+
+bool Menu::IsCommandIdEnabled(int command_id) const {
+  return true;
+}
+
+bool Menu::GetAcceleratorForCommandId(int command_id,
+                                    ui::Accelerator* accelerator) {
+  return false;
+}
+
+void Menu::ExecuteCommand(int command_id, int event_flags) {
+}
+
+// static
+v8::Handle<v8::Value> Menu::New(const v8::Arguments &args) {
+  v8::HandleScope scope;
+
+  if (!args.IsConstructCall())
+    return node::ThrowError("Require constructor call");
+
+  Menu::Create(args.This());
+
+  return args.This();
+}
+
+// static
+void Menu::Initialize(v8::Handle<v8::Object> target) {
+  v8::HandleScope scope;
+
+  v8::Local<v8::FunctionTemplate> t(v8::FunctionTemplate::New(Menu::New));
+  t->InstanceTemplate()->SetInternalFieldCount(1);
+  t->SetClassName(v8::String::NewSymbol("Menu"));
+
+  target->Set(v8::String::NewSymbol("Menu"), t->GetFunction());
+}
+
+}  // namespace api
+
+}  // namespace atom
+
+NODE_MODULE(atom_browser_menu, atom::api::Menu::Initialize)
diff --git a/browser/api/atom_api_menu.h b/browser/api/atom_api_menu.h
new file mode 100644 (file)
index 0000000..aaabc92
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_BROWSER_API_ATOM_API_MENU_H_
+#define ATOM_BROWSER_API_ATOM_API_MENU_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "browser/api/atom_api_event_emitter.h"
+#include "ui/base/models/simple_menu_model.h"
+
+namespace atom {
+
+namespace api {
+
+class Menu : public EventEmitter,
+             public ui::SimpleMenuModel::Delegate {
+ public:
+  virtual ~Menu();
+
+  static Menu* Create(v8::Handle<v8::Object> wrapper);
+
+  static void Initialize(v8::Handle<v8::Object> target);
+
+ protected:
+  explicit Menu(v8::Handle<v8::Object> wrapper);
+
+  // ui::SimpleMenuModel::Delegate implementations:
+  virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
+  virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
+  virtual bool GetAcceleratorForCommandId(
+      int command_id,
+      ui::Accelerator* accelerator) OVERRIDE;
+  virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
+
+  scoped_ptr<ui::SimpleMenuModel> model_;
+
+ private:
+  static v8::Handle<v8::Value> New(const v8::Arguments &args);
+
+  DISALLOW_COPY_AND_ASSIGN(Menu);
+};
+
+}  // namespace api
+
+}  // namespace atom
+
+#endif  // ATOM_BROWSER_API_ATOM_API_MENU_H_
diff --git a/browser/api/atom_api_menu_mac.h b/browser/api/atom_api_menu_mac.h
new file mode 100644 (file)
index 0000000..1181dda
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_BROWSER_API_ATOM_API_MENU_MAC_H_
+#define ATOM_BROWSER_API_ATOM_API_MENU_MAC_H_
+
+#include "browser/api/atom_api_menu.h"
+
+#import "chrome/browser/ui/cocoa/menu_controller.h"
+
+namespace atom {
+
+namespace api {
+
+class MenuMac : public Menu {
+ public:
+  explicit MenuMac(v8::Handle<v8::Object> wrapper);
+  virtual ~MenuMac();
+
+ protected:
+  scoped_nsobject<MenuController> controller_;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(MenuMac);
+};
+
+}  // namespace api
+
+}  // namespace atom
+
+#endif  // ATOM_BROWSER_API_ATOM_API_MENU_MAC_H_
diff --git a/browser/api/atom_api_menu_mac.mm b/browser/api/atom_api_menu_mac.mm
new file mode 100644 (file)
index 0000000..1668903
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "browser/api/atom_api_menu_mac.h"
+
+namespace atom {
+
+namespace api {
+
+MenuMac::MenuMac(v8::Handle<v8::Object> wrapper)
+    : Menu(wrapper),
+      controller_([[MenuController alloc] initWithModel:model_.get()
+                                 useWithPopUpButtonCell:NO]) {
+}
+
+MenuMac::~MenuMac() {
+}
+
+// static
+Menu* Menu::Create(v8::Handle<v8::Object> wrapper) {
+  return new MenuMac(wrapper);
+}
+
+}  // namespace api
+
+}  // namespace atom
index fdff420122d4b5fea1b0f756addea5ece1f47b15..ac4059fb1d49a64e57990782a0daf5a6f285d3f7 100644 (file)
@@ -12,6 +12,7 @@ NODE_EXT_LIST_START
 NODE_EXT_LIST_ITEM(atom_browser_app)
 NODE_EXT_LIST_ITEM(atom_browser_dialog)
 NODE_EXT_LIST_ITEM(atom_browser_ipc)
+NODE_EXT_LIST_ITEM(atom_browser_menu)
 NODE_EXT_LIST_ITEM(atom_browser_window)
 
 // Module names start with `atom_renderer_` can only be used by renderer