<commit_before>'use babel';

import _ from 'underscore'
import {
    $,
    ScrollView
} from 'atom-space-pen-views'
import {
    extMeuns,
    removeMenuItem,
    resetMenuItem,
    getHiddenMenus,
    getVisibleMenus,
    toggleMenuLabel,
    extraStrokesCfg
} from './menu-item-manager';

const menuSets = atom.contextMenu.itemSets

export default class ContextMenuManagerView extends ScrollView {
    static content() {
        this.raw(`
            <div class="context-menu-manager">
                <div class="search-bar">
                    <span>Search:</span>
                    <input type="text" name="" value="">
                    <div>
                </div>
                <h3 class="heading">显示的菜单</h3>
                <div class="visible-menus"></div>
                <h3 class="heading">隐藏的菜单</h3>
                <div class="hidden-menus"></div>
            </div>
        `)
    }

    initialize(item, option) {
        super.initialize()
        // extMeuns()
        this.render()
        this.bind()
    }

    render() {
        this.find('.hidden-menus').empty().html(this.createMenuDom(getHiddenMenus(), false))
        this.find('.visible-menus').empty().html(this.createMenuDom(getVisibleMenus(), true))
    }

    createMenuDom(menus, isShow) {
        const [word, classNames] = isShow ?　['隐藏', 'hideBtn btn icon icon-playback-pause enablement'] : ['显示', 'showBtn btn icon enablement icon-playback-play']

        return menus.map(function(it, idx) {
            const uid = _.uniqueId()
            return `<div class="menu-item" >
                <input class="data" type="hidden" value="${it._ext_selector}|||${it.label}|||${it.command}">
                <div class="left">
                    <div class="label">
                        <span>${it.label || it.type}</span>
                    </div>
                    <div>
                        <span>{selector: "${it._ext_selector}"</span>
                        <span>command: "${it.command || ''}"}</span>
                    </div>
                </div>
                <div class="right">
                    <input id="shortcut-${uid}" class="shortcut" type="checkbox" ${extraStrokesCfg.has(it.command) ? 'checked' : ''}>
                    <label for="shortcut-${uid}">附加快捷键</label>
                    <button class="${classNames}" type="button" name="button">${word}</button>
                </div>
            </div>`
        }).join('')
    }

    bind() {
        this.on('click', '.hideBtn', this.eventHandler.hideMenuItem)
        this.on('click', '.showBtn', this.eventHandler.showMenuItem)
        this.on('click', '.heading', this.eventHandler.foldMenus)
        this.on('click', '.shortcut', this.eventHandler.shortcutChange)
    }

    get eventHandler() {
        const self = this
        return {
            hideMenuItem(e) {
                const [selector, label, command] = $(e.target).parent().siblings('.data').val().split('|||')

                removeMenuItem(selector, command)
                self.render()
            },
            showMenuItem(e) {
                const [selector, label, command] = $(e.target).parent().siblings('.data').val().split('|||')

                resetMenuItem(selector, command)
                self.render()
            },
            foldMenus(e) {
                $(e.target).next().toggle()
            },
            shortcutChange(e) {
                const $label = $(e.target).parent().siblings('.left').find('.label')
                const [selector, label, command] = $(e.target).parent().siblings('.data').val().split('|||')

                $label.text(toggleMenuLabel(selector, command, e.target.checked))
            }
        }
    }

    getTitle() {
        return 'Context-Menu-Manager'
    }
}
<commit_msg>input 事件<commit_after>'use babel';

import _ from 'underscore'
import {
    $,
    ScrollView
} from 'atom-space-pen-views'
import {
    extMeuns,
    removeMenuItem,
    resetMenuItem,
    getHiddenMenus,
    getVisibleMenus,
    toggleMenuLabel,
    extraStrokesCfg
} from './menu-item-manager';

const menuSets = atom.contextMenu.itemSets

export default class ContextMenuManagerView extends ScrollView {
    static content() {
        this.raw(`
            <div class="context-menu-manager native-key-bindings">
                <div class="search-bar">
                    <span>Search:</span>
                    <input type="text" name="" value="">
                </div>
                <h3 class="heading">显示的菜单</h3>
                <div class="visible-menus"></div>
                <h3 class="heading">隐藏的菜单</h3>
                <div class="hidden-menus"></div>
            </div>
        `)
    }

    initialize(item, option) {
        super.initialize()

        this.render()
        this.bind()
    }

    render() {
        debugger
        this.find('.hidden-menus').empty().html(this.createMenuDom(getHiddenMenus(), false))
        this.find('.visible-menus').empty().html(this.createMenuDom(getVisibleMenus(), true))
    }

    createMenuDom(menus, isShow) {
        const [word, classNames] = isShow ?　['隐藏', 'hideBtn btn icon icon-playback-pause enablement'] : ['显示', 'showBtn btn icon enablement icon-playback-play']

        return menus.map(function(it, idx) {
            const uid = _.uniqueId()
            return `<div class="menu-item" >
                <input class="data" type="hidden" value="${it._ext_selector}|||${it.label}|||${it.command}">
                <div class="left">
                    <div class="label">
                        <span>${it.label || it.type}</span>
                    </div>
                    <div>
                        <span>{selector: "${it._ext_selector}"</span>
                        <span>command: "${it.command || ''}"}</span>
                    </div>
                </div>
                <div class="right">
                    <input id="shortcut-${uid}" class="shortcut" type="checkbox" ${extraStrokesCfg.has(it.command) ? 'checked' : ''}>
                    <label for="shortcut-${uid}">附加快捷键</label>
                    <button class="${classNames}" type="button" name="button">${word}</button>
                </div>
            </div>`
        }).join('')
    }

    bind() {
        this.on('click', '.hideBtn', this.eventHandler.hideMenuItem)
        this.on('click', '.showBtn', this.eventHandler.showMenuItem)
        this.on('click', '.heading', this.eventHandler.foldMenus)
        this.on('click', '.shortcut', this.eventHandler.shortcutChange)
        this.on('input', '.search-bar input', this.eventHandler.search)
    }

    get eventHandler() {
        const self = this
        return {
            hideMenuItem(e) {
                const [selector, label, command] = $(e.target).parent().siblings('.data').val().split('|||')

                removeMenuItem(selector, command)
                self.render()
            },
            showMenuItem(e) {
                const [selector, label, command] = $(e.target).parent().siblings('.data').val().split('|||')

                resetMenuItem(selector, command)
                self.render()
            },
            foldMenus(e) {
                $(e.target).next().toggle()
            },
            shortcutChange(e) {
                const $label = $(e.target).parent().siblings('.left').find('.label')
                const [selector, label, command] = $(e.target).parent().siblings('.data').val().split('|||')

                $label.text(toggleMenuLabel(selector, command, e.target.checked))
            },
            search() {
                console.log(1111111111, 1)
            }
        }
    }

    getTitle() {
        return 'Context-Menu-Manager'
    }
}

{'fraction_non_alphanumeric': 0.16333938294010888, 'fraction_numerical': 0.0024630541871921183, 'mean_word_length': 1.7721882860222782, 'pattern_counts': {'":': 0, '<': 78, '<?xml version=': 0, '>': 78, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '341890', 'n_tokens_mistral': 2262, 'n_tokens_neox': 2181, 'n_words': 366}