Assign actions for roles on Windows and Linux
This commit is contained in:
parent
d830badc57
commit
7d07f10c25
3 changed files with 24 additions and 4 deletions
|
@ -62,6 +62,12 @@ BrowserWindow::loadUrl = -> @webContents.loadUrl.apply @webContents, arguments
|
||||||
BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
|
BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
|
||||||
|
|
||||||
# Be compatible with old API.
|
# 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::restart = -> @webContents.reload()
|
||||||
BrowserWindow::getUrl = -> @webContents.getUrl()
|
BrowserWindow::getUrl = -> @webContents.getUrl()
|
||||||
BrowserWindow::reload = -> @webContents.reload.apply @webContents, arguments
|
BrowserWindow::reload = -> @webContents.reload.apply @webContents, arguments
|
||||||
|
|
|
@ -3,6 +3,17 @@ v8Util = process.atomBinding 'v8_util'
|
||||||
|
|
||||||
nextCommandId = 0
|
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
|
class MenuItem
|
||||||
@types = ['normal', 'separator', 'submenu', 'checkbox', 'radio']
|
@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
|
throw new Error("Unknown menu type #{@type}") if MenuItem.types.indexOf(@type) is -1
|
||||||
|
|
||||||
@commandId = ++nextCommandId
|
@commandId = ++nextCommandId
|
||||||
@click = =>
|
@click = (focusedWindow) =>
|
||||||
# Manually flip the checked flags when clicked.
|
# Manually flip the checked flags when clicked.
|
||||||
@checked = !@checked if @type in ['checkbox', 'radio']
|
@checked = !@checked if @type in ['checkbox', 'radio']
|
||||||
|
|
||||||
if typeof click is 'function'
|
if @role and rolesMap[@role] and process.platform isnt 'darwin'
|
||||||
click this, BrowserWindow.getFocusedWindow()
|
focusedWindow?[rolesMap[@role]]()
|
||||||
|
else if typeof click is 'function'
|
||||||
|
click this, focusedWindow
|
||||||
else if typeof @selector is 'string'
|
else if typeof @selector is 'string'
|
||||||
Menu.sendActionToFirstResponder @selector
|
Menu.sendActionToFirstResponder @selector
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,8 @@ Menu::_init = ->
|
||||||
isCommandIdVisible: (commandId) => @commandsMap[commandId]?.visible
|
isCommandIdVisible: (commandId) => @commandsMap[commandId]?.visible
|
||||||
getAcceleratorForCommandId: (commandId) => @commandsMap[commandId]?.accelerator
|
getAcceleratorForCommandId: (commandId) => @commandsMap[commandId]?.accelerator
|
||||||
getIconForCommandId: (commandId) => @commandsMap[commandId]?.icon
|
getIconForCommandId: (commandId) => @commandsMap[commandId]?.icon
|
||||||
executeCommand: (commandId) => @commandsMap[commandId]?.click()
|
executeCommand: (commandId) =>
|
||||||
|
@commandsMap[commandId]?.click BrowserWindow.getFocusedWindow()
|
||||||
menuWillShow: =>
|
menuWillShow: =>
|
||||||
# Make sure radio groups have at least one menu item seleted.
|
# Make sure radio groups have at least one menu item seleted.
|
||||||
for id, group of @groupsMap
|
for id, group of @groupsMap
|
||||||
|
|
Loading…
Add table
Reference in a new issue