<commit_before>'use babel';

import SaveTabsWithBranchView from './save-tabs-with-branch-view';
import { CompositeDisposable, TextEditor } from 'atom';

function getBranch() {
  const repos = atom.project.getRepositories();
  if (!repos || repos.length === 0) {
    return '';
  }
  const repo = repos[0];
  return repo.getShortHead();
}

function getOpenedFiles() {
  return atom.workspace.getPanes().map((pane) => {
    const activeItem = pane.getActiveItem();
    return pane.getItems().map((item) => {
      const data = {
        active: activeItem === item,
      };
      if (item instanceof TextEditor) {
        return Object.assign(data, {
          path: item.buffer.file.path,
        });
      }
      return Object.assign(data, {
        item,
      });
    });
  });
}

export default {

  saveTabsWithBranchView: null,
  modalPanel: null,
  subscriptions: null,

  activate(state) {
    this.saveTabsWithBranchView = new SaveTabsWithBranchView(state.saveTabsWithBranchViewState);
    this.modalPanel = atom.workspace.addModalPanel({
      item: this.saveTabsWithBranchView.getElement(),
      visible: false,
    });
    this.subscribeCommand();
  },

  subscribeCommand() {
    // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
    this.subscriptions = new CompositeDisposable();

    // Register command that toggles this view
    this.subscriptions.add(atom.commands.add('atom-workspace', {
      'save-tabs-with-branch:toggle': () => this.toggle(),
    }));

    this.subscriptions.add(atom.commands.add('atom-workspace', {
      'save-tabs-with-branch:get-opened-file': () => console.log(getOpenedFiles()),
    }));

    this.subscriptions.add(atom.commands.add('atom-workspace', {
      'save-tabs-with-branch:get-branch-name': () => console.log(getBranch()),
    }));
  },

  deactivate() {
    this.modalPanel.destroy();
    this.subscriptions.dispose();
    this.saveTabsWithBranchView.destroy();
  },

  serialize() {
    return {
      saveTabsWithBranchViewState: this.saveTabsWithBranchView.serialize(),
    };
  },
<commit_msg>Add initial checking for branch change<commit_after>'use babel';

import SaveTabsWithBranchView from './save-tabs-with-branch-view';
import { CompositeDisposable, TextEditor } from 'atom';

function getBranch() {
  const repos = atom.project.getRepositories();
  if (!repos || repos.length === 0) {
    return '';
  }
  const repo = repos[0];
  return repo.getShortHead();
}

function getOpenedFiles() {
  return atom.workspace.getPanes().map((pane) => {
    const activeItem = pane.getActiveItem();
    return pane.getItems().map((item) => {
      const data = {
        active: activeItem === item,
      };
      if (item instanceof TextEditor) {
        return Object.assign(data, {
          path: item.buffer.file.path,
        });
      }
      return Object.assign(data, {
        item,
      });
    });
  });
}

export default {

  saveTabsWithBranchView: null,
  modalPanel: null,
  subscriptions: null,
  currentBranch: getBranch(),

  activate(state) {
    this.saveTabsWithBranchView = new SaveTabsWithBranchView(state.saveTabsWithBranchViewState);
    this.modalPanel = atom.workspace.addModalPanel({
      item: this.saveTabsWithBranchView.getElement(),
      visible: false,
    });
    this.subscribeEvents();
  },

  subscribeEvents() {
    // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
    this.subscriptions = new CompositeDisposable();

    // Register command that toggles this view
    this.subscriptions.add(atom.commands.add('atom-workspace', {
      'save-tabs-with-branch:toggle': () => this.toggle(),
    }));

    this.subscriptions.add(atom.commands.add('atom-workspace', {
      'save-tabs-with-branch:get-opened-file': () => console.log(getOpenedFiles()),
    }));

    this.subscriptions.add(atom.commands.add('atom-workspace', {
      'save-tabs-with-branch:get-branch-name': () => console.log(getBranch()),
    }));

    const repos = atom.project.getRepositories();
    if (repos && repos.length) {
      const repo = repos[0];
      repo.onDidChangeStatuses(() => {
        const branch = getBranch();
        if (this.currentBranch !== branch) {
          this.currentBranch = branch;
        }
      });
    }
  },

  deactivate() {
    this.modalPanel.destroy();
    this.subscriptions.dispose();
    this.saveTabsWithBranchView.destroy();
  },

  serialize() {
    return {
      saveTabsWithBranchViewState: this.saveTabsWithBranchView.serialize(),
    };
  },

{'fraction_non_alphanumeric': 0.14546253570643813, 'fraction_numerical': 0.001098659635245001, 'mean_word_length': 3.145719489981785, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '897891', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1406, 'n_words': 247}