<commit_before>/*global define, $, brackets */
'use strict';

define(function (require, exports) {

    var command_manager = brackets.getModule('command/CommandManager');
    var commands = brackets.getModule('command/Commands');
    var panel_manager = brackets.getModule('view/PanelManager');
    var preferences_manager = brackets.getModule('preferences/PreferencesManager');
    var prefs = preferences_manager.getExtensionPrefs('brackets-nodejs-integration');
    var menus = brackets.getModule('command/Menus');

    var LOCALS_CONTEXT_MENU_ID = 'brackets-nodejs-integration-locals-context-menu';

    var _maxDepth = 3;
    var history = [];
    var historyCurrent = 0;
    var logContainerHTML = require('text!./assets/debuggerLog.html');

    exports.create_new = function () {
        return new DebuggerPanel();
    };

    var DebuggerPanel = function () {
        this.panel = null;
        this.$logPanel = $(null);
        this.$debuggerContent = $(null);
        this.$debuggerSideBar = $(null);
        this.$debuggerInput = $(null);
        this._nodeDebuggerDomain = null;
    };

    /*
     * KeyHandler for the inputfield
     */
    function onKeyDown(e, that) {
        //On enter send command
        if (e.keyCode === 13) {
            //Remove all may existing suggestions
            that.$debuggerInput.find('.suggestion').remove();
            var com = that.$debuggerInput.val();

            if (com.length > 0) {
                history.push(com);
                historyCurrent = history.length;
                that.log($('<span>').text('>> ' + com));
                that._nodeDebuggerDomain.exec('eval', com);
                //reset the input field
                that.$debuggerInput.val('');
            }
        }
        //On key up/down scroll through history
        if (e.keyCode === 40) {
            historyCurrent++;
            if (history[historyCurrent]) {
                that.$debuggerInput.val(history[historyCurrent]);
            }
            else {
                historyCurrent = history.length;
                that.$debuggerInput.val('');
            }
            //e.preventDefault();
        }
        if (e.keyCode === 38) {
            historyCurrent--;
            if (history[historyCurrent]) {
                that.$debuggerInput.val(history[historyCurrent]);
            }
            else {
                historyCurrent = 0;
            }
            e.preventDefault();
        }
    }

    /*
     * click event handler to give more Information about an object in the console
     */
    function evalHTMLonClick(e) {
        var $t = $(e.target);
        if ($t.hasClass('fa-chevron-right')) {
            $t.removeClass('fa-chevron-right').addClass('fa-chevron-down');
            $t.siblings().removeClass('hidden');
        }
        else {
            if ($t.hasClass('fa-chevron-down')) {
                $t.removeClass('fa-chevron-down').addClass('fa-chevron-right');
                $t.siblings().addClass('hidden');
            }
        }
    }

    /**
     * Initialize the panel
     *
     * @param {NodeDomain} nodeDebuggerDomain
     **/
    DebuggerPanel.prototype.init = function (nodeDebuggerDomain, domain_id) {
        //Create the BottomPanel
        this.panel = $('#' + domain_id).find('.brackets-nodejs-integration-debugger').html($(logContainerHTML)).show();
        this.$logPanel = $('#' + domain_id).find('.brackets-nodejs-integration-debugger-log-panel');
        _maxDepth = prefs.get('lookupDepth');
        this._nodeDebuggerDomain = nodeDebuggerDomain;

        //Find HTML
        this.$debuggerContent = this.$logPanel.find('.brackets-nodejs-integration-debugger-content');
        this.$debuggerCallbackStack = this.$logPanel.find('.brackets-nodejs-integration-debugger-callback-stack');
        this.$debuggerSideBar = this.$logPanel.find('.brackets-nodejs-integration-debugger-sidebar');
        this.$debuggerInput = this.$logPanel.find('.brackets-nodejs-integration-debugger-input');

        //Add keydown handler to input
        var that = this;
        this.$debuggerInput.on('keyup', function (e) {
            onKeyDown(e, that);
        });


        //Add help button
        var $help = $('<a>').html('<i class="fa fa-question-circle" aria-hidden="true"></i>')
            .attr('href', 'https://github.com/yacut/brackets-nodejs-integration#how-to-use-debugger')
            .attr('title', 'Help!');
        this.addControlElement($help, false, function () {});

        //Add clear console button
        var $clear = $('<a>').attr('href', '#').attr('title', 'Clear console').html('<i class="fa fa-trash" aria-hidden="true"></i>');

        this.addControlElement($clear, false, function () {
            that.$debuggerContent.html($('.brackets-nodejs-integration-debugger-input-wrapper'));
            //set the keyHandler again
            that.$debuggerInput.on('keydown', function (e) {
                onKeyDown(e, that);
            });
        });

        this._nodeDebuggerDomain.on('afterCompile', function (e, body) {
            if (body && body.script && body.script.name) {
                console.log('panel 144', e, JSON.stringify(body.script));
                var $callback_file = $('<li>').text(body.script.name).on('click', function () {
                    command_manager.execute(commands.FILE_OPEN, {
                        fullPath: $(this).text()
                    });
                });
                $callback_file.prependTo(that.$debuggerCallbackStack);
            }
        });

        //add show console button
        var $show_console = $('<a>').attr('href', '#').attr('title', 'Console').html('<i class="fa fa-terminal"></i>');
        this.addControlElement($show_console, false, function () {
            var $domain = $('#' + domain_id);
            var $callback_stack = $domain.find('.brackets-nodejs-integration-debugger-callback-stack');
            var $sidebar = $domain.find('.brackets-nodejs-integration-debugger-sidebar');
            var $content = $domain.find('.brackets-nodejs-integration-debugger-content');
            var $console_input = $domain.find('.brackets-nodejs-integration-debugger-input');
            if ($content.is(':visible')) {
                $sidebar.show();
                $callback_stack.hide();
                $console_input.hide();
                $content.show();
            }
            else {
                $callback_stack.hide();
                $sidebar.hide();
                $content.show();
                $console_input.show().select();
                $(that).toggleClass('brackets-nodejs-integration-debugger-selected-button').find('i').toggleClass('fa-bold');
            }
        });

        //add show callback stack button
        var $callback_stack_link = $('<a>').attr('href', '#').attr('title', 'Console').html('<i class="fa fa-indent"></i>');
        this.addControlElement($callback_stack_link, false, function () {
            var $domain = $('#' + domain_id);
            var $callback_stack = $domain.find('.brackets-nodejs-integration-debugger-callback-stack');
            var $sidebar = $domain.find('.brackets-nodejs-integration-debugger-sidebar');
            var $content = $domain.find('.brackets-nodejs-integration-debugger-content');
            if ($callback_stack.is(':visible')) {
                $callback_stack.hide();
                $sidebar.show();
                $content.hide();
            }
            else {
                $callback_stack.show();
                $sidebar.hide();
                $content.hide();
            }
        });

    };

    /**
     *Adds a new line to the log within brackets
     **/
    DebuggerPanel.prototype.log = function ($msg) {
        var $h = $('<div>')
            .addClass('brackets-nodejs-integration-debugger-log');

        $h.append($msg);
        $h.insertBefore($('.brackets-nodejs-integration-debugger-input-wrapper'));
        this.$debuggerInput.focus();
        //Scroll to the bottom
        this.$debuggerContent.scrollTop(9999999999999);
    };

    /**<commit_msg>fixed wrong title on callback stack button<commit_after>/*global define, $, brackets */
'use strict';

define(function (require, exports) {

    var command_manager = brackets.getModule('command/CommandManager');
    var commands = brackets.getModule('command/Commands');
    var panel_manager = brackets.getModule('view/PanelManager');
    var preferences_manager = brackets.getModule('preferences/PreferencesManager');
    var prefs = preferences_manager.getExtensionPrefs('brackets-nodejs-integration');
    var menus = brackets.getModule('command/Menus');

    var LOCALS_CONTEXT_MENU_ID = 'brackets-nodejs-integration-locals-context-menu';

    var _maxDepth = 3;
    var history = [];
    var historyCurrent = 0;
    var logContainerHTML = require('text!./assets/debuggerLog.html');

    exports.create_new = function () {
        return new DebuggerPanel();
    };

    var DebuggerPanel = function () {
        this.panel = null;
        this.$logPanel = $(null);
        this.$debuggerContent = $(null);
        this.$debuggerSideBar = $(null);
        this.$debuggerInput = $(null);
        this._nodeDebuggerDomain = null;
    };

    /*
     * KeyHandler for the inputfield
     */
    function onKeyDown(e, that) {
        //On enter send command
        if (e.keyCode === 13) {
            //Remove all may existing suggestions
            that.$debuggerInput.find('.suggestion').remove();
            var com = that.$debuggerInput.val();

            if (com.length > 0) {
                history.push(com);
                historyCurrent = history.length;
                that.log($('<span>').text('>> ' + com));
                that._nodeDebuggerDomain.exec('eval', com);
                //reset the input field
                that.$debuggerInput.val('');
            }
        }
        //On key up/down scroll through history
        if (e.keyCode === 40) {
            historyCurrent++;
            if (history[historyCurrent]) {
                that.$debuggerInput.val(history[historyCurrent]);
            }
            else {
                historyCurrent = history.length;
                that.$debuggerInput.val('');
            }
            //e.preventDefault();
        }
        if (e.keyCode === 38) {
            historyCurrent--;
            if (history[historyCurrent]) {
                that.$debuggerInput.val(history[historyCurrent]);
            }
            else {
                historyCurrent = 0;
            }
            e.preventDefault();
        }
    }

    /*
     * click event handler to give more Information about an object in the console
     */
    function evalHTMLonClick(e) {
        var $t = $(e.target);
        if ($t.hasClass('fa-chevron-right')) {
            $t.removeClass('fa-chevron-right').addClass('fa-chevron-down');
            $t.siblings().removeClass('hidden');
        }
        else {
            if ($t.hasClass('fa-chevron-down')) {
                $t.removeClass('fa-chevron-down').addClass('fa-chevron-right');
                $t.siblings().addClass('hidden');
            }
        }
    }

    /**
     * Initialize the panel
     *
     * @param {NodeDomain} nodeDebuggerDomain
     **/
    DebuggerPanel.prototype.init = function (nodeDebuggerDomain, domain_id) {
        //Create the BottomPanel
        this.panel = $('#' + domain_id).find('.brackets-nodejs-integration-debugger').html($(logContainerHTML)).show();
        this.$logPanel = $('#' + domain_id).find('.brackets-nodejs-integration-debugger-log-panel');
        _maxDepth = prefs.get('lookupDepth');
        this._nodeDebuggerDomain = nodeDebuggerDomain;

        //Find HTML
        this.$debuggerContent = this.$logPanel.find('.brackets-nodejs-integration-debugger-content');
        this.$debuggerCallbackStack = this.$logPanel.find('.brackets-nodejs-integration-debugger-callback-stack');
        this.$debuggerSideBar = this.$logPanel.find('.brackets-nodejs-integration-debugger-sidebar');
        this.$debuggerInput = this.$logPanel.find('.brackets-nodejs-integration-debugger-input');

        //Add keydown handler to input
        var that = this;
        this.$debuggerInput.on('keyup', function (e) {
            onKeyDown(e, that);
        });


        //Add help button
        var $help = $('<a>').html('<i class="fa fa-question-circle" aria-hidden="true"></i>')
            .attr('href', 'https://github.com/yacut/brackets-nodejs-integration#how-to-use-debugger')
            .attr('title', 'Help!');
        this.addControlElement($help, false, function () {});

        //Add clear console button
        var $clear = $('<a>').attr('href', '#').attr('title', 'Clear console').html('<i class="fa fa-trash" aria-hidden="true"></i>');

        this.addControlElement($clear, false, function () {
            that.$debuggerContent.html($('.brackets-nodejs-integration-debugger-input-wrapper'));
            //set the keyHandler again
            that.$debuggerInput.on('keydown', function (e) {
                onKeyDown(e, that);
            });
        });

        this._nodeDebuggerDomain.on('afterCompile', function (e, body) {
            if (body && body.script && body.script.name) {
                console.log('panel 144', e, JSON.stringify(body.script));
                var $callback_file = $('<li>').text(body.script.name).on('click', function () {
                    command_manager.execute(commands.FILE_OPEN, {
                        fullPath: $(this).text()
                    });
                });
                $callback_file.prependTo(that.$debuggerCallbackStack);
            }
        });

        //add show console button
        var $show_console = $('<a>').attr('href', '#').attr('title', 'Console').html('<i class="fa fa-terminal"></i>');
        this.addControlElement($show_console, false, function () {
            var $domain = $('#' + domain_id);
            var $callback_stack = $domain.find('.brackets-nodejs-integration-debugger-callback-stack');
            var $sidebar = $domain.find('.brackets-nodejs-integration-debugger-sidebar');
            var $content = $domain.find('.brackets-nodejs-integration-debugger-content');
            var $console_input = $domain.find('.brackets-nodejs-integration-debugger-input');
            if ($content.is(':visible')) {
                $sidebar.show();
                $callback_stack.hide();
                $console_input.hide();
                $content.show();
            }
            else {
                $callback_stack.hide();
                $sidebar.hide();
                $content.show();
                $console_input.show().select();
                $(that).toggleClass('brackets-nodejs-integration-debugger-selected-button').find('i').toggleClass('fa-bold');
            }
        });

        //add show callback stack button
        var $callback_stack_link = $('<a>').attr('href', '#').attr('title', 'Callback stack').html('<i class="fa fa-indent"></i>');
        this.addControlElement($callback_stack_link, false, function () {
            var $domain = $('#' + domain_id);
            var $callback_stack = $domain.find('.brackets-nodejs-integration-debugger-callback-stack');
            var $sidebar = $domain.find('.brackets-nodejs-integration-debugger-sidebar');
            var $content = $domain.find('.brackets-nodejs-integration-debugger-content');
            if ($callback_stack.is(':visible')) {
                $callback_stack.hide();
                $sidebar.show();
                $content.hide();
            }
            else {
                $callback_stack.show();
                $sidebar.hide();
                $content.hide();
            }
        });
    };

    /**
     *Adds a new line to the log within brackets
     **/
    DebuggerPanel.prototype.log = function ($msg) {
        var $h = $('<div>')
            .addClass('brackets-nodejs-integration-debugger-log');

        $h.append($msg);
        $h.insertBefore($('.brackets-nodejs-integration-debugger-input-wrapper'));
        this.$debuggerInput.focus();
        //Scroll to the bottom
        this.$debuggerContent.scrollTop(9999999999999);
    };

    /**
{'fraction_non_alphanumeric': 0.15479494295405488, 'fraction_numerical': 0.0032069071847055197, 'mean_word_length': 2.0555869606180517, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '6168276', 'n_tokens_mistral': 4623, 'n_tokens_neox': 4355, 'n_words': 729}