<commit_before>import Radium from 'radium';
import React, {PropTypes} from 'react';
import {
  Analytics,
  Android,
  FileSystem,
  Simulator,
  UrlUtils,
} from 'xdl';

import {PopoverEnum} from '../Constants';
import ProjectIcon from '../ProjectIcon';
import StyleConstants from '../StyleConstants';

import IconButton from './IconButton';
import MenuItem from './MenuItem';
import MenuSeparator from './MenuSeparator';
import Popover from './Popover';

@Radium
export default class ToolBar extends React.Component {
  static propTypes = {
    isProjectOpen: PropTypes.bool,
    isProjectRunning: PropTypes.bool,
    openPopover: PropTypes.oneOf(Object.keys(PopoverEnum).map((k) => PopoverEnum[k])),
    onTogglePopover: PropTypes.func.isRequired,
    projectJson: PropTypes.object,
    projectRoot: PropTypes.string,
    projectSettings: PropTypes.object,
    sendTo: PropTypes.string,
    userName: PropTypes.string,

    onAppendErrors: PropTypes.func,
    onAppendLogs: PropTypes.func,
    onLogOut: PropTypes.func,
    onNewProjectClick: PropTypes.func,
    onOpenProjectClick: PropTypes.func,
    onCloseProjectClick: PropTypes.func,
    onPublishClick: PropTypes.func,
    onRestartClick: PropTypes.func,
    onSendLinkClick: PropTypes.func,
    onDocsClicked: PropTypes.func,
    onJoinUsOnSlackClicked: PropTypes.func,
  };

  constructor(props, context) {
    super(props, context);
    this.state = {
      shiftSelected: false,
    };
  }

  componentDidMount() {
    document.body.addEventListener('keydown', this._onKeyDown);
    document.body.addEventListener('keyup', this._onKeyUp);
  }

  componentWillUnmount() {
    document.body.removeEventListener('keydown', this._onKeyDown);
    document.body.removeEventListener('keyup', this._onKeyUp);
  }

  _onKeyDown = (event) => {
    let metaKey = event.ctrlKey;
    if (process.platform === 'darwin') {
      metaKey = event.metaKey;
    }

    this.setState({
      shiftSelected: !!event.shiftKey,
    });

    if (metaKey) {
      switch (event.key) {
        case 'n':
          event.preventDefault();
          this.props.onNewProjectClick();
          break;
        case 'o':
          event.preventDefault();
          this.props.onOpenProjectClick();
          break;
        case 'p':
        case 'r':
          event.preventDefault();
          if (this.props.isProjectOpen) {
            this.props.onRestartClick(true);
          }
          break;
        case 'R':
          event.preventDefault();
          if (this.props.isProjectOpen) {
            this.props.onRestartClick(false);
          }
          break;
        case 'i':
          event.preventDefault();
          if (this.props.isProjectRunning && Simulator.isPlatformSupported()) {
            this._simulatorIOSAsync();
          }
          break;
        case 'd':
          event.preventDefault();
          if (this.props.isProjectRunning && Android.isPlatformSupported()) {
            this._simulatorAndroidAsync();
          }
          break;
      }
    }
  };
<commit_msg>Make cmd+[shift+]p the only packager restart shortcuts<commit_after>import Radium from 'radium';
import React, {PropTypes} from 'react';
import {
  Analytics,
  Android,
  FileSystem,
  Simulator,
  UrlUtils,
} from 'xdl';

import {PopoverEnum} from '../Constants';
import ProjectIcon from '../ProjectIcon';
import StyleConstants from '../StyleConstants';

import IconButton from './IconButton';
import MenuItem from './MenuItem';
import MenuSeparator from './MenuSeparator';
import Popover from './Popover';

@Radium
export default class ToolBar extends React.Component {
  static propTypes = {
    isProjectOpen: PropTypes.bool,
    isProjectRunning: PropTypes.bool,
    openPopover: PropTypes.oneOf(Object.keys(PopoverEnum).map((k) => PopoverEnum[k])),
    onTogglePopover: PropTypes.func.isRequired,
    projectJson: PropTypes.object,
    projectRoot: PropTypes.string,
    projectSettings: PropTypes.object,
    sendTo: PropTypes.string,
    userName: PropTypes.string,

    onAppendErrors: PropTypes.func,
    onAppendLogs: PropTypes.func,
    onLogOut: PropTypes.func,
    onNewProjectClick: PropTypes.func,
    onOpenProjectClick: PropTypes.func,
    onCloseProjectClick: PropTypes.func,
    onPublishClick: PropTypes.func,
    onRestartClick: PropTypes.func,
    onSendLinkClick: PropTypes.func,
    onDocsClicked: PropTypes.func,
    onJoinUsOnSlackClicked: PropTypes.func,
  };

  constructor(props, context) {
    super(props, context);
    this.state = {
      shiftSelected: false,
    };
  }

  componentDidMount() {
    document.body.addEventListener('keydown', this._onKeyDown);
    document.body.addEventListener('keyup', this._onKeyUp);
  }

  componentWillUnmount() {
    document.body.removeEventListener('keydown', this._onKeyDown);
    document.body.removeEventListener('keyup', this._onKeyUp);
  }

  _onKeyDown = (event) => {
    let metaKey = event.ctrlKey;
    if (process.platform === 'darwin') {
      metaKey = event.metaKey;
    }

    this.setState({
      shiftSelected: !!event.shiftKey,
    });

    if (metaKey) {
      switch (event.key.toLowerCase()) {
        case 'n':
          event.preventDefault();
          this.props.onNewProjectClick();
          break;
        case 'o':
          event.preventDefault();
          this.props.onOpenProjectClick();
          break;
        case 'p':
          event.preventDefault();
          if (this.props.isProjectOpen) {
            this.props.onRestartClick(true);
          }
          break;
        case 'i':
          event.preventDefault();
          if (this.props.isProjectRunning && Simulator.isPlatformSupported()) {
            this._simulatorIOSAsync();
          }
          break;
        case 'd':
          event.preventDefault();
          if (this.props.isProjectRunning && Android.isPlatformSupported()) {
            this._simulatorAndroidAsync();
          }
          break;
      }
    }
  };

{'fraction_non_alphanumeric': 0.11906365779723813, 'fraction_numerical': 0.0, 'mean_word_length': 2.76362484157161, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '326570', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1740, 'n_words': 339}