namespace api {
Menu::Menu()
- : model_(new ui::SimpleMenuModel(this)),
+ : model_(new AtomMenuModel(this)),
parent_(NULL) {
}
#include <string>
#include "atom/browser/api/atom_api_window.h"
+#include "atom/browser/ui/atom_menu_model.h"
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
-#include "ui/base/models/simple_menu_model.h"
#include "native_mate/wrappable.h"
namespace atom {
namespace api {
class Menu : public mate::Wrappable,
- public ui::SimpleMenuModel::Delegate {
+ public AtomMenuModel::Delegate {
public:
static mate::Wrappable* Create();
static void SendActionToFirstResponder(const std::string& action);
#endif
- ui::SimpleMenuModel* model() const { return model_.get(); }
+ AtomMenuModel* model() const { return model_.get(); }
protected:
Menu();
// mate::Wrappable:
void AfterInit(v8::Isolate* isolate) override;
- // ui::SimpleMenuModel::Delegate implementations:
+ // ui::SimpleMenuModel::Delegate:
bool IsCommandIdChecked(int command_id) const override;
bool IsCommandIdEnabled(int command_id) const override;
bool IsCommandIdVisible(int command_id) const override;
virtual void Popup(Window* window) = 0;
virtual void PopupAt(Window* window, int x, int y) = 0;
- scoped_ptr<ui::SimpleMenuModel> model_;
+ scoped_ptr<AtomMenuModel> model_;
Menu* parent_;
private:
namespace mate {
template<>
-struct Converter<ui::SimpleMenuModel*> {
+struct Converter<atom::AtomMenuModel*> {
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
- ui::SimpleMenuModel** out) {
+ atom::AtomMenuModel** out) {
// null would be tranfered to NULL.
if (val->IsNull()) {
*out = nullptr;
--- /dev/null
+// Copyright (c) 2015 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "atom/browser/ui/atom_menu_model.h"
+
+namespace atom {
+
+AtomMenuModel::AtomMenuModel(Delegate* delegate)
+ : ui::SimpleMenuModel(delegate),
+ delegate_(delegate) {
+}
+
+AtomMenuModel::~AtomMenuModel() {
+}
+
+void AtomMenuModel::MenuClosed() {
+ ui::SimpleMenuModel::MenuClosed();
+ FOR_EACH_OBSERVER(Observer, observers_, MenuClosed());
+}
+
+} // namespace atom
--- /dev/null
+// Copyright (c) 2015 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_BROWSER_UI_ATOM_MENU_MODEL_H_
+#define ATOM_BROWSER_UI_ATOM_MENU_MODEL_H_
+
+#include "base/observer_list.h"
+#include "ui/base/models/simple_menu_model.h"
+
+namespace atom {
+
+class AtomMenuModel : public ui::SimpleMenuModel {
+ public:
+ class Delegate : public ui::SimpleMenuModel::Delegate {
+ public:
+ virtual ~Delegate() {}
+ };
+
+ class Observer {
+ public:
+ virtual ~Observer() {}
+
+ // Notifies the menu has been closed.
+ virtual void MenuClosed() {}
+ };
+
+ explicit AtomMenuModel(Delegate* delegate);
+ virtual ~AtomMenuModel();
+
+ void AddObserver(Observer* obs) { observers_.AddObserver(obs); }
+ void RemoveObserver(Observer* obs) { observers_.RemoveObserver(obs); }
+
+ // ui::SimpleMenuModel:
+ void MenuClosed() override;
+
+ private:
+ Delegate* delegate_; // weak ref.
+
+ ObserverList<Observer> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(AtomMenuModel);
+};
+
+} // namespace atom
+
+#endif // ATOM_BROWSER_UI_ATOM_MENU_MODEL_H_
#import "atom/browser/ui/cocoa/atom_menu_controller.h"
+#include "atom/browser/ui/atom_menu_model.h"
#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/accelerators/platform_accelerator_cocoa.h"
#include "ui/base/l10n/l10n_util_mac.h"
-#include "ui/base/models/simple_menu_model.h"
#include "ui/events/cocoa/cocoa_event_utils.h"
#include "ui/gfx/image/image.h"
[item setTarget:nil];
[item setAction:nil];
ui::MenuModel* submenuModel = model->GetSubmenuModelAt(index);
- NSMenu* submenu =
- [self menuFromModel:(ui::SimpleMenuModel*)submenuModel];
+ NSMenu* submenu = [self menuFromModel:submenuModel];
[submenu setTitle:[item title]];
[item setSubmenu:submenu];
'atom/browser/ui/accelerator_util.h',
'atom/browser/ui/accelerator_util_mac.mm',
'atom/browser/ui/accelerator_util_views.cc',
+ 'atom/browser/ui/atom_menu_model.cc',
+ 'atom/browser/ui/atom_menu_model.h',
'atom/browser/ui/cocoa/atom_menu_controller.h',
'atom/browser/ui/cocoa/atom_menu_controller.mm',
'atom/browser/ui/cocoa/event_processing_window.h',