allow multiple labels for the same command

This commit is contained in:
Philip Schatz 2014-06-17 23:36:59 -04:00
parent 2fdcf7a124
commit 624c0bf9f1
2 changed files with 16 additions and 2 deletions

View File

@ -24,12 +24,26 @@ describe "ContextMenuManager", ->
contextMenu.add 'file-path', contextMenu.add 'file-path',
'.selector': '.selector':
'another label': 'command' 'label': 'command'
expect(contextMenu.definitions['.selector'][0].label).toEqual 'label' expect(contextMenu.definitions['.selector'][0].label).toEqual 'label'
expect(contextMenu.definitions['.selector'][0].command).toEqual 'command' expect(contextMenu.definitions['.selector'][0].command).toEqual 'command'
expect(contextMenu.definitions['.selector'][1]).toBeUndefined() expect(contextMenu.definitions['.selector'][1]).toBeUndefined()
it 'allows duplicate commands with different labels', ->
contextMenu.add 'file-path',
'.selector':
'label': 'command'
contextMenu.add 'file-path',
'.selector':
'another label': 'command'
expect(contextMenu.definitions['.selector'][0].label).toEqual 'label'
expect(contextMenu.definitions['.selector'][0].command).toEqual 'command'
expect(contextMenu.definitions['.selector'][1].label).toEqual 'another label'
expect(contextMenu.definitions['.selector'][1].command).toEqual 'command'
it "loads submenus", -> it "loads submenus", ->
contextMenu.add 'file-path', contextMenu.add 'file-path',
'.selector': '.selector':

View File

@ -60,7 +60,7 @@ class ContextMenuManager
# editor is in dev mode. # editor is in dev mode.
addBySelector: (selector, definition, {devMode}={}) -> addBySelector: (selector, definition, {devMode}={}) ->
definitions = if devMode then @devModeDefinitions else @definitions definitions = if devMode then @devModeDefinitions else @definitions
unless _.findWhere(definitions[selector], command: definition.command) unless _.findWhere(definitions[selector], definition)
(definitions[selector] ?= []).push(definition) (definitions[selector] ?= []).push(definition)
# Returns definitions which match the element and devMode. # Returns definitions which match the element and devMode.