import React, { PropTypes } from 'react' import ReactDOM from 'react-dom' import ExternalLink from 'browser/components/ExternalLink' import { setSearchFilter, clearSearch, toggleOnlyUnsavedFilter, toggleTutorial, saveAllArticles, switchArticle } from '../actions' import store from '../store' const electron = require('electron') const remote = electron.remote const Menu = remote.Menu const MenuItem = remote.MenuItem const OSX = process.platform === 'darwin' var menu = new Menu() var lastIndex = -1 menu.append(new MenuItem({ label: 'Show only unsaved', click: function () { store.dispatch(setSearchFilter('--unsaved')) } })) menu.append(new MenuItem({ label: 'Go to an unsaved article', click: function () { lastIndex++ let state = store.getState() let modified = state.articles.modified if (modified.length === 0) return if (modified.length <= lastIndex) { lastIndex = 0 } store.dispatch(switchArticle(modified[lastIndex].key)) } })) const BRAND_COLOR = '#18AF90' const searchTutorialElement = ( ) export default class ArticleTopBar extends React.Component { constructor (props) { super(props) this.state = { isTooltipHidden: true, isLinksDropdownOpen: false } } componentDidMount () { this.searchInput = ReactDOM.findDOMNode(this.refs.searchInput) this.linksButton = ReactDOM.findDOMNode(this.refs.links) this.showLinksDropdown = e => { e.preventDefault() e.stopPropagation() if (!this.state.isLinksDropdownOpen) { this.setState({isLinksDropdownOpen: true}) } } this.linksButton.addEventListener('click', this.showLinksDropdown) this.hideLinksDropdown = e => { if (this.state.isLinksDropdownOpen) { this.setState({isLinksDropdownOpen: false}) } } document.addEventListener('click', this.hideLinksDropdown) } componentWillUnmount () { document.removeEventListener('click', this.hideLinksDropdown) this.linksButton.removeEventListener('click', this.showLinksDropdown()) } handleTooltipRequest (e) { if (this.searchInput.value.length === 0 && (document.activeElement === this.searchInput)) { this.setState({isTooltipHidden: false}) } else { this.setState({isTooltipHidden: true}) } } isInputFocused () { return document.activeElement === ReactDOM.findDOMNode(this.refs.searchInput) } escape () { let { status, dispatch } = this.props if (status.search.length > 0) { dispatch(clearSearch()) return } this.blurInput() } focusInput () { this.searchInput.focus() } blurInput () { this.searchInput.blur() } handleSearchChange (e) { let { dispatch } = this.props dispatch(setSearchFilter(e.target.value)) this.handleTooltipRequest() } handleSearchClearButton (e) { this.searchInput.value = '' this.focusInput() } handleOnlyUnsavedChange (e) { let { dispatch } = this.props dispatch(toggleOnlyUnsavedFilter()) } handleSaveAllButtonClick (e) { let { dispatch } = this.props dispatch(saveAllArticles()) } handleSaveMenuButtonClick (e) { menu.popup(590, 45) } handleTutorialButtonClick (e) { let { dispatch } = this.props dispatch(toggleTutorial()) } render () { let { status, modified } = this.props return (