<commit_before>define(function(require, exports, module) {
    main.consumes = [
        "Plugin", "ui", "commands", "menus", "tabManager", "dialog.alert"
    ];
    main.provides = ["format"];
    return main;

    function main(options, imports, register) {
        var Plugin     = imports.Plugin;
        var ui         = imports.ui;
        var commands   = imports.commands;
        var tabManager = imports.tabManager;
        var menus      = imports.menus;
        var alert      = imports["dialog.alert"].show;
        
        /***** Initialization *****/
        
        var plugin = new Plugin("Ajax.org", main.consumes);
        var emit   = plugin.getEmitter();
        
        var count = 200;
        var mnuFormat;
        
        var loaded = false;
        function load() {
            if (loaded) return false;
            loaded = true;
            
            commands.addCommand({
                name    : "formatcode",
                hint    : "reformat selected JavaScript code in the editor",
                msg     : "Beautifying selection.",
                bindKey : { mac: "Command-Shift-B", win: "Ctrl-Shift-B" },
                isAvailable : function(editor){
                    if (editor && editor.type == "ace") {
                        var range = editor.ace.getSelectionRange();
                        return range.start.row != range.end.row
                          || range.start.column != range.end.column;
                    }
                    return false;
                },
                exec : function(editor, args) {
                    formatCode(args.mode, editor);
                }
            }, plugin);
            
            menus.addItemByPath("Edit/Code Formatting", new ui.item(), 1400, plugin);
            
            menus.addItemByPath("Edit/Code Formatting/Auto Selected Formatter", new ui.item({
                selected : true,
                value    : "auto",
                command  : "formatcode"
            }), 100, plugin);
            menus.addItemByPath("Edit/Code Formatting/~", new ui.divider(), 200, plugin);
            
            mnuFormat = menus.get("Edit/Code Formatting").menu;
            mnuFormat.on("itemclick", function(e){
                if (e.value && e.value != "auto")
                    formatCode(e.value);
            });
        }
        
        /***** Methods *****/
        
        function getMode(editor){
            return editor.ace.session.syntax;
        }
        
        function formatCode(mode, editor) {
            if (!editor)
                editor = tabManager.focussedTab.editor;
            
            if (!mode || mode == "auto")
                mode = getMode(editor);
            
            if (!emit("format", { mode: mode, editor: editor })) {
                alert("Error",
                    "This code could not be beautified",
                    '"' + mode + "\" is not supported yet");
            }
        }
        
        function addFormatter(caption, mode, plugin){
            menus.addItemByPath("Edit/Code Formatting/" + caption, new ui.item({
                value       : mode,
                isAvailable : commands.commands.formatcode.isAvailable
            }), count += 100, plugin);
        }
        
        /***** Lifecycle *****/
        
        plugin.on("load", function() {
            load();
        });
        plugin.on("enable", function() {
            
        });
        plugin.on("disable", function() {
            
        });
        plugin.on("unload", function() {
            loaded = false;
        });
        
        /***** Register and define API *****/
        
        /**
         * 
         **/
        plugin.freezePublicAPI({
            /**
             * 
             */
            formatCode : formatCode,
            
            /**
             * 
             */
            addFormatter : addFormatter,
            
            _events : [
                /**
                 * @event format
                 * @param {Object} e
                 * @param {String} e.mode
                 */
                "format"
            ]
        });
        
        register(null, {
            format: plugin
        });
    }
});<commit_msg>More menu fixes<commit_after>define(function(require, exports, module) {
    main.consumes = [
        "Plugin", "ui", "commands", "menus", "tabManager", "dialog.alert"
    ];
    main.provides = ["format"];
    return main;

    function main(options, imports, register) {
        var Plugin     = imports.Plugin;
        var ui         = imports.ui;
        var commands   = imports.commands;
        var tabManager = imports.tabManager;
        var menus      = imports.menus;
        var alert      = imports["dialog.alert"].show;
        
        /***** Initialization *****/
        
        var plugin = new Plugin("Ajax.org", main.consumes);
        var emit   = plugin.getEmitter();
        
        var count = 200;
        var mnuFormat;
        
        var loaded = false;
        function load() {
            if (loaded) return false;
            loaded = true;
            
            commands.addCommand({
                name    : "formatcode",
                hint    : "reformat selected JavaScript code in the editor",
                msg     : "Beautifying selection.",
                bindKey : { mac: "Command-Shift-B", win: "Ctrl-Shift-B" },
                isAvailable : function(editor){
                    if (editor && editor.type == "ace") {
                        var range = editor.ace.getSelectionRange();
                        return range.start.row != range.end.row
                          || range.start.column != range.end.column;
                    }
                    return false;
                },
                exec : function(editor, args) {
                    formatCode(args.mode, editor);
                }
            }, plugin);
            
            menus.addItemByPath("Edit/Code Formatting", null, 1400, plugin);
            
            menus.addItemByPath("Edit/Code Formatting/Auto Selected Formatter", new ui.item({
                selected : true,
                value    : "auto",
                command  : "formatcode"
            }), 100, plugin);
            menus.addItemByPath("Edit/Code Formatting/~", new ui.divider(), 200, plugin);
            
            mnuFormat = menus.get("Edit/Code Formatting").menu;
            mnuFormat.on("itemclick", function(e){
                if (e.value && e.value != "auto")
                    formatCode(e.value);
            });
        }
        
        /***** Methods *****/
        
        function getMode(editor){
            return editor.ace.session.syntax;
        }
        
        function formatCode(mode, editor) {
            if (!editor)
                editor = tabManager.focussedTab.editor;
            
            if (!mode || mode == "auto")
                mode = getMode(editor);
            
            if (!emit("format", { mode: mode, editor: editor })) {
                alert("Error",
                    "This code could not be beautified",
                    '"' + mode + "\" is not supported yet");
            }
        }
        
        function addFormatter(caption, mode, plugin){
            menus.addItemByPath("Edit/Code Formatting/" + caption, new ui.item({
                value       : mode,
                isAvailable : commands.commands.formatcode.isAvailable
            }), count += 100, plugin);
        }
        
        /***** Lifecycle *****/
        
        plugin.on("load", function() {
            load();
        });
        plugin.on("enable", function() {
            
        });
        plugin.on("disable", function() {
            
        });
        plugin.on("unload", function() {
            loaded = false;
        });
        
        /***** Register and define API *****/
        
        /**
         * 
         **/
        plugin.freezePublicAPI({
            /**
             * 
             */
            formatCode : formatCode,
            
            /**
             * 
             */
            addFormatter : addFormatter,
            
            _events : [
                /**
                 * @event format
                 * @param {Object} e
                 * @param {String} e.mode
                 */
                "format"
            ]
        });
        
        register(null, {
            format: plugin
        });
    }
});
{'fraction_non_alphanumeric': 0.12237475067464508, 'fraction_numerical': 0.003754546521177989, 'mean_word_length': 1.1167121926992798, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4952430', 'n_tokens_mistral': 2193, 'n_tokens_neox': 2059, 'n_words': 449}