Mailspring/internal_packages/account-sidebar/lib/sidebar-commands.coffee
Juan Tejada 2380e1eefa Update sidebar to hold state for selected account
- Ensures that it displays the correct set of sidebar items even when
  the perspective changes
- Also sets up hotkeys to switch currently focused accounts
2016-01-21 14:13:48 -08:00

50 lines
1.4 KiB
CoffeeScript

_ = require 'underscore'
{AccountStore, MenuHelpers} = require 'nylas-exports'
SidebarActions = require './sidebar-actions'
class SidebarCommands
@_registerCommands: ->
commands = {}
allKey = "application:select-account-0"
commands[allKey] = => SidebarActions.focusAccounts(AccountStore.accounts())
[1..8].forEach (index) =>
account = AccountStore.accounts()[index - 1]
return unless account
key = "application:select-account-#{index}"
commands[key] = => SidebarActions.focusAccounts([account])
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