Skip to content

Commit

Permalink
Honor created() function for an item in a submenu.
Browse files Browse the repository at this point in the history
Fixes atom#10483.
  • Loading branch information
bolinfest committed Jan 19, 2016
1 parent f8d2076 commit 9917ed3
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/context-menu-manager.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,9 @@ class ContextMenuManager

for itemSet in matchingItemSets
for item in itemSet.items
continue if item.devMode and not @devMode
item = Object.create(item)
if typeof item.shouldDisplay is 'function'
continue unless item.shouldDisplay(event)
item.created?(event)
MenuHelpers.merge(currentTargetItems, item, itemSet.specificity)
itemForEvent = @cloneItemForEvent(item, event)
if itemForEvent
MenuHelpers.merge(currentTargetItems, itemForEvent, itemSet.specificity)

for item in currentTargetItems
MenuHelpers.merge(template, item, false)
Expand All @@ -150,6 +147,19 @@ class ContextMenuManager

template

# Returns an object compatible with `::add()` or `null`.
cloneItemForEvent: (item, event) ->
return null if item.devMode and not @devMode
item = Object.create(item)
if typeof item.shouldDisplay is 'function'
return null unless item.shouldDisplay(event)
item.created?(event)
if Array.isArray(item.submenu)
item.submenu = item.submenu
.map((item) => @cloneItemForEvent(item, event))
.filter((item) -> item isnt null)
return item

convertLegacyItemsBySelector: (legacyItemsBySelector, devMode) ->
itemsBySelector = {}

Expand Down

0 comments on commit 9917ed3

Please sign in to comment.