mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Merge pull request #1116 from atom/windows-menus
Make Windows menus more Native(tm), fixes #1085
This commit is contained in:
@@ -14,7 +14,7 @@ class MenuManager
|
||||
# Private:
|
||||
constructor: ({@resourcePath}) ->
|
||||
@template = []
|
||||
atom.keymap.on 'bundled-keymaps-loaded', => @loadCoreItems()
|
||||
atom.keymap.on 'bundled-keymaps-loaded', => @loadPlatformItems()
|
||||
|
||||
# Public: Adds the given item definition to the existing template.
|
||||
#
|
||||
@@ -37,22 +37,21 @@ class MenuManager
|
||||
@sendToBrowserProcess(@template, keystrokesByCommand)
|
||||
|
||||
# Private
|
||||
loadCoreItems: ->
|
||||
loadPlatformItems: ->
|
||||
menusDirPath = path.join(@resourcePath, 'menus')
|
||||
menuPaths = fs.listSync(menusDirPath, ['cson', 'json'])
|
||||
for menuPath in menuPaths
|
||||
data = CSON.readFileSync(menuPath)
|
||||
@add(data.menu)
|
||||
platformMenuPath = fs.resolve(menusDirPath, process.platform, ['cson', 'json'])
|
||||
data = CSON.readFileSync(platformMenuPath)
|
||||
@add(data.menu)
|
||||
|
||||
# Private: Merges an item in a submenu aware way such that new items are always
|
||||
# appended to the bottom of existing menus where possible.
|
||||
merge: (menu, item) ->
|
||||
item = _.deepClone(item)
|
||||
|
||||
if item.submenu? and match = _.find(menu, (i) -> i.submenu? and i.label == item.label)
|
||||
if item.submenu? and match = _.find(menu, (i) => i.submenu? and @normalizeLabel(i.label) == @normalizeLabel(item.label))
|
||||
@merge(match.submenu, i) for i in item.submenu
|
||||
else
|
||||
menu.push(item) unless _.find(menu, (i) -> i.label == item.label)
|
||||
menu.push(item) unless _.find(menu, (i) => @normalizeLabel(i.label) == @normalizeLabel(item.label))
|
||||
|
||||
# Private: OSX can't handle displaying accelerators for multiple keystrokes.
|
||||
# If they are sent across, it will stop processing accelerators for the rest
|
||||
@@ -71,3 +70,10 @@ class MenuManager
|
||||
sendToBrowserProcess: (template, keystrokesByCommand) ->
|
||||
keystrokesByCommand = @filterMultipleKeystroke(keystrokesByCommand)
|
||||
ipc.sendChannel 'update-application-menu', template, keystrokesByCommand
|
||||
|
||||
# Private
|
||||
normalizeLabel: (label) ->
|
||||
if process.platform is 'win32'
|
||||
label.replace(/\&/g, '')
|
||||
else
|
||||
label
|
||||
|
||||
Reference in New Issue
Block a user