]> khamidou — GitHub mirrors - electron.git/commitdiff
specify positioning item for popup menus
authorevgenyzinoviev <me@ch1p.com>
Fri, 22 Jan 2016 02:18:04 +0000 (03:18 +0100)
committerevgenyzinoviev <me@ch1p.com>
Fri, 22 Jan 2016 02:18:27 +0000 (03:18 +0100)
atom/browser/api/atom_api_menu.h
atom/browser/api/atom_api_menu_mac.h
atom/browser/api/atom_api_menu_mac.mm
atom/browser/api/atom_api_menu_views.cc
atom/browser/api/atom_api_menu_views.h
atom/browser/api/lib/menu.js
docs/api/menu.md

index 17bb9073a719bdccae9687031d502e1707824ef4..d3452628100250224e00dd3a8e575f121ebab277 100644 (file)
@@ -52,7 +52,8 @@ class Menu : public mate::TrackableObject<Menu>,
   void MenuWillShow(ui::SimpleMenuModel* source) override;
 
   virtual void Popup(Window* window) = 0;
-  virtual void PopupAt(Window* window, int x, int y) = 0;
+  virtual void PopupAt(Window* window, int x, int y,
+      int positioningItem = 0) = 0;
 
   scoped_ptr<AtomMenuModel> model_;
   Menu* parent_;
index 5a086776a63962a015368e5194f8d7dfc8052e4a..e71198315b68cef1a42c2c334e081a3a92610b49 100644 (file)
@@ -20,7 +20,7 @@ class MenuMac : public Menu {
   MenuMac();
 
   void Popup(Window* window) override;
-  void PopupAt(Window* window, int x, int y) override;
+  void PopupAt(Window* window, int x, int y, int positioningItem = 0) override;
 
   base::scoped_nsobject<AtomMenuController> menu_controller_;
 
index 071753218d6a069d7f7acadc24b0ecbc755b906b..7e505ccd9d3403ff6ec4f53d18277d83756d26ab 100644 (file)
@@ -50,7 +50,7 @@ void MenuMac::Popup(Window* window) {
                    forView:web_contents->GetContentNativeView()];
 }
 
-void MenuMac::PopupAt(Window* window, int x, int y) {
+void MenuMac::PopupAt(Window* window, int x, int y, int positioningItem) {
   NativeWindow* native_window = window->window();
   if (!native_window)
     return;
@@ -64,7 +64,13 @@ void MenuMac::PopupAt(Window* window, int x, int y) {
   NSView* view = web_contents->GetContentNativeView();
 
   // Show the menu.
-  [menu popUpMenuPositioningItem:[menu itemAtIndex:0]
+  if (positioningItem >= [menu numberOfItems]) {
+    positioningItem = [menu numberOfItems] - 1;
+  }
+  if (positioningItem < 0) {
+    positioningItem = 0;
+  }
+  [menu popUpMenuPositioningItem:[menu itemAtIndex:positioningItem]
                       atLocation:NSMakePoint(x, [view frame].size.height - y)
                           inView:view];
 }
index 45904dd8c033ed3e33b954eb5651d7d8385bbebf..67b55d5e988897c2d196f0f588b2c7fc2d7a076f 100644 (file)
@@ -20,7 +20,7 @@ void MenuViews::Popup(Window* window) {
   PopupAtPoint(window, gfx::Screen::GetNativeScreen()->GetCursorScreenPoint());
 }
 
-void MenuViews::PopupAt(Window* window, int x, int y) {
+void MenuViews::PopupAt(Window* window, int x, int y, int positioningItem) {
   NativeWindow* native_window = static_cast<NativeWindow*>(window->window());
   if (!native_window)
     return;
index de0d2e8b01446304f6c272868191d933f4a6eecf..9e306b4e72b727e1722cc17d2d037ec244790994 100644 (file)
@@ -18,7 +18,7 @@ class MenuViews : public Menu {
 
  protected:
   void Popup(Window* window) override;
-  void PopupAt(Window* window, int x, int y) override;
+  void PopupAt(Window* window, int x, int y, int positioningItem = 0) override;
 
  private:
   void PopupAtPoint(Window* window, const gfx::Point& point);
index 69ad4fec051ddf8f21636f9d9c3f2c1ec9dabdb3..d6b276ddc1ea8ccd09ba0318755d23ba8a2b94cc 100644 (file)
@@ -158,7 +158,7 @@ Menu.prototype._init = function() {
   };
 };
 
-Menu.prototype.popup = function(window, x, y) {
+Menu.prototype.popup = function(window, x, y, positioningItem) {
   if ((window != null ? window.constructor : void 0) !== BrowserWindow) {
     // Shift.
     y = x;
@@ -166,7 +166,7 @@ Menu.prototype.popup = function(window, x, y) {
     window = BrowserWindow.getFocusedWindow();
   }
   if ((x != null) && (y != null)) {
-    return this._popupAt(window, x, y);
+    return this._popupAt(window, x, y, positioningItem || 0);
   } else {
     return this._popup(window);
   }
index 38069140ad30b145872132019fe75856586e01a0..f0cfaccd7f1a793c08d9413140ac5981cfd9c333 100644 (file)
@@ -237,15 +237,18 @@ Generally, the `template` is just an array of `options` for constructing a
 You can also attach other fields to the element of the `template` and they
 will become properties of the constructed menu items.
 
-### `Menu.popup([browserWindow, x, y])`
+### `Menu.popup([browserWindow, x, y, positioningItem])`
 
 * `browserWindow` BrowserWindow (optional)
 * `x` Number (optional)
 * `y` Number (**required** if `x` is used)
+* `positioningItem` Number (optional) _OS X_
 
 Pops up this menu as a context menu in the `browserWindow`. You
 can optionally provide a `x,y` coordinate to place the menu at, otherwise it
-will be placed at the current mouse cursor position.
+will be placed at the current mouse cursor position. `positioningItem` is the
+index of the menu item to be positioned under the mouse cursor at the specified
+coordinates (only supported on OS X).
 
 ### `Menu.append(menuItem)`