<commit_before>Ext.ux.CodeMirror = Ext.extend(Ext.BoxComponent, {

    readOnly         : (this.readOnly) ? this.readOnly : false,
    width            : 'auto',
    height           : 'auto',
    autoResize       : true,
    initialised      : false,
    documentDurty    : false,
    spellCheck       : ( this.spellCheck ) ? this.spellCheck : false,
    parser           : (this.parser) ? this.parser : "xml",
    parserFile       : "parsexml.js",
    parserStylesheet : "js/ux/codemirror/css/xmlcolors.css",

    initComponent : function()
    {
        Ext.ux.CodeMirror.superclass.initComponent.apply(this);

        this.addEvents({
            initialize   : true,
            codemodified : true,
            coderestored : true,
            cursormove   : true,
            scroll       : true
        });

        //For the parser
        if( this.parser === 'xml' ) {
            this.parserFile = "parsexml.js";
            this.parserStylesheet = "js/ux/codemirror/css/xmlcolors.css";
        }

        if( this.parser === 'html' ) {
            this.parserFile = ["parsexml.js", "parsecss.js", "tokenizejavascript.js", "parsejavascript.js", "parsehtmlmixed.js"];
            this.parserStylesheet = ["js/ux/codemirror/css/xmlcolors.css", "js/ux/codemirror/css/jscolors.css", "js/ux/codemirror/css/csscolors.css"];
        }

        if( this.parser === 'php' ) {
            this.parserFile = ["parsexml.js", "parsecss.js", "tokenizejavascript.js", "parsejavascript.js",
                             "../contrib/php/js/tokenizephp.js", "../contrib/php/js/parsephp.js",
                             "../contrib/php/js/parsephphtmlmixed.js"];
            this.parserStylesheet = ["js/ux/codemirror/css/xmlcolors.css", "js/ux/codemirror/css/jscolors.css", "js/ux/codemirror/css/csscolors.css", "js/ux/codemirror/contrib/php/css/phpcolors.css"];
        }
    },
    onRender : function(ct, position)
    {
        Ext.ux.CodeMirror.superclass.onRender.apply(this, [ct, position]);
    },

    resize: function()
    {
        this.mirror.frame.style.height = this.ownerCt.lastSize.height - 89 +"px";
        this.mirror.frame.style.width  = this.ownerCt.lastSize.width  - 35 +"px";
    },

    onInit: function(t, cmId)
    {
        var cmp    = Ext.getCmp(cmId),
            mirror = cmp.mirror;

        cmp.ownerCt.fireEvent('resize');

        // Fire the initialize event
        cmp.fireEvent('initialize');
        cmp.initialised = true;

        // Value used to monitor the state of this document (changed or not)
        cmp.documentDurty = false;

        // Attach some others events
        mirror.editor.keyUp = function(e) {

            // On envoie cursormove
            var r        = mirror.cursorPosition(),
                line     = mirror.lineNumber(r.line),
                caracter = r.character;
            cmp.fireEvent('cursormove', line, caracter);

            if( Ext.getCmp(cmId).documentDurty === true && e.keyCode !== 8 && e.keyCode !== 46 ) {

                // Don't need to check if the code has changed

            } else {

                // We check if the code has changed or not
                cmp.manageCodeChange(cmId);
            }
        };

        Ext.EventManager.addListener(mirror.frame.contentWindow, "scroll", function(e){ cmp.monitorScroll(e, cmp); }, this);
    },

    onCursorActivity: function(cmId)
    {
        var cmp      = Ext.getCmp(cmId),
            mirror   = cmp.mirror,
            r        = mirror.cursorPosition(),
            line     = mirror.lineNumber(r.line),
            caracter = r.character;
            cmp.fireEvent('cursormove', line, caracter);
    },

    manageCodeChange: function(cmId, force)
    {
        var cmp             = Ext.getCmp(cmId),
            mirror          = cmp.mirror,
            originalContent = mirror.originalContent,
            currentContent  = mirror.getCode(),
            btnUndo         = Ext.getCmp(cmId + '-btn-undo');

        // If originalContent is false, the editor is not ready
        if( originalContent ) {
            if( originalContent === currentContent ) {
                if( cmp.documentDurty === true ) {
                    cmp.fireEvent('coderestored');
                    cmp.documentDurty = false;
                }
                
            } else {
                btnUndo.enable(); // undo
                if( cmp.documentDurty === false ) {
                    cmp.fireEvent('codemodified');
                    cmp.documentDurty = true;
                }
            }
        }
    },

    saveFunction: function(cmId)
    {
        var saveBtn = Ext.getCmp(cmId + '-btn-save');

        if( ! saveBtn.disabled ) {
            saveBtn.handler.call(saveBtn.scope || saveBtn, saveBtn);
        }
    },

    monitorScroll: function(e, cmp)
    {
        cmp.fireEvent('scroll',e.target.body.scrollTop, this);
    },

    afterRender: function()
    {
        this.mirror = new CodeMirror(CodeMirror.replace(Ext.get(this.id).dom), {
            textWrapping       : false,
            saveFunction       : this.saveFunction,
            width              : '100%',
            height             : this.ownerCt.lastSize.height,
            readOnly           : this.readOnly,<commit_msg>Enable undoBtn only if it exist<commit_after>Ext.ux.CodeMirror = Ext.extend(Ext.BoxComponent, {

    readOnly         : (this.readOnly) ? this.readOnly : false,
    width            : 'auto',
    height           : 'auto',
    autoResize       : true,
    initialised      : false,
    documentDurty    : false,
    spellCheck       : ( this.spellCheck ) ? this.spellCheck : false,
    parser           : (this.parser) ? this.parser : "xml",
    parserFile       : "parsexml.js",
    parserStylesheet : "js/ux/codemirror/css/xmlcolors.css",

    initComponent : function()
    {
        Ext.ux.CodeMirror.superclass.initComponent.apply(this);

        this.addEvents({
            initialize   : true,
            codemodified : true,
            coderestored : true,
            cursormove   : true,
            scroll       : true
        });

        //For the parser
        if( this.parser === 'xml' ) {
            this.parserFile = "parsexml.js";
            this.parserStylesheet = "js/ux/codemirror/css/xmlcolors.css";
        }

        if( this.parser === 'html' ) {
            this.parserFile = ["parsexml.js", "parsecss.js", "tokenizejavascript.js", "parsejavascript.js", "parsehtmlmixed.js"];
            this.parserStylesheet = ["js/ux/codemirror/css/xmlcolors.css", "js/ux/codemirror/css/jscolors.css", "js/ux/codemirror/css/csscolors.css"];
        }

        if( this.parser === 'php' ) {
            this.parserFile = ["parsexml.js", "parsecss.js", "tokenizejavascript.js", "parsejavascript.js",
                             "../contrib/php/js/tokenizephp.js", "../contrib/php/js/parsephp.js",
                             "../contrib/php/js/parsephphtmlmixed.js"];
            this.parserStylesheet = ["js/ux/codemirror/css/xmlcolors.css", "js/ux/codemirror/css/jscolors.css", "js/ux/codemirror/css/csscolors.css", "js/ux/codemirror/contrib/php/css/phpcolors.css"];
        }
    },
    onRender : function(ct, position)
    {
        Ext.ux.CodeMirror.superclass.onRender.apply(this, [ct, position]);
    },

    resize: function()
    {
        this.mirror.frame.style.height = this.ownerCt.lastSize.height - 89 +"px";
        this.mirror.frame.style.width  = this.ownerCt.lastSize.width  - 35 +"px";
    },

    onInit: function(t, cmId)
    {
        var cmp    = Ext.getCmp(cmId),
            mirror = cmp.mirror;

        cmp.ownerCt.fireEvent('resize');

        // Fire the initialize event
        cmp.fireEvent('initialize');
        cmp.initialised = true;

        // Value used to monitor the state of this document (changed or not)
        cmp.documentDurty = false;

        // Attach some others events
        mirror.editor.keyUp = function(e) {

            // On envoie cursormove
            var r        = mirror.cursorPosition(),
                line     = mirror.lineNumber(r.line),
                caracter = r.character;
            cmp.fireEvent('cursormove', line, caracter);

            if( Ext.getCmp(cmId).documentDurty === true && e.keyCode !== 8 && e.keyCode !== 46 ) {

                // Don't need to check if the code has changed

            } else {

                // We check if the code has changed or not
                cmp.manageCodeChange(cmId);
            }
        };

        Ext.EventManager.addListener(mirror.frame.contentWindow, "scroll", function(e){ cmp.monitorScroll(e, cmp); }, this);
    },

    onCursorActivity: function(cmId)
    {
        var cmp      = Ext.getCmp(cmId),
            mirror   = cmp.mirror,
            r        = mirror.cursorPosition(),
            line     = mirror.lineNumber(r.line),
            caracter = r.character;
            cmp.fireEvent('cursormove', line, caracter);
    },

    manageCodeChange: function(cmId, force)
    {
        var cmp             = Ext.getCmp(cmId),
            mirror          = cmp.mirror,
            originalContent = mirror.originalContent,
            currentContent  = mirror.getCode(),
            btnUndo         = Ext.getCmp(cmId + '-btn-undo');

        // If originalContent is false, the editor is not ready
        if( originalContent ) {
            if( originalContent === currentContent ) {
                if( cmp.documentDurty === true ) {
                    cmp.fireEvent('coderestored');
                    cmp.documentDurty = false;
                }
                
            } else {

                // Enable the Undo Btn if it exist (don't exist when we open a fil in readOnly mode
                if( btnUndo ) {
                    btnUndo.enable(); // undo
                }

                if( cmp.documentDurty === false ) {
                    cmp.fireEvent('codemodified');
                    cmp.documentDurty = true;
                }
            }
        }
    },

    saveFunction: function(cmId)
    {
        var saveBtn = Ext.getCmp(cmId + '-btn-save');

        if( ! saveBtn.disabled ) {
            saveBtn.handler.call(saveBtn.scope || saveBtn, saveBtn);
        }
    },

    monitorScroll: function(e, cmp)
    {
        cmp.fireEvent('scroll',e.target.body.scrollTop, this);
    },

    afterRender: function()
    {
        this.mirror = new CodeMirror(CodeMirror.replace(Ext.get(this.id).dom), {
            textWrapping       : false,
            saveFunction       : this.saveFunction,
            width              : '100%',
            height             : this.ownerCt.lastSize.height,
            readOnly           : this.readOnly,
{'fraction_non_alphanumeric': 0.1261918115535614, 'fraction_numerical': 0.001869508319312021, 'mean_word_length': 1.6293929712460065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 20}, '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': '6030495', 'n_tokens_mistral': 3261, 'n_tokens_neox': 3129, 'n_words': 563}