mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-08 16:19:17 +03:00
Fix handling of submenus in conversion of legacy context menu format
This commit is contained in:
parent
eff70b07d9
commit
6ce5356505
@ -150,3 +150,25 @@ describe "ContextMenuManager", ->
|
||||
|
||||
shouldDisplay = false
|
||||
expect(contextMenu.templateForEvent(dispatchedEvent)).toEqual []
|
||||
|
||||
it "allows items to be specified in the legacy format for now", ->
|
||||
contextMenu.add '.parent':
|
||||
'A': 'a'
|
||||
'Separator 1': '-'
|
||||
'B':
|
||||
'C': 'c'
|
||||
'Separator 2': '-'
|
||||
'D': 'd'
|
||||
|
||||
expect(contextMenu.templateForElement(parent)).toEqual [
|
||||
{label: 'A', command: 'a'}
|
||||
{type: 'separator'}
|
||||
{
|
||||
label: 'B'
|
||||
submenu: [
|
||||
{label: 'C', command: 'c'}
|
||||
{type: 'separator'}
|
||||
{label: 'D', command: 'd'}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
@ -85,7 +85,7 @@ class ContextMenuManager
|
||||
for key, value of itemsBySelector
|
||||
unless _.isArray(value)
|
||||
Grim.deprecate("The format for declaring context menu items has changed. Please consult the documentation.")
|
||||
itemsBySelector = @convertLegacyItems(itemsBySelector, devMode)
|
||||
itemsBySelector = @convertLegacyItemsBySelector(itemsBySelector, devMode)
|
||||
|
||||
addedItemSets = []
|
||||
|
||||
@ -126,13 +126,18 @@ class ContextMenuManager
|
||||
|
||||
template
|
||||
|
||||
convertLegacyItems: (legacyItems, devMode) ->
|
||||
convertLegacyItemsBySelector: (legacyItemsBySelector, devMode) ->
|
||||
itemsBySelector = {}
|
||||
|
||||
for selector, commandsByLabel of legacyItems
|
||||
itemsBySelector[selector] = items = []
|
||||
for selector, commandsByLabel of legacyItemsBySelector
|
||||
itemsBySelector[selector] = @convertLegacyItems(commandsByLabel, devMode)
|
||||
|
||||
for label, commandOrSubmenu of commandsByLabel
|
||||
itemsBySelector
|
||||
|
||||
convertLegacyItems: (legacyItems, devMode) ->
|
||||
items = []
|
||||
|
||||
for label, commandOrSubmenu of legacyItems
|
||||
if typeof commandOrSubmenu is 'object'
|
||||
items.push({label, submenu: @convertLegacyItems(commandOrSubmenu, devMode), devMode})
|
||||
else if commandOrSubmenu is '-'
|
||||
@ -140,7 +145,7 @@ class ContextMenuManager
|
||||
else
|
||||
items.push({label, command: commandOrSubmenu, devMode})
|
||||
|
||||
itemsBySelector
|
||||
items
|
||||
|
||||
# Public: Request a context menu to be displayed.
|
||||
#
|
||||
|
@ -42,7 +42,6 @@ normalizeLabel = (label) ->
|
||||
else
|
||||
label.replace(/\&/g, '')
|
||||
|
||||
|
||||
cloneMenuItem = (item) ->
|
||||
item = _.pick(item, 'type', 'label', 'command', 'submenu', 'commandDetail')
|
||||
if item.submenu?
|
||||
|
Loading…
Reference in New Issue
Block a user