mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-07 23:59:22 +03:00
Add devMode flag to individual items
This commit is contained in:
parent
f8225a6441
commit
c5b395579b
@ -95,6 +95,15 @@ describe "ContextMenuManager", ->
|
||||
{label: 'C', command: 'c'}
|
||||
]
|
||||
|
||||
it "excludes items marked for display in devMode unless in dev mode", ->
|
||||
disposable1 = contextMenu.add
|
||||
'.grandchild': [{label: 'A', command: 'a', devMode: true}, {label: 'B', command: 'b', devMode: false}]
|
||||
|
||||
expect(contextMenu.templateForElement(grandchild)).toEqual [{label: 'B', command: 'b'}]
|
||||
|
||||
contextMenu.devMode = true
|
||||
expect(contextMenu.templateForElement(grandchild)).toEqual [{label: 'A', command: 'a'}, {label: 'B', command: 'b'}]
|
||||
|
||||
describe "executeBuildHandlers", ->
|
||||
menuTemplate = [
|
||||
label: 'label'
|
||||
|
@ -47,9 +47,11 @@ class ContextMenuManager
|
||||
# * `options` An optional {Object} with the following keys:
|
||||
# * `devMode` Determines whether the entries should only be shown when
|
||||
# the window is in dev mode.
|
||||
add: (name, object, {devMode}={}) ->
|
||||
add: (items) ->
|
||||
unless typeof arguments[0] is 'object'
|
||||
return @add(@convertLegacyItems(object), {devMode})
|
||||
legacyItems = arguments[1]
|
||||
devMode = arguments[2]?.devMode
|
||||
return @add(@convertLegacyItems(legacyItems, devMode))
|
||||
|
||||
itemsBySelector = _.deepClone(arguments[0])
|
||||
devMode = arguments[1]?.devMode ? false
|
||||
@ -75,13 +77,16 @@ class ContextMenuManager
|
||||
.sort (a, b) -> a.compare(b)
|
||||
|
||||
for {items} in matchingItemSets
|
||||
MenuHelpers.merge(template, item) for item in items
|
||||
for item in items
|
||||
continue if item.devMode and not @devMode
|
||||
item = _.pick(item, 'type', 'label', 'command')
|
||||
MenuHelpers.merge(template, item)
|
||||
|
||||
currentTarget = currentTarget.parentElement
|
||||
|
||||
template
|
||||
|
||||
convertLegacyItems: (legacyItems) ->
|
||||
convertLegacyItems: (legacyItems, devMode) ->
|
||||
itemsBySelector = {}
|
||||
|
||||
for selector, commandsByLabel of legacyItems
|
||||
@ -89,11 +94,11 @@ class ContextMenuManager
|
||||
|
||||
for label, commandOrSubmenu of commandsByLabel
|
||||
if typeof commandOrSubmenu is 'object'
|
||||
items.push({label, submenu: @convertLegacyItems(commandOrSubmenu)})
|
||||
items.push({label, submenu: @convertLegacyItems(commandOrSubmenu, devMode), devMode})
|
||||
else if commandOrSubmenu is '-'
|
||||
items.push({type: 'separator'})
|
||||
else
|
||||
items.push({label, command: commandOrSubmenu})
|
||||
items.push({label, command: commandOrSubmenu, devMode})
|
||||
|
||||
itemsBySelector
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user