2016-01-22 06:12:56 +08:00
|
|
|
_ = require 'underscore'
|
2016-02-03 02:50:12 +08:00
|
|
|
{AccountStore, MenuHelpers} = require 'nylas-exports'
|
|
|
|
SidebarActions = require './sidebar-actions'
|
2016-01-22 06:12:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
class SidebarCommands
|
|
|
|
|
2016-01-23 03:58:24 +08:00
|
|
|
@_focusAccounts: (accounts) ->
|
2016-02-03 02:50:12 +08:00
|
|
|
SidebarActions.focusAccounts(accounts)
|
2016-01-23 03:58:24 +08:00
|
|
|
NylasEnv.show() unless NylasEnv.isVisible()
|
|
|
|
|
2016-01-22 06:12:56 +08:00
|
|
|
@_registerCommands: ->
|
|
|
|
commands = {}
|
2016-01-23 03:58:24 +08:00
|
|
|
|
2016-01-22 06:12:56 +08:00
|
|
|
allKey = "application:select-account-0"
|
2016-01-23 03:58:24 +08:00
|
|
|
commands[allKey] = @_focusAccounts.bind(@, AccountStore.accounts())
|
|
|
|
|
2016-01-22 06:12:56 +08:00
|
|
|
[1..8].forEach (index) =>
|
|
|
|
account = AccountStore.accounts()[index - 1]
|
|
|
|
return unless account
|
|
|
|
key = "application:select-account-#{index}"
|
2016-01-23 03:58:24 +08:00
|
|
|
commands[key] = @_focusAccounts.bind(@, [account])
|
|
|
|
|
2016-01-22 06:12:56 +08:00
|
|
|
NylasEnv.commands.add('body', commands)
|
|
|
|
|
|
|
|
@_registerMenuItems: ->
|
|
|
|
windowMenu = _.find NylasEnv.menu.template, ({label}) ->
|
|
|
|
MenuHelpers.normalizeLabel(label) is 'Window'
|
|
|
|
return unless windowMenu
|
|
|
|
|
|
|
|
submenu = _.reject windowMenu.submenu, (item) -> item.account
|
|
|
|
return unless submenu
|
|
|
|
|
|
|
|
idx = _.findIndex submenu, ({type}) -> type is 'separator'
|
|
|
|
return unless idx > 0
|
|
|
|
|
|
|
|
menuItems = [{
|
|
|
|
label: 'All Accounts'
|
|
|
|
command: "application:select-account-0"
|
|
|
|
account: true
|
|
|
|
}]
|
|
|
|
menuItems = menuItems.concat AccountStore.accounts().map((item, idx) =>
|
|
|
|
label: item.emailAddress,
|
|
|
|
command: "application:select-account-#{idx + 1}",
|
|
|
|
account: true
|
|
|
|
)
|
|
|
|
|
|
|
|
submenu.splice(idx + 1, 0, menuItems...)
|
|
|
|
windowMenu.submenu = submenu
|
|
|
|
NylasEnv.menu.update()
|
|
|
|
|
|
|
|
@register: ->
|
|
|
|
@_registerCommands()
|
|
|
|
@_registerMenuItems()
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = SidebarCommands
|