first pass at menu event emission
This commit is contained in:
parent
39554566cc
commit
3399480304
6 changed files with 29 additions and 5 deletions
|
@ -153,6 +153,14 @@ bool Menu::IsVisibleAt(int index) const {
|
||||||
return model_->IsVisibleAt(index);
|
return model_->IsVisibleAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Menu::OnMenuWillClose() {
|
||||||
|
Emit("menu-will-close");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::OnMenuWillShow() {
|
||||||
|
Emit("menu-will-show");
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void Menu::BuildPrototype(v8::Isolate* isolate,
|
void Menu::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::FunctionTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
|
|
|
@ -60,6 +60,10 @@ class Menu : public mate::TrackableObject<Menu>,
|
||||||
std::unique_ptr<AtomMenuModel> model_;
|
std::unique_ptr<AtomMenuModel> model_;
|
||||||
Menu* parent_;
|
Menu* parent_;
|
||||||
|
|
||||||
|
// Observable:
|
||||||
|
void OnMenuWillClose() override;
|
||||||
|
void OnMenuWillShow() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InsertItemAt(int index, int command_id, const base::string16& label);
|
void InsertItemAt(int index, int command_id, const base::string16& label);
|
||||||
void InsertSeparatorAt(int index);
|
void InsertSeparatorAt(int index);
|
||||||
|
|
|
@ -42,8 +42,16 @@ bool AtomMenuModel::GetAcceleratorAtWithParams(
|
||||||
|
|
||||||
void AtomMenuModel::MenuWillClose() {
|
void AtomMenuModel::MenuWillClose() {
|
||||||
ui::SimpleMenuModel::MenuWillClose();
|
ui::SimpleMenuModel::MenuWillClose();
|
||||||
for (Observer& observer : observers_)
|
for (Observer& observer : observers_) {
|
||||||
observer.MenuWillClose();
|
observer.OnMenuWillClose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AtomMenuModel::MenuWillShow() {
|
||||||
|
ui::SimpleMenuModel::MenuWillShow();
|
||||||
|
for (Observer& observer : observers_) {
|
||||||
|
observer.OnMenuWillShow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AtomMenuModel* AtomMenuModel::GetSubmenuModelAt(int index) {
|
AtomMenuModel* AtomMenuModel::GetSubmenuModelAt(int index) {
|
||||||
|
|
|
@ -36,8 +36,11 @@ class AtomMenuModel : public ui::SimpleMenuModel {
|
||||||
public:
|
public:
|
||||||
virtual ~Observer() {}
|
virtual ~Observer() {}
|
||||||
|
|
||||||
|
// Notifies the menu will open.
|
||||||
|
virtual void OnMenuWillShow() {}
|
||||||
|
|
||||||
// Notifies the menu has been closed.
|
// Notifies the menu has been closed.
|
||||||
virtual void MenuWillClose() {}
|
virtual void OnMenuWillClose() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit AtomMenuModel(Delegate* delegate);
|
explicit AtomMenuModel(Delegate* delegate);
|
||||||
|
@ -54,6 +57,7 @@ class AtomMenuModel : public ui::SimpleMenuModel {
|
||||||
|
|
||||||
// ui::SimpleMenuModel:
|
// ui::SimpleMenuModel:
|
||||||
void MenuWillClose() override;
|
void MenuWillClose() override;
|
||||||
|
void MenuWillShow() override;
|
||||||
|
|
||||||
using SimpleMenuModel::GetSubmenuModelAt;
|
using SimpleMenuModel::GetSubmenuModelAt;
|
||||||
AtomMenuModel* GetSubmenuModelAt(int index);
|
AtomMenuModel* GetSubmenuModelAt(int index);
|
||||||
|
|
|
@ -35,7 +35,7 @@ class TrayIconCocoa : public TrayIcon,
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// AtomMenuModel::Observer:
|
// AtomMenuModel::Observer:
|
||||||
void MenuWillClose() override;
|
void OnMenuWillClose() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Atom custom view for NSStatusItem.
|
// Atom custom view for NSStatusItem.
|
||||||
|
|
|
@ -461,7 +461,7 @@ gfx::Rect TrayIconCocoa::GetBounds() {
|
||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayIconCocoa::MenuWillClose() {
|
void TrayIconCocoa::OnMenuWillClose() {
|
||||||
[status_item_view_ setNeedsDisplay:YES];
|
[status_item_view_ setNeedsDisplay:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue