Add `menu` parameter for Tray.popUpContextMenu
authorCheng Zhao <zcbenz@gmail.com>
Wed, 2 Dec 2015 10:43:11 +0000 (18:43 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 2 Dec 2015 10:43:11 +0000 (18:43 +0800)
atom/browser/api/atom_api_tray.cc
atom/browser/ui/tray_icon.cc
atom/browser/ui/tray_icon.h
atom/browser/ui/tray_icon_cocoa.h
atom/browser/ui/tray_icon_cocoa.mm
atom/browser/ui/win/notify_icon.cc
atom/browser/ui/win/notify_icon.h
docs/api/tray.md

index 5e32657..1e1c7c3 100644 (file)
@@ -137,9 +137,11 @@ void Tray::DisplayBalloon(mate::Arguments* args,
 }
 
 void Tray::PopUpContextMenu(mate::Arguments* args) {
+  Menu* menu = nullptr;
+  args->GetNext(&menu);
   gfx::Point pos;
   args->GetNext(&pos);
-  tray_icon_->PopUpContextMenu(pos);
+  tray_icon_->PopUpContextMenu(pos, menu ? menu->model() : nullptr);
 }
 
 void Tray::SetContextMenu(mate::Arguments* args, Menu* menu) {
index 1696aab..60923c2 100644 (file)
@@ -26,7 +26,8 @@ void TrayIcon::DisplayBalloon(const gfx::Image& icon,
                               const base::string16& contents) {
 }
 
-void TrayIcon::PopUpContextMenu(const gfx::Point& pos) {
+void TrayIcon::PopUpContextMenu(const gfx::Point& pos,
+                                ui::SimpleMenuModel* menu_model) {
 }
 
 void TrayIcon::NotifyClicked(const gfx::Rect& bounds, int modifiers) {
index bc29acd..c80ff08 100644 (file)
@@ -47,7 +47,9 @@ class TrayIcon {
                               const base::string16& title,
                               const base::string16& contents);
 
-  virtual void PopUpContextMenu(const gfx::Point& pos);
+  // Popups the menu.
+  virtual void PopUpContextMenu(const gfx::Point& pos,
+                                ui::SimpleMenuModel* menu_model);
 
   // Set the context menu for this icon.
   virtual void SetContextMenu(ui::SimpleMenuModel* menu_model) = 0;
index 7781c93..59e2241 100644 (file)
@@ -29,7 +29,8 @@ class TrayIconCocoa : public TrayIcon,
   void SetToolTip(const std::string& tool_tip) override;
   void SetTitle(const std::string& title) override;
   void SetHighlightMode(bool highlight) override;
-  void PopUpContextMenu(const gfx::Point& pos) override;
+  void PopUpContextMenu(const gfx::Point& pos,
+                        ui::SimpleMenuModel* menu_model) override;
   void SetContextMenu(ui::SimpleMenuModel* menu_model) override;
 
  protected:
index e25f8ab..5005234 100644 (file)
@@ -338,7 +338,8 @@ void TrayIconCocoa::SetHighlightMode(bool highlight) {
   [status_item_view_ setHighlight:highlight];
 }
 
-void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos) {
+void TrayIconCocoa::PopUpContextMenu(const gfx::Point& pos,
+                                     ui::SimpleMenuModel* menu_model) {
   [status_item_view_ popUpContextMenu];
 }
 
index b2ca4bc..133ab06 100644 (file)
@@ -66,7 +66,7 @@ void NotifyIcon::HandleClickEvent(const gfx::Point& cursor_pos,
     return;
   } else if (!double_button_click) {  // single right click
     if (menu_model_)
-      PopUpContextMenu(cursor_pos);
+      PopUpContextMenu(cursor_pos, menu_model_);
     else
       NotifyRightClicked(gfx::Rect(rect), modifiers);
   }
@@ -142,7 +142,8 @@ void NotifyIcon::DisplayBalloon(const gfx::Image& icon,
     LOG(WARNING) << "Unable to create status tray balloon.";
 }
 
-void NotifyIcon::PopUpContextMenu(const gfx::Point& pos) {
+void NotifyIcon::PopUpContextMenu(const gfx::Point& pos,
+                                  ui::SimpleMenuModel* menu_model) {
   // Returns if context menu isn't set.
   if (!menu_model_)
     return;
index d368dec..8ee6000 100644 (file)
@@ -52,7 +52,8 @@ class NotifyIcon : public TrayIcon {
   void DisplayBalloon(const gfx::Image& icon,
                       const base::string16& title,
                       const base::string16& contents) override;
-  void PopUpContextMenu(const gfx::Point& pos) override;
+  void PopUpContextMenu(const gfx::Point& pos,
+                        ui::SimpleMenuModel* menu_model) override;
   void SetContextMenu(ui::SimpleMenuModel* menu_model) override;
 
  private:
index f230c32..08a4363 100644 (file)
@@ -187,12 +187,16 @@ when the tray icon is clicked. Defaults to true.
 
 Displays a tray balloon.
 
-### `Tray.popUpContextMenu([position])` _OS X_ _Windows_
+### `Tray.popUpContextMenu([menu, position])` _OS X_ _Windows_
 
-* `position` Object (optional)- The pop up position.
+* `menu` Menu (optional)
+* `position` Object (optional) - The pop up position.
   * `x` Integer
   * `y` Integer
 
+Popups the context menu of tray icon. When `menu` is passed, the `menu` will
+showed instead of the tray's context menu.
+
 The `position` is only available on Windows, and it is (0, 0) by default.
 
 ### `Tray.setContextMenu(menu)`