_ = require 'underscore' path = require 'path' React = require 'react' classNames = require 'classnames' {RetinaImg, TimeoutTransitionGroup} = require 'nylas-component-kit' {Actions, Utils, ComponentRegistry, UndoRedoStore, NamespaceStore} = require 'nylas-exports' class UndoRedoComponent extends React.Component @displayName: 'UndoRedoComponent' @propTypes: task: React.PropTypes.object.isRequired show: React.PropTypes.bool constructor: (@props) -> @state = @_getStateFromStores() @_timeout = null _onChange: => @setState(@_getStateFromStores(), => @_setNewTimeout()) _clearTimeout: => clearTimeout(@_timeout) _setNewTimeout: => @_clearTimeout() @_timeout = setTimeout (=> @_hide() return ), 3000 _getStateFromStores: -> t = UndoRedoStore.getMostRecentTask() s = false if t s = true return {show: s, task: t} componentWillMount: -> @_unsubscribe = UndoRedoStore.listen(@_onChange) componentWillUnmount: -> @_clearTimeout() @_unsubscribe() render: => items = [].concat(@_renderUndoRedoManager()) names = classNames "undo-redo-manager": true {items} _renderUndoRedoManager: => if @state.show

{@_formatMessage()}

Undo

else [] _undoTask: => atom.commands.dispatch(document.querySelector('body'), 'core:undo') @_hide() _formatMessage: => return @state.task.description() _hide: => @setState({show: false, task: null}) module.exports = UndoRedoComponent