<commit_before>app.create('inbox', {
    lastReceivedTime: null,

    init: function () {
        if (!app.isAuth()) return;

        ui.init(this.ns);
        c.log('app.inbox.init');

        ui.partial('filter');
        ui.$pg = $(ui.tpl('inbox', {}));
        ui.$header.removeClass('hide');
        ui.$nav.removeClass('hide');
        ui.$header.find('a.inbox').addClass('active').siblings().removeClass('active');

        api.getInbox(this.showInbox.bind(this)); //needs spinner

        //start long polling for new messages
        ui.timers.inbox = setInterval(function(){
            ui.$header.find('a.inbox').addClass('anim');
            api.getInbox(this.showMessages.bind(this));
        }.bind(this), app.cfg('inbox.refresh'));

        //page events
        ui.$pg.find("#inbox-action").on('submit.inbox', this.actionItem.bind(this));
        ui.filter();

        //handle click events on currently opened message headers
        ui.$pg.find("table").on('click.inbox', 'tr.msg header', function (e) {
            e.preventDefault();

            var $el = $(e.target) //clicked element
                , isSentMessage = false
                , $row = $(e.currentTarget).parents('tr.msg')
                , id = $row.attr('data-msgid'); //msg.msgid

            //handle msg actions
            if ( $el.is('a.trash') ) {
                c.log('trash msg');
                (function() {
                    var spin = ui.spin($el);

                    api.moveToTrash(id, function(id, msg){
                        this.moveToTrash(id, msg, spin);
                    }.bind(this));
                }.bind(this))();
            } else if ( $el.is('a.close') ) {
                c.log('close msg');
                app.message.hideMsg(id);
            } else if ( $el.is('a.maximize') ) {
                app.message.maximize($row);
            } else if ( $el.is('a.minimize') ) {
                app.message.minimize($row);
            } else if ( $el.is('a.reply') ) {
                this.showReply(id); //should be moved to app.message?
            } else if ( $el.is('.from') || $el.is('.address') ) {
                (function(){
                    var id = $el.attr('data-address');

                    c.log('address', id);
                    app.compose.init(id);
                })();
            } else if ( $el.is('a.render-html') ) {
                app.message.renderHtml(id, isSentMessage);
            } else if ( $el.is('a.ext') ) {
                //ui.win($el.attr('href'));
            } else if ( $el.is('a.reverse') ) {
                app.message.reverseThread(id, isSentMessage);
            } else if ( $el.is('a.prev-msg') ) {
                app.message.prevMsg($row, id);
            } else if ( $el.is('a.next-msg') ) {
                app.message.nextMsg($row, id);
            }
        }.bind(this));


        //clicks on message bodies
        ui.$pg.find("table").on('click.inbox', 'tr.msg .message', function (e) {
            e.preventDefault();

            var $el = $(e.target) //clicked element
                , isSentMessage = false
                , $row = $(e.currentTarget).parents('tr.msg')
                , id = $row.attr('data-msgid'); //msg.msgid

            if ( $el.is('.address') ) {
                (function(){
                    var id = $el.attr('data-address');

                    c.log('address', id);
                    app.compose.init(id);
                })();
            }
        }.bind(this));

        ui.$pg.find("table").on('contextmenu.inbox', 'tr.msg .message', function (e) {
            e.preventDefault();

            var isSentMessage = false
                , $row = $(e.currentTarget).parents('tr.msg')
                , id = $row.attr('data-msgid'); //msg.msgid

            var gui = require('nw.gui')
                , menu = new gui.Menu();

            var searchItem = new gui.MenuItem({
                label: 'Search web...'
                , click: function(e){
                    var text = window.getSelection().toString()
                        , q = encodeURIComponent(text.replace(/&amp;/g, "&"));

                    //var url = 'https://encrypted.google.com/#q='+q;
                    var url = 'https://ixquick.com/do/search?q='+q;

                    ui.win(url);
                }
            });

            var quoteItem = new gui.MenuItem({
                label: 'Quote text in reply'
                , click: function(e){
                    var quote = window.getSelection().toString()
                        , lines = quote.split('\n');

                    //quote the lines
                    lines = _.map(lines, function(ln){
                       return '> ' + ln;
                    });

                    quote = lines.join('\n');

                    this.showReply(id, quote);
                }.bind(this)
            });

            menu.append(searchItem);
            menu.append(quoteItem);
            menu.popup(e.clientX, e.clientY);

        }.bind(this));<commit_msg>add google translate option to context menu.<commit_after>app.create('inbox', {
    lastReceivedTime: null,

    init: function () {
        if (!app.isAuth()) return;

        ui.init(this.ns);
        c.log('app.inbox.init');

        ui.partial('filter');
        ui.$pg = $(ui.tpl('inbox', {}));
        ui.$header.removeClass('hide');
        ui.$nav.removeClass('hide');
        ui.$header.find('a.inbox').addClass('active').siblings().removeClass('active');

        api.getInbox(this.showInbox.bind(this)); //needs spinner

        //start long polling for new messages
        ui.timers.inbox = setInterval(function(){
            ui.$header.find('a.inbox').addClass('anim');
            api.getInbox(this.showMessages.bind(this));
        }.bind(this), app.cfg('inbox.refresh'));

        //page events
        ui.$pg.find("#inbox-action").on('submit.inbox', this.actionItem.bind(this));
        ui.filter();

        //handle click events on currently opened message headers
        ui.$pg.find("table").on('click.inbox', 'tr.msg header', function (e) {
            e.preventDefault();

            var $el = $(e.target) //clicked element
                , isSentMessage = false
                , $row = $(e.currentTarget).parents('tr.msg')
                , id = $row.attr('data-msgid'); //msg.msgid

            //handle msg actions
            if ( $el.is('a.trash') ) {
                c.log('trash msg');
                (function() {
                    var spin = ui.spin($el);

                    api.moveToTrash(id, function(id, msg){
                        this.moveToTrash(id, msg, spin);
                    }.bind(this));
                }.bind(this))();
            } else if ( $el.is('a.close') ) {
                c.log('close msg');
                app.message.hideMsg(id);
            } else if ( $el.is('a.maximize') ) {
                app.message.maximize($row);
            } else if ( $el.is('a.minimize') ) {
                app.message.minimize($row);
            } else if ( $el.is('a.reply') ) {
                this.showReply(id); //should be moved to app.message?
            } else if ( $el.is('.from') || $el.is('.address') ) {
                (function(){
                    var id = $el.attr('data-address');

                    c.log('address', id);
                    app.compose.init(id);
                })();
            } else if ( $el.is('a.render-html') ) {
                app.message.renderHtml(id, isSentMessage);
            } else if ( $el.is('a.ext') ) {
                //ui.win($el.attr('href'));
            } else if ( $el.is('a.reverse') ) {
                app.message.reverseThread(id, isSentMessage);
            } else if ( $el.is('a.prev-msg') ) {
                app.message.prevMsg($row, id);
            } else if ( $el.is('a.next-msg') ) {
                app.message.nextMsg($row, id);
            }
        }.bind(this));


        //clicks on message bodies
        ui.$pg.find("table").on('click.inbox', 'tr.msg .message', function (e) {
            e.preventDefault();

            var $el = $(e.target) //clicked element
                , isSentMessage = false
                , $row = $(e.currentTarget).parents('tr.msg')
                , id = $row.attr('data-msgid'); //msg.msgid

            if ( $el.is('.address') ) {
                (function(){
                    var id = $el.attr('data-address');

                    c.log('address', id);
                    app.compose.init(id);
                })();
            }
        }.bind(this));

        ui.$pg.find("table").on('contextmenu.inbox', 'tr.msg .message', function (e) {
            e.preventDefault();

            var isSentMessage = false
                , $row = $(e.currentTarget).parents('tr.msg')
                , id = $row.attr('data-msgid'); //msg.msgid

            var gui = require('nw.gui')
                , menu = new gui.Menu();

            var searchItem = new gui.MenuItem({
                label: 'Search web...'
                , click: function(e){
                    var text = window.getSelection().toString()
                        , q = encodeURIComponent(text.replace(/&amp;/g, "&"));

                    //var url = 'https://encrypted.google.com/#q='+q;
                    var url = 'https://ixquick.com/do/search?q='+q;

                    ui.win(url);
                }
            });

            var quoteItem = new gui.MenuItem({
                label: 'Quote text in reply'
                , click: function(e){
                    var quote = window.getSelection().toString()
                        , lines = quote.split('\n');

                    //quote the lines
                    lines = _.map(lines, function(ln){
                       return '> ' + ln;
                    });

                    quote = lines.join('\n');

                    this.showReply(id, quote);
                }.bind(this)
            });

            var translateItem = new gui.MenuItem({
                label: 'Translate...'
                , click: function(e){
                    var text = window.getSelection().toString()
                        , q = encodeURIComponent(text.replace(/&amp;/g, "&"));

                    var url = 'https://translate.google.com/#auto/en/'+q;

                    ui.win(url);
                }
            });

            menu.append(searchItem);
            menu.append(quoteItem);
            menu.append(translateItem);
            menu.popup(e.clientX, e.clientY);

        }.bind(this));
{'fraction_non_alphanumeric': 0.16800909693925897, 'fraction_numerical': 0.0, 'mean_word_length': 1.33289124668435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 5, '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': '3046928', 'n_tokens_mistral': 3103, 'n_tokens_neox': 2912, 'n_words': 517}