2015-09-23 05:43:08 +08:00
|
|
|
React = require 'react'
|
2016-01-22 06:12:56 +08:00
|
|
|
{Actions} = require 'nylas-exports'
|
|
|
|
{RetinaImg} = require 'nylas-component-kit'
|
2016-02-06 06:24:07 +08:00
|
|
|
AccountCommands = require '../account-commands'
|
2015-09-23 05:43:08 +08:00
|
|
|
|
2016-01-20 15:42:50 +08:00
|
|
|
|
2015-09-23 05:43:08 +08:00
|
|
|
class AccountSwitcher extends React.Component
|
|
|
|
@displayName: 'AccountSwitcher'
|
|
|
|
|
2016-01-20 15:42:50 +08:00
|
|
|
@propTypes:
|
|
|
|
accounts: React.PropTypes.array.isRequired
|
|
|
|
focusedAccounts: React.PropTypes.array.isRequired
|
|
|
|
|
|
|
|
|
2016-02-05 06:48:15 +08:00
|
|
|
_makeMenuTemplate: =>
|
2016-02-06 06:24:07 +08:00
|
|
|
template = AccountCommands.menuTemplate(
|
|
|
|
@props.accounts,
|
|
|
|
@props.focusedAccounts,
|
|
|
|
clickHandlers: true
|
|
|
|
)
|
2016-02-05 06:48:15 +08:00
|
|
|
template = template.concat [
|
|
|
|
{type: 'separator'}
|
|
|
|
{label: 'Manage Accounts...', click: @_onManageAccounts}
|
|
|
|
]
|
|
|
|
return template
|
2015-09-25 10:07:50 +08:00
|
|
|
|
2016-02-05 06:48:15 +08:00
|
|
|
# Handlers
|
2015-09-23 05:43:08 +08:00
|
|
|
|
2016-02-05 06:48:15 +08:00
|
|
|
_onManageAccounts: =>
|
|
|
|
Actions.switchPreferencesTab('Accounts')
|
|
|
|
Actions.openPreferences()
|
2015-09-23 05:43:08 +08:00
|
|
|
|
2016-02-05 06:48:15 +08:00
|
|
|
_onShowMenu: =>
|
|
|
|
remote = require('electron').remote
|
|
|
|
Menu = remote.Menu
|
|
|
|
menu = Menu.buildFromTemplate(@_makeMenuTemplate())
|
|
|
|
menu.popup()
|
2015-09-23 05:43:08 +08:00
|
|
|
|
2016-01-20 15:42:50 +08:00
|
|
|
render: =>
|
2016-02-05 06:48:15 +08:00
|
|
|
<div className="account-switcher" onMouseDown={@_onShowMenu}>
|
|
|
|
<RetinaImg
|
|
|
|
style={width: 13, height: 14}
|
|
|
|
name="account-switcher-dropdown.png"
|
|
|
|
mode={RetinaImg.Mode.ContentDark} />
|
2016-01-20 15:42:50 +08:00
|
|
|
</div>
|
2015-09-23 05:43:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
module.exports = AccountSwitcher
|