]> khamidou — GitHub mirrors - electron.git/commitdiff
Assign actions for roles on Windows and Linux
authorCheng Zhao <zcbenz@gmail.com>
Tue, 1 Sep 2015 15:34:32 +0000 (23:34 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 2 Sep 2015 01:42:17 +0000 (09:42 +0800)
atom/browser/api/lib/browser-window.coffee
atom/browser/api/lib/menu-item.coffee
atom/browser/api/lib/menu.coffee

index 68b5932a93b49c82468df38238d9e35572eef6a1..283e99641f477910ce9943767654158ecaba3bc3 100644 (file)
@@ -62,6 +62,12 @@ BrowserWindow::loadUrl = -> @webContents.loadUrl.apply @webContents, arguments
 BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
 
 # Be compatible with old API.
+BrowserWindow::undo = -> @webContents.undo()
+BrowserWindow::redo = -> @webContents.redo()
+BrowserWindow::cut = -> @webContents.cut()
+BrowserWindow::copy = -> @webContents.copy()
+BrowserWindow::paste = -> @webContents.paste()
+BrowserWindow::selectAll = -> @webContents.selectAll()
 BrowserWindow::restart = -> @webContents.reload()
 BrowserWindow::getUrl = -> @webContents.getUrl()
 BrowserWindow::reload = -> @webContents.reload.apply @webContents, arguments
index 7663b32996d8184b5bb9cd346fe2a374dd4cc858..cfefeec4edbbffb889ace0a9fabf44c414da5807 100644 (file)
@@ -3,6 +3,17 @@ v8Util = process.atomBinding 'v8_util'
 
 nextCommandId = 0
 
+# Maps role to methods of webContents
+rolesMap =
+  undo: 'undo'
+  redo: 'redo'
+  cut: 'cut'
+  copy: 'copy'
+  paste: 'paste'
+  selectall: 'selectAll'
+  minimize: 'minimize'
+  close: 'close'
+
 class MenuItem
   @types = ['normal', 'separator', 'submenu', 'checkbox', 'radio']
 
@@ -28,12 +39,14 @@ class MenuItem
     throw new Error("Unknown menu type #{@type}") if MenuItem.types.indexOf(@type) is -1
 
     @commandId = ++nextCommandId
-    @click = =>
+    @click = (focusedWindow) =>
       # Manually flip the checked flags when clicked.
       @checked = !@checked if @type in ['checkbox', 'radio']
 
-      if typeof click is 'function'
-        click this, BrowserWindow.getFocusedWindow()
+      if @role and rolesMap[@role] and process.platform isnt 'darwin'
+        focusedWindow?[rolesMap[@role]]()
+      else if typeof click is 'function'
+        click this, focusedWindow
       else if typeof @selector is 'string'
         Menu.sendActionToFirstResponder @selector
 
index 35335ffcebe5057b7b88c1ac807076246e22cd9d..3595ba1fe7db3384747e8221064ab257fc89b048 100644 (file)
@@ -67,7 +67,8 @@ Menu::_init = ->
     isCommandIdVisible: (commandId) => @commandsMap[commandId]?.visible
     getAcceleratorForCommandId: (commandId) => @commandsMap[commandId]?.accelerator
     getIconForCommandId: (commandId) => @commandsMap[commandId]?.icon
-    executeCommand: (commandId) => @commandsMap[commandId]?.click()
+    executeCommand: (commandId) =>
+      @commandsMap[commandId]?.click BrowserWindow.getFocusedWindow()
     menuWillShow: =>
       # Make sure radio groups have at least one menu item seleted.
       for id, group of @groupsMap