]> khamidou — GitHub mirrors - electron.git/commitdiff
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 5e32657f008a305f6c67c7d2d17970b1a3f7e0d7..1e1c7c304d8287a55302ac139f8b4781574327a6 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 1696aab276b198c57fb54ab23e122b92ffdf07fb..60923c2ad0a6489774247a6e9b0b5c376920f5e1 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 bc29acd8a255ac4bef434083188ed7428c4e7b89..c80ff08d6a52daa84252c0a0369bc474d07245df 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 7781c93a1c03705462189d607dad6843752ac934..59e2241aa480470e99d1be3f7b4cdcf4cf31c5aa 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 e25f8ab5c201aaa2bb1c9ec1c1febe501c0fd3d4..5005234ab13129567d2a64ca50175e97888b4476 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 b2ca4bceedd121cc901b329906436b483c27a7dd..133ab068da7be52cacf6d84536298e9ff45fde55 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 d368dec71327873cce9522f561b7bcf4b06fd938..8ee600033e946baafb25f054a2d0a7e7e7063a21 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 f230c324ec08ba6de9aec1ae267933dcc612fa2a..08a43638be1433d55080e7de997c2d7e525778b1 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)`