'use babel';

import { Directory } from 'pathwatcher';
import path from 'path';
import { CompositeDisposable } from 'atom';

import config from './config';
import Blamer from './util/blamer';
import BlameGutter from './util/BlameGutter';
import errorController from './controllers/errorController';

/**
 * Main Package Module
 */
export default {

  config,

  disposables: null,
  gutters: null,

  activate() {
    this.gutters = new Map();
    this.disposables = new CompositeDisposable();
    this.disposables.add(atom.commands.add('atom-workspace', {
      'git-blame:toggle': this.toggle.bind(this),
    }));
  },

  deactivate() {
    this.disposables.dispose();
    this.gutters.clear();
  },

  toggle() {
    const editor = atom.workspace.getActiveTextEditor();

    // if there is no active text editor, git-blame can do nothing
    if (!editor) {
      return;
    }

    // get a BlameGutter from the cache or create a new one and add
    // it to the cache.
    let gutter = this.gutters.get(editor);
    if (!gutter) {
      gutter = new BlameGutter(editor);
      this.disposables.add(gutter);
      this.gutters.set(editor, gutter);
    }

    // toggle visiblity of the active gutter
    gutter.toggleVisibility()
      .catch(e => {
        console.error(e);
      });
  },

};

'use babel';

import { Directory } from 'pathwatcher';
import path from 'path';
import { CompositeDisposable } from 'atom';

import config from './config';
import Blamer from './util/Blamer';
import BlameGutter from './util/BlameGutter';
import errorController from './controllers/errorController';

/**
 * Main Package Module
 */
export default {

  config,

  disposables: null,
  gutters: null,

  activate() {
    this.gutters = new Map();
    this.disposables = new CompositeDisposable();
    this.disposables.add(atom.commands.add('atom-workspace', {
      'git-blame:toggle': this.toggle.bind(this),
    }));
  },

  deactivate() {
    this.disposables.dispose();
    this.gutters.clear();
  },

  toggle() {
    const editor = atom.workspace.getActiveTextEditor();

    // if there is no active text editor, git-blame can do nothing
    if (!editor) {
      return;
    }

    // get a BlameGutter from the cache or create a new one and add
    // it to the cache.
    let gutter = this.gutters.get(editor);
    if (!gutter) {
      gutter = new BlameGutter(editor);
      this.disposables.add(gutter);
      this.gutters.set(editor, gutter);
    }

    // toggle visiblity of the active gutter
    gutter.toggleVisibility()
      .catch(e => {
        console.error(e);
      });
  },

};

Update index.js to correct import for Blamer (#180)