<commit_before>'use strict';

const CompositeDisposable = require('atom').CompositeDisposable;

const SelectListView = require('atom-space-pen-views').SelectListView,
    $$ = require('atom-space-pen-views').$$;

const _utilities = require('./utilities');

class PVSelectListView extends SelectListView {

    constructor () {
        super();
    }

    initialize () {
        this.disposables = new CompositeDisposable();
        this.setLoading('Loading projects...');
    }

    getEmptyMessage () {
        return 'Couldn\'t find any projects';
    }

    destroy () {
        this.cancel();

        if (this.panel) {
            this.panel.destroy();
        }
    }

    cancelSelection () {
        if (this.panel && this.panel.isVisible()) {
            this.cancel();
        }
    }

    confirmSelection () {
      if (this.panel && !this.panel.isVisible()) {
          return;
      }
        const item = this.getSelectedItem();
        if (item) {
            this.confirmed(item);
        }
        if (this.panel && this.panel.isVisible()) {
            this.cancel();
        }
    }

    confirmed (item) {
        const event = new MouseEvent('click');
        const view = document.getElementById(item.projectId);
        if (view) {
          view.dispatchEvent(event);
        }
        this.cancel();
    }

    cancel () {
        this.filterEditorView.setText('');
        this.hide();
    }

    show () {
        if (!this.panel) {
            this.panel = atom.workspace.addModalPanel({
                item: this
            });
        }
        this.disposables.add(
            atom.commands.add(
                'atom-workspace', {
                    'core:move-up': this.selectPreviousItemView.bind(this),
                    'core:move-down': this.selectNextItemView.bind(this),
                    'core:confirm': this.confirmSelection.bind(this),
                    'core:cancel': this.cancelSelection.bind(this)
                }
            )
        );

        // let the atom-space-pen-views plugin manage the update and the filtering (fuzzy search) of the list with the native 'populateList' function
        this.disposables.add(
            this.filterEditorView.getModel().getBuffer().onDidChange(this.populateList.bind(this))
        );
        this.storeFocusedElement();
        this.panel.show();
        if (this.items.length > 0) {
            this.scrollToItemView(this.list.find('li:first'));
        }
        this.focusFilterEditor();
    }

    hide () {
        this.disposables.dispose();
        if (this.panel) {
            this.list.empty();
            this.panel.hide();
        }
    }

    cancelled () {
        this.cancel();
    }

    toggle () {
        if (this.panel && this.panel.isVisible()) {
            this.cancel();
        } else {
            this.populate();
            this.show();
            this.focusFilterEditor();
        }
    }
<commit_msg>Registrer handlers only once in 'initialize' function<commit_after>'use strict';

const CompositeDisposable = require('atom').CompositeDisposable;

const SelectListView = require('atom-space-pen-views').SelectListView,
    $$ = require('atom-space-pen-views').$$;

const _utilities = require('./utilities');

class PVSelectListView extends SelectListView {

    constructor () {
        super();
    }

    initialize () {
        this.disposables = new CompositeDisposable();
        this.disposables.add(
            atom.commands.add(
                'atom-workspace', {
                    'core:move-up': this.selectPreviousItemView.bind(this),
                    'core:move-down': this.selectNextItemView.bind(this),
                    'core:confirm': this.confirmSelection.bind(this),
                    'core:cancel': this.cancelSelection.bind(this)
                }
            )
        );
        // let the atom-space-pen-views plugin manage the update and the filtering (fuzzy search) of the list with the native 'populateList' function
        this.disposables.add(
            this.filterEditorView.getModel().getBuffer().onDidChange(this.populateList.bind(this))
        );
        this.setLoading('Loading projects...');
    }

    getEmptyMessage () {
        return 'Couldn\'t find any projects';
    }

    destroy () {
        this.cancel();

        if (this.panel) {
            this.panel.destroy();
        }
    }

    cancelSelection () {
        if (this.panel && this.panel.isVisible()) {
            this.cancel();
        }
    }

    confirmSelection () {
      if (this.panel && !this.panel.isVisible()) {
          return;
      }
        const item = this.getSelectedItem();
        if (item) {
            this.confirmed(item);
        }
        if (this.panel && this.panel.isVisible()) {
            this.cancel();
        }
    }

    confirmed (item) {
        const event = new MouseEvent('click');
        const view = document.getElementById(item.projectId);
        if (view) {
          view.dispatchEvent(event);
        }
        this.cancel();
    }

    cancel () {
        this.filterEditorView.setText('');
        this.hide();
    }

    show () {
        if (!this.panel) {
            this.panel = atom.workspace.addModalPanel({
                item: this
            });
        }
        this.storeFocusedElement();
        this.panel.show();
        if (this.items.length > 0) {
            this.scrollToItemView(this.list.find('li:first'));
        }
        this.focusFilterEditor();
    }

    hide () {
        if (this.panel) {
            this.list.empty();
            this.panel.hide();
        }
    }

    cancelled () {
        this.cancel();
    }

    toggle () {
        if (this.panel && this.panel.isVisible()) {
            this.cancel();
        } else {
            this.populate();
            this.show();
            this.focusFilterEditor();
        }
    }

{'fraction_non_alphanumeric': 0.13586124808706002, 'fraction_numerical': 0.0003400782179901377, 'mean_word_length': 1.6748522055479764, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4358134', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1605, 'n_words': 275}